From 1af99421475eb88fbf20e4ac7b0b9a9245fdb481 Mon Sep 17 00:00:00 2001 From: ereti <43418802+ereti@users.noreply.github.com> Date: Thu, 1 Dec 2022 21:10:23 +0000 Subject: [PATCH] feat: the monorepo man --- .github/workflows/bot.yml | 12 ++++--- .github/workflows/github-bot.yml | 15 +++++---- .github/workflows/server.yml | 2 +- .npmrc | 3 +- Dockerfile.bot | 33 +++++++++++-------- Dockerfile.ghbot | 30 ++++++++++------- Dockerfile.server | 22 ++++++------- bot/package.json | 3 +- bot/tsconfig.json | 12 +++++-- .../src/components/imports/ImportFileInfo.tsx | 2 +- client/tsconfig.json | 14 ++++++-- common/package.json | 6 ++-- database-seeds/scripts/package.json | 2 ++ database-seeds/scripts/tsconfig.json | 14 ++++++-- github-bot/package.json | 4 +-- package.json | 1 + pnpm-lock.yaml | 6 ++-- server/package.json | 12 +++---- server/src/test-utils/single-process-tap.ts | 2 +- server/tsconfig.json | 9 +++-- sieglinde/package.json | 2 ++ sieglinde/src/calc/util/calc.ts | 2 +- sieglinde/src/calc/util/lerp.ts | 2 +- sieglinde/tsconfig.json | 12 +++++-- tachi.code-workspace | 4 +++ tsconfig.json | 18 +++++++--- 26 files changed, 159 insertions(+), 85 deletions(-) diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml index 67cfecbbd..4c3b0381e 100644 --- a/.github/workflows/bot.yml +++ b/.github/workflows/bot.yml @@ -17,10 +17,10 @@ jobs: working-directory: ./bot steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Docker Hub login - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} @@ -29,16 +29,18 @@ jobs: run: 'echo "VERSION_TAG=$(cat package.json | grep version | head -1 | awk -F: ''{ print $2 }'' | sed ''s/[", ]//g'')" >> $GITHUB_ENV' - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Build and push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: context: ./ - file: ./Dockerfile.bot push: true tags: ${{ secrets.DOCKER_USERNAME }}/tachi-bot:stable,${{ secrets.DOCKER_USERNAME }}/tachi-bot:${{ env.VERSION_TAG }}, + file: ./Dockerfile.bot + cache-from: type=gha,scope=$GITHUB_REF_NAME-bot + cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-bot - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/github-bot.yml b/.github/workflows/github-bot.yml index 02a64111d..9eec79282 100644 --- a/.github/workflows/github-bot.yml +++ b/.github/workflows/github-bot.yml @@ -16,10 +16,10 @@ jobs: working-directory: ./github-bot steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Docker Hub login - uses: docker/login-action@v1 + uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_TOKEN }} @@ -28,16 +28,19 @@ jobs: run: 'echo "VERSION_TAG=$(cat package.json | grep version | head -1 | awk -F: ''{ print $2 }'' | sed ''s/[", ]//g'')" >> $GITHUB_ENV' - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + uses: docker/setup-buildx-action@v2 - name: Build and push id: docker_build - uses: docker/build-push-action@v2 + uses: docker/build-push-action@v3 with: context: ./ - file: ./Dockerfile.ghbot push: true - tags: ${{ secrets.DOCKER_USERNAME }}/tachi-gh-bot:stable,${{ secrets.DOCKER_USERNAME }}/tachi-gh-bot:${{ env.VERSION_TAG }}, + tags: ${{ secrets.DOCKER_USERNAME }}/tachi-gh-bot:stable,${{ secrets.DOCKER_USERNAME }}/tachi-gh-bot:${{ env.VERSION_TAG }} + file: ./Dockerfile.ghbot + cache-from: type=gha,scope=$GITHUB_REF_NAME-github-bot + cache-to: type=gha,mode=max,scope=$GITHUB_REF_NAME-github-bot + - name: Image digest run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 82239c1ae..7e93c7498 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -39,7 +39,7 @@ jobs: cache: pnpm - name: Install dependencies - run: pnpm --filter ./common --filter ./server --filter . install --frozen-lockfile + run: pnpm --filter tachi-server... --filter . install --frozen-lockfile # configure external dbs - uses: supercharge/mongodb-github-action@1.4.1 diff --git a/.npmrc b/.npmrc index fa4e09523..7b6294327 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ -strict-peer-dependencies=false \ No newline at end of file +strict-peer-dependencies=false +workspace-concurrency=0 \ No newline at end of file diff --git a/Dockerfile.bot b/Dockerfile.bot index b37e8df31..0dd916f5e 100644 --- a/Dockerfile.bot +++ b/Dockerfile.bot @@ -1,22 +1,27 @@ -FROM node:16 as build +# This dockerfile spins up an instance of tachi-server and *tachi-server* alone. +# It does not spin up mongodb instances or redis instances, which the server +# does need to boot. You should consider using docker-compose for this. +FROM node:16-alpine as base +RUN npm install --silent -g pnpm + +FROM base AS build WORKDIR /app -COPY --chown=node:node ./bot /app/bot -COPY --chown=node:node ./common /app/common -COPY --chown=node:node ./pnpm-lock.yaml /app -COPY --chown=node:node ./.npmrc /app -COPY --chown=node:node ./pnpm-workspace.yaml /app -COPY --chown=node:node ./package.json /app -COPY --chown=node:node ./tsconfig.json /app +COPY pnpm-lock.yaml . -RUN npm install --silent -g pnpm@6 && groupmod -g 1003 node && chown node:node /app +RUN pnpm fetch -USER node +COPY bot ./bot +COPY common ./common +COPY *.json *.yaml ./ + +RUN pnpm --filter tachi-bot... --filter . install --offline --silent +RUN pnpm --filter tachi-bot... -r build + +FROM base AS app +COPY --from=build /app /app WORKDIR /app/bot -RUN pnpm install --silent && pnpm build && pnpm prune --silent --production && pnpm store prune --silent - -HEALTHCHECK --interval=15s --timeout=5s CMD curl -f http://localhost:8080 || exit 1 ENV NODE_PATH=js/ -CMD ["pnpm", "start-no-build"] +CMD ["node", "js/main.js"] diff --git a/Dockerfile.ghbot b/Dockerfile.ghbot index 7cb18db55..09e111426 100644 --- a/Dockerfile.ghbot +++ b/Dockerfile.ghbot @@ -1,21 +1,27 @@ -FROM node:16 as build +# This dockerfile spins up an instance of tachi-server and *tachi-server* alone. +# It does not spin up mongodb instances or redis instances, which the server +# does need to boot. You should consider using docker-compose for this. +FROM node:16-alpine as base +RUN npm install --silent -g pnpm + +FROM base AS build WORKDIR /app -COPY --chown=node:node ./github-bot /app/github-bot -COPY --chown=node:node ./pnpm-lock.yaml /app -COPY --chown=node:node ./.npmrc /app -COPY --chown=node:node ./pnpm-workspace.yaml /app -COPY --chown=node:node ./package.json /app -COPY --chown=node:node ./tsconfig.json /app +COPY pnpm-lock.yaml . -RUN npm install --silent -g pnpm@6 && groupmod -g 1003 node && chown node:node /app +RUN pnpm fetch -USER node +COPY github-bot ./github-bot +COPY common ./common +COPY *.json *.yaml ./ + +RUN pnpm --filter tachi-github-bot... --filter . install --offline --silent +RUN pnpm --filter tachi-github-bot... -r build + +FROM base AS app +COPY --from=build /app /app WORKDIR /app/github-bot -RUN pnpm install --silent && pnpm build && pnpm prune --silent --production && pnpm store prune --silent - -HEALTHCHECK --interval=15s --timeout=5s CMD curl -f http://localhost:8080 || exit 1 ENV NODE_PATH=js/ CMD ["node", "js/main.js"] diff --git a/Dockerfile.server b/Dockerfile.server index 5b6846523..3d701e6e6 100644 --- a/Dockerfile.server +++ b/Dockerfile.server @@ -11,23 +11,23 @@ RUN apk add --no-cache FROM base AS build WORKDIR /app + COPY pnpm-lock.yaml . RUN pnpm fetch -COPY . . +COPY server /app/server +COPY common /app/common +COPY *.json *.yaml ./ -RUN pnpm --filter ./common --filter ./server --filter . install --prefer-offline --silent - -RUN pnpm --filter ./common --filter ./server build --silent +RUN pnpm --filter tachi-server... --filter . install --offline --silent +RUN pnpm --filter tachi-server... -r build FROM base AS app -WORKDIR /app -COPY --from=build /app/node_modules /app/node_modules -COPY --from=build /app/server /app/server -COPY --from=build /app/common /app/common -COPY --from=build /app/package.json /app/package.json +COPY --from=build /app /app HEALTHCHECK --interval=15s --timeout=5s CMD curl -f http://localhost:8080/api/v1/status || exit 1 -ENV NODE_PATH=/app/server/js -CMD ["node", "/app/server/js/main.js"] +WORKDIR /app/server + +ENV NODE_PATH=js/ +CMD ["node", "js/main.js"] diff --git a/bot/package.json b/bot/package.json index d92a7dbf9..4ae2f2945 100644 --- a/bot/package.json +++ b/bot/package.json @@ -5,7 +5,7 @@ "main": "js/bot/src/main.js", "license": "MIT", "scripts": { - "build": "tsc", + "build": "tsc -b", "start": "pnpm build && node -r ts-node/register -r tsconfig-paths/register js/bot/src/main.js", "start-no-build": "node -r ts-node/register -r tsconfig-paths/register js/bot/src/main.js", "lint": "eslint . --fix" @@ -38,6 +38,7 @@ "prudence": "0.9.8", "seq-logging": "1.1.1", "sync-fetch": "^0.3.1", + "tachi-common": "workspace:../common", "typescript": "4.5.5", "ts-node": "10.0.0", "tsconfig-paths": "3.12.0" diff --git a/bot/tsconfig.json b/bot/tsconfig.json index e7070d818..8a02f0d43 100644 --- a/bot/tsconfig.json +++ b/bot/tsconfig.json @@ -1,8 +1,9 @@ { "extends": "../tsconfig.json", "compilerOptions": { + "rootDir": "src", "baseUrl": "src", - "outDir": "./js", + "outDir": "js", "lib": [ "DOM" // hack workaround. URLSearchParams must be imported, yet // discordJS carelessly uses it without being imported @@ -20,6 +21,8 @@ "../../common/src/*" ] }, + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, "include": [ "src/**/*" @@ -27,5 +30,10 @@ "exclude": [ "node_modules", "**/*.test.ts" - ] + ], + "references": [ + { + "path": "../common" + } + ], } \ No newline at end of file diff --git a/client/src/components/imports/ImportFileInfo.tsx b/client/src/components/imports/ImportFileInfo.tsx index 5ab5bfc79..f1d977c2e 100644 --- a/client/src/components/imports/ImportFileInfo.tsx +++ b/client/src/components/imports/ImportFileInfo.tsx @@ -56,7 +56,7 @@ export default function ImportFileInfo({ setData({ valid, info }); } catch (err) { - setErrMsg(err.message); + setErrMsg((err as Error).message); setData({ valid: false, info: {} }); } }); diff --git a/client/tsconfig.json b/client/tsconfig.json index 94e79715e..52d329127 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -1,7 +1,9 @@ { "compilerOptions": { "target": "esnext", - "outDir": "./dist/", + "rootDir": "src", + "baseUrl": "src", + "outDir": "dist", "strictNullChecks": true, "moduleResolution": "node", "allowJs": true, @@ -9,7 +11,6 @@ "strict": true, "esModuleInterop": true, "jsx": "react", - "baseUrl": "src", "paths": { "tachi-common": [ "../../common/src" @@ -40,11 +41,18 @@ "allowSyntheticDefaultImports": true, "allowUnusedLabels": true, "resolveJsonModule": true, + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, "include": [ "src" ], "exclude": [ "node_modules" - ] + ], + "references": [ + { + "path": "../common" + } + ], } \ No newline at end of file diff --git a/common/package.json b/common/package.json index 6484e0495..5211ed43f 100644 --- a/common/package.json +++ b/common/package.json @@ -9,9 +9,9 @@ }, "scripts": { "test": "tap", - "build": "tsc", - "install": "tsc", - "prepublish": "tsc", + "build": "tsc -b", + "install": "tsc -b", + "prepublish": "tsc -b", "lint": "eslint . --ext .ts --fix" }, "author": "zkldi", diff --git a/database-seeds/scripts/package.json b/database-seeds/scripts/package.json index af3aaeece..15b085459 100644 --- a/database-seeds/scripts/package.json +++ b/database-seeds/scripts/package.json @@ -5,6 +5,7 @@ "description": "Scripts for dealing with tachi-database-seeds.", "main": "", "scripts": { + "build": "tsc -b", "test": "./run-tests.sh", "sort": "node deterministic-collection-sort.js" }, @@ -29,6 +30,7 @@ "monk": "^7.3.4", "node-fetch": "2.6.7", "prudence": "0.9.8", + "tachi-common": "workspace:../../common", "xml2js": "^0.4.23" } } \ No newline at end of file diff --git a/database-seeds/scripts/tsconfig.json b/database-seeds/scripts/tsconfig.json index 050b3469b..f16ddc25c 100644 --- a/database-seeds/scripts/tsconfig.json +++ b/database-seeds/scripts/tsconfig.json @@ -11,8 +11,9 @@ // I hope not. "DOM" ], - "outDir": "./js", + "rootDir": "src", "baseUrl": "src", + "outDir": "js", // USE TS-NODE! "noEmit": true, "typeRoots": [ @@ -26,7 +27,9 @@ "tachi-common/*": [ "../../../common/src/*" ] - } + }, + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, "ts-node": { "require": [ @@ -35,5 +38,10 @@ }, "exclude": [ "node_modules", - ] + ], + "references": [ + { + "path": "../../common" + } + ], } \ No newline at end of file diff --git a/github-bot/package.json b/github-bot/package.json index 4e9fc8475..1e5e41cd8 100644 --- a/github-bot/package.json +++ b/github-bot/package.json @@ -5,8 +5,8 @@ "description": "A GitHub bot for listening to Tachi's GitHub Repo.", "author": "zkldi", "scripts": { - "build": "tsc", - "start": "tsc && node js/main.js" + "build": "tsc -b ", + "start": "tsc -b && node js/main.js" }, "dependencies": { "@octokit/webhooks": "10.1.5", diff --git a/package.json b/package.json index 3a05f4545..55c172d44 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "description": "The root of the Tachi monorepo. Contains common utils like linters.", "scripts": { + "build": "pnpm -r build", "start-client": "pnpm --filter ./client start", "start-server": "pnpm --filter ./server start", "test-server": "pnpm --filter ./server test", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dfc292a2d..bf0527c98 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -456,7 +456,6 @@ importers: seq-logging: 1.1.1 tachi-common: link:../common ts-node: 10.0.0_eyk5xebzzzbswsv7f7bz54zw5q - tsconfig-paths: 3.12.0 typescript: 4.5.5 winston: 3.5.1 winston-daily-rotate-file: 4.6.0_winston@3.5.1 @@ -468,6 +467,7 @@ importers: node-mocks-http: 1.11.0 supertest: 6.2.2 tap: 15.1.6_beks75j6uapyr6v7hoxdw666hu + tsconfig-paths: 3.12.0 sieglinde: specifiers: @@ -6034,6 +6034,7 @@ packages: dependencies: ms: 2.1.2 supports-color: 6.1.0 + dev: true /decamelize/1.2.0: resolution: {integrity: sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==} @@ -7556,7 +7557,7 @@ packages: debug: optional: true dependencies: - debug: 4.3.4_supports-color@6.1.0 + debug: 4.3.4 /for-in/1.0.2: resolution: {integrity: sha512-7EwmXrOjyL+ChxMhmG5lnW9MPt1aIeZEwKhQzoBUdTV0N3zuwWDZYVJatDvZ2OyzPUvdIAZDsCetk3coyMfcnQ==} @@ -14177,7 +14178,6 @@ packages: json5: 1.0.1 minimist: 1.2.6 strip-bom: 3.0.0 - dev: false /tsconfig-paths/3.14.1: resolution: {integrity: sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==} diff --git a/server/package.json b/server/package.json index 9b314f57f..a62c66859 100644 --- a/server/package.json +++ b/server/package.json @@ -11,8 +11,8 @@ "test": "tap", "snap": "TAP_SNAPSHOT=1 tap", "watchtest": "tap --watch", - "build": "tsc --project tsconfig.build.json", - "typecheck": "tsc --project tsconfig.build.json --noEmit", + "build": "tsc -b tsconfig.build.json", + "typecheck": "tsc -b tsconfig.build.json --noEmit", "lint": "eslint ./src --ext .ts --fix", "start": "pnpm build && pnpm start-no-build", "start-no-build": "node js/server/main.js", @@ -29,7 +29,8 @@ "glob": "^7.2.0", "node-mocks-http": "1.11.0", "supertest": "6.2.2", - "tap": "15.1.6" + "tap": "15.1.6", + "tsconfig-paths": "3.12.0" }, "dependencies": { "@aws-sdk/client-s3": "3.49.0", @@ -89,12 +90,11 @@ "semver": "^7.3.7", "seq-logging": "1.1.1", "ts-node": "10.0.0", - "tsconfig-paths": "3.12.0", + "tachi-common": "workspace:../common", "typescript": "4.5.5", "winston": "3.5.1", "winston-daily-rotate-file": "4.6.0", - "winston-transport": "4.5.0", - "tachi-common": "workspace:../common" + "winston-transport": "4.5.0" }, "nyc": { "reporter": [ diff --git a/server/src/test-utils/single-process-tap.ts b/server/src/test-utils/single-process-tap.ts index db0318f27..6e2d4e418 100644 --- a/server/src/test-utils/single-process-tap.ts +++ b/server/src/test-utils/single-process-tap.ts @@ -4,7 +4,7 @@ import glob from "glob"; import t from "tap"; import path from "path"; -const files = glob.sync(path.join(__dirname, "../../", "**/*.test.ts")); +const files = glob.sync(path.join(__dirname, "../", "**/*.test.ts")); process.env.NODE_PATH = path.join(__dirname, "../"); diff --git a/server/tsconfig.json b/server/tsconfig.json index f5e87ebfc..dd0a84948 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -27,7 +27,7 @@ ], "tachi-common/*": [ "../../common/src/*" - ], + ] }, "composite": true, "tsBuildInfoFile": ".tsbuildinfo" @@ -42,5 +42,10 @@ { "path": "../common" } - ] + ], + "ts-node": { + "require": [ + "tsconfig-paths/register" + ] + } } \ No newline at end of file diff --git a/sieglinde/package.json b/sieglinde/package.json index 1f2d359fa..bc57d58b0 100644 --- a/sieglinde/package.json +++ b/sieglinde/package.json @@ -4,6 +4,7 @@ "description": "", "main": "index.js", "scripts": { + "build": "tsc -b", "test": "echo \"Error: no test specified\" && exit 1", "calc-v1": "ts-node src/main.ts" }, @@ -15,6 +16,7 @@ "fast-xml-parser": "^4.0.0-beta.2", "mei-logger": "^1.0.1", "node-fetch": "2.6.7", + "tachi-common": "workspace:../common", "winston": "3.5.1" } } \ No newline at end of file diff --git a/sieglinde/src/calc/util/calc.ts b/sieglinde/src/calc/util/calc.ts index 3fddad3c3..0b315f5ef 100644 --- a/sieglinde/src/calc/util/calc.ts +++ b/sieglinde/src/calc/util/calc.ts @@ -1,4 +1,4 @@ -import logger from "../logger"; +import logger from "../../logger"; import fs from "fs"; import path from "path"; diff --git a/sieglinde/src/calc/util/lerp.ts b/sieglinde/src/calc/util/lerp.ts index 3997401a3..0f227779d 100644 --- a/sieglinde/src/calc/util/lerp.ts +++ b/sieglinde/src/calc/util/lerp.ts @@ -34,7 +34,7 @@ // 6.070885183, // 25 // ]; -import { GetBaseline } from "../util"; +import { GetBaseline } from "../../util"; import type { BMSTablesDataset } from "types"; export type EcConstants = Array<{ diff --git a/sieglinde/tsconfig.json b/sieglinde/tsconfig.json index 71432fcc5..c8de1d4e2 100644 --- a/sieglinde/tsconfig.json +++ b/sieglinde/tsconfig.json @@ -1,8 +1,9 @@ { "extends": "../tsconfig.json", "compilerOptions": { + "rootDir": "src", "baseUrl": "src", - "outDir": "./js", + "outDir": "js", "lib": [ "ES2019" ], @@ -17,7 +18,9 @@ "tachi-common/*": [ "../../common/src/*" ] - } + }, + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo" }, "ts-node": { "require": [ @@ -29,5 +32,10 @@ ], "exclude": [ "node_modules", + ], + "references": [ + { + "path": "../common" + } ] } \ No newline at end of file diff --git a/tachi.code-workspace b/tachi.code-workspace index 1a93deffd..481407a88 100644 --- a/tachi.code-workspace +++ b/tachi.code-workspace @@ -20,6 +20,10 @@ "path": "bot", "name": "tachi-bot" }, + { + "path": "github-bot", + "name": "tachi-github-bot" + }, { "path": "database-seeds", "name": "tachi-database-seeds" diff --git a/tsconfig.json b/tsconfig.json index 58e16d4d4..eb8e7e4c9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,12 +18,22 @@ "files": [], "references": [ { - "path": "./common", - "prepend": true + "path": "./common" }, { - "path": "./server", - "prepend": true + "path": "./server" + }, + { + "path": "./bot" + }, + { + "path": "./client" + }, + { + "path": "./sieglinde" + }, + { + "path": "./database-seeds/scripts" } ] } \ No newline at end of file