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

feat: 启动容器时日志打印版本信息 #477

Merged
merged 8 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .changeset/early-kangaroos-count.md
Original file line number Diff line number Diff line change
@@ -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
---

系统启动时,各个容器在日志中打印版本信息
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ internal
.turbo
out
dist
version.json
1 change: 1 addition & 0 deletions apps/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion apps/auth/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions apps/mis-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions apps/mis-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions apps/mis-web/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions apps/portal-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions apps/portal-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions apps/portal-web/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 9 additions & 3 deletions dockerfiles/Dockerfile.auth
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -59,4 +63,6 @@ EXPOSE 5000

WORKDIR /app/apps/auth

COPY --from=pruner /app/version.json ./version.json

CMD ["npm", "run", "serve"]
16 changes: 11 additions & 5 deletions dockerfiles/Dockerfile.mis-server
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -67,4 +71,6 @@ EXPOSE 5000

WORKDIR /app/apps/mis-server

COPY --from=pruner /app/version.json ./version.json

CMD ["npm", "run", "serve"]
17 changes: 11 additions & 6 deletions dockerfiles/Dockerfile.mis-web
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -68,4 +71,6 @@ EXPOSE 3000

WORKDIR /app/apps/mis-web

COPY --from=pruner /app/version.json ./version.json

CMD ["npm", "run", "serve"]
16 changes: 11 additions & 5 deletions dockerfiles/Dockerfile.portal-server
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -67,4 +71,6 @@ EXPOSE 5000

WORKDIR /app/apps/portal-server

COPY --from=pruner /app/version.json ./version.json

CMD ["npm", "run", "serve"]
16 changes: 11 additions & 5 deletions dockerfiles/Dockerfile.portal-web
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -67,4 +71,6 @@ EXPOSE 3000

WORKDIR /app/apps/portal-web

COPY --from=pruner /app/version.json ./version.json

CMD ["npm", "run", "serve"]
30 changes: 30 additions & 0 deletions libs/utils/src/version.ts
Original file line number Diff line number Diff line change
@@ -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; }


Loading