diff --git a/.changeset/early-kangaroos-count.md b/.changeset/early-kangaroos-count.md new file mode 100644 index 0000000000..da2f3e7e3f --- /dev/null +++ b/.changeset/early-kangaroos-count.md @@ -0,0 +1,10 @@ +--- +"@scow/portal-server": patch +"@scow/mis-server": patch +"@scow/portal-web": patch +"@scow/mis-web": patch +"@scow/utils": patch +"@scow/auth": patch +--- + +系统启动时,各个容器在日志中打印版本信息 diff --git a/.gitignore b/.gitignore index 6782ed4df5..31eebfea15 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ internal .turbo out dist +version.json diff --git a/apps/auth/package.json b/apps/auth/package.json index bd4e8770bd..74215ee7e2 100644 --- a/apps/auth/package.json +++ b/apps/auth/package.json @@ -29,6 +29,7 @@ "@scow/config": "workspace:*", "@scow/lib-config": "workspace:*", "@scow/lib-ssh": "workspace:*", + "@scow/utils": "workspace:*", "@sinclair/typebox": "0.25.24", "asn1": "0.2.6", "fastify": "4.13.0", diff --git a/apps/auth/src/app.ts b/apps/auth/src/app.ts index b08b001de2..63c1763be4 100644 --- a/apps/auth/src/app.ts +++ b/apps/auth/src/app.ts @@ -12,6 +12,7 @@ import createError from "@fastify/error"; import { omitConfigSpec } from "@scow/lib-config"; +import { readVersionFile } from "@scow/utils/build/version"; import fastify, { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback } from "fastify"; import { config } from "src/config/env"; import { plugins } from "src/plugins"; @@ -53,7 +54,9 @@ export function buildApp(pluginOverrides?: PluginOverrides) { }, }); - server.log.info({ config: omitConfigSpec(config) }, "Loaded config"); + server.log.info({ version: readVersionFile() }, "Running @scow/auth"); + + server.log.info({ config: omitConfigSpec(config) }, "Loaded env config"); applyPlugins(server, pluginOverrides); diff --git a/apps/mis-server/package.json b/apps/mis-server/package.json index 085b774a09..4f989cc1dd 100644 --- a/apps/mis-server/package.json +++ b/apps/mis-server/package.json @@ -39,6 +39,7 @@ "@sinclair/typebox": "0.25.24", "@scow/lib-auth": "workspace:*", "@scow/protos": "workspace:*", + "@scow/utils": "workspace:*", "dotenv": "16.0.3", "node-cron": "3.0.2", "uuid": "9.0.0", diff --git a/apps/mis-server/src/app.ts b/apps/mis-server/src/app.ts index 0adb8b8c6f..412f00d39d 100644 --- a/apps/mis-server/src/app.ts +++ b/apps/mis-server/src/app.ts @@ -11,6 +11,8 @@ */ import { Server } from "@ddadaal/tsgrpc-server"; +import { omitConfigSpec } from "@scow/lib-config"; +import { readVersionFile } from "@scow/utils/build/version"; import { updateBlockStatusInSlurm } from "src/bl/block"; import { config } from "src/config/env"; import { plugins } from "src/plugins"; @@ -37,6 +39,9 @@ export async function createServer() { }, }); + server.logger.info({ version: readVersionFile() }, "@scow/mis-server: "); + server.logger.info({ config: omitConfigSpec(config) }, "Loaded env config"); + for (const plugin of plugins) { await server.register(plugin); } diff --git a/apps/mis-web/config.js b/apps/mis-web/config.js index 6365e12ae3..61c6f72b24 100644 --- a/apps/mis-web/config.js +++ b/apps/mis-web/config.js @@ -9,6 +9,7 @@ const { DEFAULT_PRIMARY_COLOR, getUiConfig } = require("@scow/config/build/ui"); const { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER } = require("next/constants"); const { join } = require("path"); const { getCapabilities } = require("@scow/lib-auth"); +const { readVersionFile } = require("@scow/utils/build/version"); /** * Get auth capabilities @@ -116,6 +117,8 @@ const buildRuntimeConfig = async (phase, basePath) => { }; if (!building) { + console.log("Running @scow/mis-web"); + console.log("Version: ", readVersionFile()); console.log("Server Runtime Config", serverRuntimeConfig); console.log("Public Runtime Config", publicRuntimeConfig); } diff --git a/apps/portal-server/package.json b/apps/portal-server/package.json index df69266da9..eb113dc698 100644 --- a/apps/portal-server/package.json +++ b/apps/portal-server/package.json @@ -28,6 +28,7 @@ "@scow/lib-slurm": "workspace:*", "@scow/lib-ssh": "workspace:*", "@scow/protos": "workspace:*", + "@scow/utils": "workspace:*", "@sinclair/typebox": "0.25.24", "dotenv": "16.0.3", "node-cron": "3.0.2", diff --git a/apps/portal-server/src/app.ts b/apps/portal-server/src/app.ts index adab14136d..d057ae847c 100644 --- a/apps/portal-server/src/app.ts +++ b/apps/portal-server/src/app.ts @@ -11,6 +11,8 @@ */ import { Server } from "@ddadaal/tsgrpc-server"; +import { omitConfigSpec } from "@scow/lib-config"; +import { readVersionFile } from "@scow/utils/build/version"; import { config } from "src/config/env"; import { plugins } from "src/plugins"; import { appServiceServer } from "src/services/app"; @@ -33,6 +35,9 @@ export async function createServer() { }, }); + server.logger.info({ version: readVersionFile() }, "Running @scow/portal-server"); + server.logger.info({ config: omitConfigSpec(config) }, "Loaded env config"); + for (const plugin of plugins) { await server.register(plugin); } diff --git a/apps/portal-web/config.js b/apps/portal-web/config.js index 56cb7aab80..f6c1c5d3e9 100644 --- a/apps/portal-web/config.js +++ b/apps/portal-web/config.js @@ -5,6 +5,7 @@ const { join } = require("path"); const { homedir } = require("os"); const { PHASE_DEVELOPMENT_SERVER, PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_SERVER, PHASE_TEST } = require("next/constants"); +const { readVersionFile } = require("@scow/utils/build/version"); const { getCapabilities } = require("@scow/lib-auth"); const { DEFAULT_PRIMARY_COLOR, getUiConfig } = require("@scow/config/build/ui"); const { getPortalConfig } = require("@scow/config/build/portal"); @@ -145,6 +146,8 @@ const buildRuntimeConfig = async (phase, basePath) => { } if (!building && !testenv) { + console.log("Running @scow/portal-web"); + console.log("Version", readVersionFile()); console.log("Server Runtime Config", serverRuntimeConfig); console.log("Public Runtime Config", publicRuntimeConfig); } diff --git a/dockerfiles/Dockerfile.auth b/dockerfiles/Dockerfile.auth index 4c1ac8a519..7acb6e059e 100644 --- a/dockerfiles/Dockerfile.auth +++ b/dockerfiles/Dockerfile.auth @@ -11,7 +11,7 @@ FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS base -RUN apk update && apk add libc6-compat python3 make gcc g++ +RUN apk update && apk add libc6-compat python3 make gcc g++ git RUN corepack enable @@ -26,6 +26,8 @@ WORKDIR /app COPY . . +RUN node scripts/createVersionFile.mjs version.json + RUN pnpm dlx turbo prune --scope="@scow/auth" --docker FROM base AS builder @@ -40,12 +42,14 @@ COPY tsconfig.json .eslintrc.json turbo.json ./ COPY libs/tsconfig.json ./libs/ COPY protos ./protos - RUN pnpm build COPY scripts scripts RUN node scripts/copyDist.mjs -RUN cd dist && pnpm i --offline --prod --frozen-lockfile + +WORKDIR /app/dist + +RUN pnpm i --offline --prod --frozen-lockfile FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS runner @@ -59,4 +63,6 @@ EXPOSE 5000 WORKDIR /app/apps/auth +COPY --from=pruner /app/version.json ./version.json + CMD ["npm", "run", "serve"] diff --git a/dockerfiles/Dockerfile.mis-server b/dockerfiles/Dockerfile.mis-server index 3762dd0de3..b842db6363 100644 --- a/dockerfiles/Dockerfile.mis-server +++ b/dockerfiles/Dockerfile.mis-server @@ -11,15 +11,15 @@ FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS base -RUN apk update && apk add libc6-compat python3 make gcc g++ curl +RUN apk update && apk add libc6-compat python3 make gcc g++ curl git ARG BUF_VERSION="1.11.0" RUN BIN="/usr/local/bin" && \ -VERSION="${BUF_VERSION}" && \ + VERSION="${BUF_VERSION}" && \ curl -sSL \ - "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ - -o "${BIN}/buf" && \ + "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ + -o "${BIN}/buf" && \ chmod +x "${BIN}/buf" RUN corepack enable @@ -36,6 +36,7 @@ WORKDIR /app COPY . . +RUN node scripts/createVersionFile.mjs version.json RUN pnpm dlx turbo prune --scope="@scow/mis-server" --docker FROM base AS builder @@ -54,7 +55,10 @@ RUN pnpm build COPY scripts scripts RUN node scripts/copyDist.mjs -RUN cd dist && pnpm i --offline --prod --frozen-lockfile + +WORKDIR /app/dist + +RUN pnpm i --offline --prod --frozen-lockfile FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS runner @@ -67,4 +71,6 @@ EXPOSE 5000 WORKDIR /app/apps/mis-server +COPY --from=pruner /app/version.json ./version.json + CMD ["npm", "run", "serve"] diff --git a/dockerfiles/Dockerfile.mis-web b/dockerfiles/Dockerfile.mis-web index 3946010463..6475c00eaa 100644 --- a/dockerfiles/Dockerfile.mis-web +++ b/dockerfiles/Dockerfile.mis-web @@ -11,15 +11,15 @@ FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS base -RUN apk update && apk add libc6-compat python3 make gcc g++ curl +RUN apk update && apk add libc6-compat python3 make gcc g++ curl git ARG BUF_VERSION="1.11.0" RUN BIN="/usr/local/bin" && \ -VERSION="${BUF_VERSION}" && \ + VERSION="${BUF_VERSION}" && \ curl -sSL \ - "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ - -o "${BIN}/buf" && \ + "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ + -o "${BIN}/buf" && \ chmod +x "${BIN}/buf" RUN corepack enable @@ -35,7 +35,7 @@ WORKDIR /app COPY . . -# Network connection required +RUN node scripts/createVersionFile.mjs version.json RUN pnpm dlx turbo prune --scope="@scow/mis-web" --docker FROM base AS builder @@ -54,7 +54,10 @@ RUN pnpm build COPY scripts scripts RUN node scripts/copyDist.mjs -RUN cd dist && pnpm i --offline --prod --frozen-lockfile + +WORKDIR /app/dist + +RUN pnpm i --offline --prod --frozen-lockfile FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS runner @@ -68,4 +71,6 @@ EXPOSE 3000 WORKDIR /app/apps/mis-web +COPY --from=pruner /app/version.json ./version.json + CMD ["npm", "run", "serve"] diff --git a/dockerfiles/Dockerfile.portal-server b/dockerfiles/Dockerfile.portal-server index 23ff21cccb..a42c09af94 100644 --- a/dockerfiles/Dockerfile.portal-server +++ b/dockerfiles/Dockerfile.portal-server @@ -11,15 +11,15 @@ FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS base -RUN apk update && apk add libc6-compat python3 make gcc g++ curl +RUN apk update && apk add libc6-compat python3 make gcc g++ curl git ARG BUF_VERSION="1.11.0" RUN BIN="/usr/local/bin" && \ -VERSION="${BUF_VERSION}" && \ + VERSION="${BUF_VERSION}" && \ curl -sSL \ - "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ - -o "${BIN}/buf" && \ + "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ + -o "${BIN}/buf" && \ chmod +x "${BIN}/buf" RUN corepack enable @@ -35,6 +35,7 @@ WORKDIR /app COPY . . +RUN node scripts/createVersionFile.mjs version.json RUN pnpm dlx turbo prune --scope="@scow/portal-server" --docker FROM base AS builder @@ -53,7 +54,10 @@ RUN pnpm build COPY scripts scripts RUN node scripts/copyDist.mjs -RUN cd dist && pnpm i --offline --prod --frozen-lockfile + +WORKDIR /app/dist + +RUN pnpm i --offline --prod --frozen-lockfile FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS runner @@ -67,4 +71,6 @@ EXPOSE 5000 WORKDIR /app/apps/portal-server +COPY --from=pruner /app/version.json ./version.json + CMD ["npm", "run", "serve"] diff --git a/dockerfiles/Dockerfile.portal-web b/dockerfiles/Dockerfile.portal-web index 9d4ea9e7d7..174f66859d 100644 --- a/dockerfiles/Dockerfile.portal-web +++ b/dockerfiles/Dockerfile.portal-web @@ -11,15 +11,15 @@ FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS base -RUN apk update && apk add libc6-compat python3 make gcc g++ curl +RUN apk update && apk add libc6-compat python3 make gcc g++ curl git ARG BUF_VERSION="1.11.0" RUN BIN="/usr/local/bin" && \ -VERSION="${BUF_VERSION}" && \ + VERSION="${BUF_VERSION}" && \ curl -sSL \ - "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ - -o "${BIN}/buf" && \ + "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ + -o "${BIN}/buf" && \ chmod +x "${BIN}/buf" RUN corepack enable @@ -35,6 +35,7 @@ WORKDIR /app COPY . . +RUN node scripts/createVersionFile.mjs version.json RUN pnpm dlx turbo prune --scope="@scow/portal-web" --docker FROM base AS builder @@ -53,7 +54,10 @@ RUN pnpm build COPY scripts scripts RUN node scripts/copyDist.mjs -RUN cd dist && pnpm i --offline --prod --frozen-lockfile + +WORKDIR /app/dist + +RUN pnpm i --offline --prod --frozen-lockfile FROM node:hydrogen-alpine@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 AS runner @@ -67,4 +71,6 @@ EXPOSE 3000 WORKDIR /app/apps/portal-web +COPY --from=pruner /app/version.json ./version.json + CMD ["npm", "run", "serve"] diff --git a/libs/utils/src/version.ts b/libs/utils/src/version.ts new file mode 100644 index 0000000000..46ff848ee8 --- /dev/null +++ b/libs/utils/src/version.ts @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy + * SCOW is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +import { existsSync, readFileSync } from "fs"; + +interface VersionJsonInfo { + tag?: string; + commit: string; +} + +export interface VersionInfo extends VersionJsonInfo {} + +export function readVersionFile(versionJsonFileName = "version.json") { + + const jsonInfo: VersionJsonInfo = existsSync(versionJsonFileName) + ? JSON.parse(readFileSync(versionJsonFileName, "utf-8")) + : {}; + + return jsonInfo; } + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 985479dbe5..f46d5e892a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -85,6 +85,7 @@ importers: '@scow/config': workspace:* '@scow/lib-config': workspace:* '@scow/lib-ssh': workspace:* + '@scow/utils': workspace:* '@sinclair/typebox': 0.25.24 '@types/asn1': 0.2.0 '@types/ldapjs': 2.2.5 @@ -106,6 +107,7 @@ importers: '@scow/config': link:../../libs/config '@scow/lib-config': link:../../libs/libconfig '@scow/lib-ssh': link:../../libs/ssh + '@scow/utils': link:../../libs/utils '@sinclair/typebox': 0.25.24 asn1: 0.2.6 fastify: registry.npmmirror.com/fastify/4.13.0 @@ -142,6 +144,7 @@ importers: '@scow/lib-slurm': workspace:* '@scow/lib-ssh': workspace:* '@scow/protos': workspace:* + '@scow/utils': workspace:* '@sinclair/typebox': 0.25.24 '@types/google-protobuf': 3.15.6 '@types/node-cron': 3.0.7 @@ -168,6 +171,7 @@ importers: '@scow/lib-slurm': link:../../libs/slurm '@scow/lib-ssh': link:../../libs/ssh '@scow/protos': link:../../libs/protos + '@scow/utils': link:../../libs/utils '@sinclair/typebox': 0.25.24 dotenv: 16.0.3 node-cron: 3.0.2 @@ -279,6 +283,7 @@ importers: '@scow/lib-slurm': workspace:* '@scow/lib-ssh': workspace:* '@scow/protos': workspace:* + '@scow/utils': workspace:* '@sinclair/typebox': 0.25.24 '@types/node-cron': 3.0.7 '@types/shell-quote': 1.7.1 @@ -300,6 +305,7 @@ importers: '@scow/lib-slurm': link:../../libs/slurm '@scow/lib-ssh': link:../../libs/ssh '@scow/protos': link:../../libs/protos + '@scow/utils': link:../../libs/utils '@sinclair/typebox': 0.25.24 dayjs: 1.11.7 dotenv: 16.0.3 @@ -6296,7 +6302,7 @@ packages: /axios/0.21.4_debug@4.3.4: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.15.2_debug@4.3.4 + follow-redirects: 1.15.2 transitivePeerDependencies: - debug dev: true @@ -9061,19 +9067,6 @@ packages: peerDependenciesMeta: debug: optional: true - dev: false - - /follow-redirects/1.15.2_debug@4.3.4: - resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} - engines: {node: '>=4.0'} - peerDependencies: - debug: '*' - peerDependenciesMeta: - debug: - optional: true - dependencies: - debug: 4.3.4 - dev: true /for-each/0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} diff --git a/scripts/createVersionFile.mjs b/scripts/createVersionFile.mjs new file mode 100644 index 0000000000..54ba2e5244 --- /dev/null +++ b/scripts/createVersionFile.mjs @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2022 Peking University and Peking University Institute for Computing and Digital Economy + * SCOW is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +/** + * Create a json file at the specified path + * containing the commit number and tag number of current commit + * + * Usage: + * node scripts/createVersionFile.mjs [json file path] + * + * e.g. node scripts/createVersionFile.mjs version.json + */ + +import { execSync } from "node:child_process"; +import { writeFileSync } from "node:fs"; + +let outputFile = process.argv[2] || "version.json"; + +const exec = (cmd) => execSync(cmd, { encoding: "utf-8" }); + +const tags = exec("git tag --points-at HEAD").split("\n"); +const commit = exec("git rev-parse HEAD").trim(); + +const versionObject = { + tag: tags[0] || undefined, + commit, +}; + +writeFileSync(outputFile, JSON.stringify(versionObject));