Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2023-11-24 15:34:55 +0900 #257

Merged
merged 38 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9fb5706
remove unused ones
csenet Nov 23, 2023
1bca0ec
install connect query
gotti Nov 23, 2023
a071087
fix typo
gotti Nov 23, 2023
24295a5
Commit from GitHub Actions (compile_PB)
github-actions[bot] Nov 23, 2023
1291d37
fix path
gotti Nov 23, 2023
ea63fc4
Commit from GitHub Actions (compile_PB)
github-actions[bot] Nov 23, 2023
df9bd47
fix typo
gotti Nov 23, 2023
1ee8e27
fix typo
gotti Nov 23, 2023
4edbba8
fix generation path
gotti Nov 23, 2023
cab7606
Commit from GitHub Actions (compile_PB)
github-actions[bot] Nov 23, 2023
554bc34
implement proxy
gotti Nov 23, 2023
5fc21a2
implement views and updates of trafficlights
gotti Nov 23, 2023
62245bb
views and updates of points
gotti Nov 23, 2023
9a00f44
fix bufbuild moromoro
gotti Nov 23, 2023
f93ecfc
views and updates of trains
gotti Nov 23, 2023
86169c3
fix
gotti Nov 23, 2023
184a04a
remove import extension js
Azuki-bar Nov 24, 2023
8a71c6f
Commit from GitHub Actions (compile_PB)
github-actions[bot] Nov 24, 2023
ee31cb6
CI走らせるために空コミットする
Azuki-bar Nov 24, 2023
f120c3f
fix deployment target dir
Azuki-bar Nov 24, 2023
9ad1fff
Merge pull request #256 from ueckoken/implement-frontend-api-call
gotti Nov 24, 2023
7ce279f
Update react monorepo
renovate[bot] Nov 24, 2023
9d7ca41
Update Node.js to v20.10
renovate[bot] Nov 24, 2023
7eafbe5
backend/auto-operationをpnpmの管理下にいれる
Azuki-bar Nov 24, 2023
9f155b2
buildできるようにする
Azuki-bar Nov 24, 2023
70be46f
イメージ作る
Azuki-bar Nov 24, 2023
7eed030
migrate connect-ewb to connect-es
Azuki-bar Nov 24, 2023
d738391
Commit from GitHub Actions (compile_PB)
github-actions[bot] Nov 24, 2023
546ae2e
CI走らせるために空コミットする
Azuki-bar Nov 24, 2023
93bfaaf
fix import path
Azuki-bar Nov 24, 2023
432367f
キャッシュを掴まないようにする
Azuki-bar Nov 24, 2023
74c5ff0
pnpmがおかしい
Azuki-bar Nov 24, 2023
317f576
pin version
Azuki-bar Nov 24, 2023
3e7074b
fix
Azuki-bar Nov 24, 2023
c695ecb
fix
Azuki-bar Nov 24, 2023
23d56c3
corepack enable
Azuki-bar Nov 24, 2023
806dd7a
fix nodejs version
Azuki-bar Nov 24, 2023
73acd10
Merge pull request #259 from ueckoken/impl-image-autooperation
Azuki-bar Nov 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions .github/workflows/create-proto.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: compile_PB
name: compile PB

on:
push:
Expand All @@ -18,19 +18,9 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
working-directory: ./frontend/dashboard
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --immutable
working-directory: ./frontend/dashboard
- name: Corepack Enable
run: corepack enable
- run: pnpm install --frozen-lockfile
- name: Set up Go
uses: actions/setup-go@v4
with:
Expand Down
1 change: 1 addition & 0 deletions backend/auto-operation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main.js
45 changes: 28 additions & 17 deletions backend/auto-operation/main.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { createPromiseClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-node";
import { StateManagerService } from "./proto/state/v1/state_connectweb.js";
import { StateManagerService } from "./proto/state/v1/state_connect.js";
import { BlockStateEnum } from "./proto/state/v1/block_pb.js";
import { StopStateEnum } from "./proto/state/v1/stop_pb.js";
import { PointStateEnum } from "./proto/state/v1/point_pb.js";
import { Priority } from "./proto/state/v1/train_pb.js";

let mapConfig;
type MapConfig = {
stopBlocks: { [key: string]: string },
stations: {
[key: string]: {
capacity: number,
}
}
}
let mapConfig: MapConfig;

const SERVER_ADDR = process.env['SERVER_ADDR'] ?? 'http://localhost:8080'
const transport = createConnectTransport(
{
httpVersion: "2",
baseUrl: "http://localhost:8080",
baseUrl: SERVER_ADDR,
});
const client = createPromiseClient(StateManagerService, transport);

async function loadConfig() {
mapConfig = await import("./map/chofufes-2023.json");
mapConfig = (await import("./map/chofufes-2023.json")).default;
}

loadConfig();
Expand All @@ -27,7 +36,7 @@ async function addTest() {
train: {
trainId: "test",
positionId: "shinjuku_b1",
priority: Priority.PRIORITY_HIGH,
priority: Priority.HIGH,
uuid: "test",
destination: "hashimoto_up_s1"
}
Expand All @@ -36,7 +45,7 @@ async function addTest() {
train: {
trainId: "test2",
positionId: "shinjuku_s1",
priority: Priority.PRIORITY_LOW,
priority: Priority.LOW,
uuid: "test",
destination: "hachioji_up_s1"
}
Expand Down Expand Up @@ -84,14 +93,14 @@ async function main() {
// 通過待ちができるかどうか
const stationName = train.positionId.split("_")[0] + "_" + train.positionId.split("_")[1];
const capacity = mapConfig.stations[stationName];
if (capacity > 1 && train.Priority === Priority.PRIORITY_LOW) {
if (capacity.capacity > 1 && train.priority === Priority.LOW) {
// 通過待ちが可能な駅で、PriorityがLOWの列車はPriorityがHIGHの列車が停車するまで待つ
const highPriorityTrains = trains.filter(t => (t.positionId.includes(stationName)) && t.Priority === Priority.PRIORITY_HIGH);
const highPriorityTrains = trains.filter(t => (t.positionId.includes(stationName)) && t.priority === Priority.HIGH);
if (highPriorityTrains.length > 0) continue;
}
const stop = stops.find(s => s.id === train.positionId);
// 問題ないならGOにする
if (stop.state !== StopStateEnum.STOP_STATE_GO) {
if (stop && stop.state !== StopStateEnum.STOP_STATE_GO) {
await client.updateStopState({
"state": {
"id": stop.id,
Expand All @@ -108,8 +117,8 @@ async function main() {
// 桜上水上りポイント
// デフォルトではSTRAIGHTにして、sakurajosui_up_s1がONならREVERSEにする
const sakurajosui_up_s1 = stops.find(s => s.id === "sakurajosui_up_s1");
if (sakurajosui_up_s1.state === StopStateEnum.STOP_STATE_STOP) {
if (point.state !== StopStateEnum.STOP_STATE_REVERSE) {
if (sakurajosui_up_s1 && sakurajosui_up_s1.state === StopStateEnum.STOP_STATE_STOP) {
if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
await client.updatePointState({
"state": {
"id": point.id,
Expand All @@ -118,7 +127,7 @@ async function main() {
})
}
} else {
if (point.state !== StopStateEnum.STOP_STATE_STRAIGHT) {
if (point.state !== PointStateEnum.POINT_STATE_NORMAL) {
await client.updatePointState({
"state": {
"id": point.id,
Expand All @@ -130,7 +139,7 @@ async function main() {
}
if (point.id === "sakurajosui_down_p1") {
const sakurajosui_down_s1 = stops.find(s => s.id === "sakurajosui_down_s1");
if (sakurajosui_down_s1.state === StopStateEnum.STOP_STATE_STOP) {
if (sakurajosui_down_s1 && sakurajosui_down_s1.state === StopStateEnum.STOP_STATE_STOP) {
if (point.state !== PointStateEnum.POINT_STATE_REVERSE) {
await client.updatePointState({
"state": {
Expand Down Expand Up @@ -183,7 +192,9 @@ async function main() {

addTest();

while (true) {
main();
await new Promise(resolve => setTimeout(resolve, 200));
}
(async () => {
while (true) {
main();
await new Promise(resolve => setTimeout(resolve, 200));
}
})()
18 changes: 11 additions & 7 deletions backend/auto-operation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "npx tsc"
},
"keywords": [],
"author": "",
"type": "module",
"license": "ISC",
"dependencies": {
"@bufbuild/buf": "^1.28.1",
"@bufbuild/connect-web": "^0.13.0",
"@bufbuild/protobuf": "^1.4.2",
"@bufbuild/protoc-gen-es": "^1.4.2",
"@connectrpc/connect": "^1.1.3",
"@connectrpc/connect-node": "^1.1.3",
"@connectrpc/connect-web": "^1.1.3",
"@connectrpc/protoc-gen-connect-es": "^1.1.3",
"install": "^0.13.0",
"install": "^0.13.0"
},
"devDependencies": {
"@types/node": "20.9.5",
"tsx": "^4.3.0",
"typescript": "5.2.2"
}
"typescript": "5.2.2",
"@connectrpc/protoc-gen-connect-es": "^1.1.3",
"@bufbuild/protoc-gen-es": "^1.4.2"
},
"packageManager": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-connect-web v0.11.0 with parameter "target=dts+js"
// @generated by protoc-gen-connect-es v1.1.3 with parameter "target=dts+js"
// @generated from file state/v1/state.proto (package state.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-connect-web v0.11.0 with parameter "target=dts+js"
// @generated by protoc-gen-connect-es v1.1.3 with parameter "target=dts+js"
// @generated from file state/v1/state.proto (package state.v1, syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down
8 changes: 4 additions & 4 deletions backend/auto-operation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
Expand All @@ -25,9 +25,9 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "Node16", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
Expand All @@ -39,7 +39,7 @@
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
"resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

Expand Down
28 changes: 28 additions & 0 deletions backend/proxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"fmt"
"net/http"
"net/http/httputil"
"net/url"
"strings"
)

func main() {
frontendURL, _ := url.Parse("http://localhost:3000")
backendURL, _ := url.Parse("http://localhost:8080")

mux := http.NewServeMux()
mux.Handle("/", httputil.NewSingleHostReverseProxy(frontendURL))
rev := httputil.ReverseProxy{
Director: func(r *http.Request) {
r.URL.Path = strings.Replace(r.URL.Path, "/api", "", 1)
r.URL.Host = backendURL.Host
r.URL.Scheme = backendURL.Scheme
r.Header.Set("X-Forwarded-Host", r.Header.Get("Host"))
},
}
mux.Handle("/api/", &rev)

fmt.Println(http.ListenAndServe(":3030", mux))
}
8 changes: 8 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
group "default" {
targets = [
"state-manager",
"autooperation",
"dashboard"
]
}
Expand Down Expand Up @@ -29,6 +30,13 @@ target "state-manager" {
]
}

target "autooperation" {
dockerfile = "docker/backend/auto-operation/Dockerfile"
tags = [
GET_TAG("autooperation")
]
}

target "dashboard" {
dockerfile = "docker/frontend/dashboard/Dockerfile"
tags = [
Expand Down
24 changes: 24 additions & 0 deletions docker/backend/auto-operation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:20.9-bookworm AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable

FROM base AS dep-resolver

WORKDIR /auto-operation
COPY --chown=node:node pnpm-lock.yaml pnpm-workspace.yaml ./
COPY backend/auto-operation ./backend/auto-operation
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile

FROM dep-resolver AS auto-operation-builder
RUN pnpm run --filter=./backend/auto-operation -r build
RUN pnpm deploy --filter=./backend/auto-operation --prod dist/auto-operation
RUN cp backend/auto-operation/main.js dist/auto-operation/main.js
WORKDIR /autooperation/dist/auto-operation


FROM gcr.io/distroless/nodejs20-debian12:nonroot AS dashboard-runner
COPY --from=auto-operation-builder --chown=nonroot:nonroot /auto-operation/dist/auto-operation /auto-operation
ENV SERVER_ADDR=''
CMD ["/auto-operation/main.js"]

10 changes: 5 additions & 5 deletions docker/frontend/dashboard/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:20.9-bookworm AS base
FROM node:20.10-bookworm AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
Expand All @@ -8,15 +8,15 @@ FROM base AS dep-resolver
WORKDIR /dashboard
COPY --chown=node:node pnpm-lock.yaml pnpm-workspace.yaml ./
COPY frontend/ ./frontend
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm install --frozen-lockfile --no-optional

FROM dep-resolver AS dashboard-builder
RUN pnpm run --filter=./frontend/dashboard -r build
RUN pnpm deploy --filter=./frontend/dashboard --prod dist/dashboard
WORKDIR /dashboard/dist/dashboard
RUN cp -r .next/static .next/standalone/frontend/dashboard/.next/
RUN cp -r public .next/standalone/frontend/dashboard/
RUN cp -r .next/static .next/standalone/.next/
RUN cp -r public .next/standalone/

FROM gcr.io/distroless/nodejs20-debian12:nonroot AS dashboard-runner
COPY --from=dashboard-builder --chown=nonroot:nonroot /dashboard/dist/dashboard /dashboard
CMD ["/dashboard/.next/standalone/frontend/dashboard/server.js"]
CMD ["/dashboard/.next/standalone/server.js"]
28 changes: 0 additions & 28 deletions frontend/dashboard/app/test/page.tsx

This file was deleted.

14 changes: 8 additions & 6 deletions frontend/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
"lint": "next lint"
},
"dependencies": {
"@bufbuild/connect-web": "^0.13.0",
"@bufbuild/protobuf": "^1.4.2",
"@connectrpc/connect": "^1.1.3",
"@connectrpc/connect-query": "^0.6.0",
"@connectrpc/connect-web": "^1.1.3",
"@tanstack/react-query": "^5.8.4",
"clsx": "^2.0.0",
"next": "14.0.3",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@bufbuild/buf": "^1.28.1",
"@bufbuild/protoc-gen-connect-web": "^0.11.0",
"@bufbuild/protoc-gen-es": "^1.4.2",
"@connectrpc/protoc-gen-connect-es": "^1.1.3",
"@connectrpc/protoc-gen-connect-query": "^0.6.0",
"@svgr/webpack": "^8.1.0",
"@types/node": "20.9.2",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"@types/node": "20.9.5",
"@types/react": "18.2.38",
"@types/react-dom": "18.2.17",
"eslint-config-prettier": "^9.0.0",
"prettier": "3.1.0",
"sass": "^1.69.5",
Expand All @@ -36,5 +37,6 @@
".next/standalone",
".next/static",
"public"
]
],
"packageManager": "[email protected]"
}
Loading