From dc4d88fc4731d3e81ef38c078bd71abc8731bc1e Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sun, 5 May 2024 01:07:35 +0800 Subject: [PATCH] chore: add docker canary image version display --- .github/workflows/docker-publish-canary.yml | 1 + Dockerfile | 5 +++++ src/client/pages/Layout.tsx | 3 +-- src/client/pages/Layout/UserConfig.tsx | 2 +- src/client/utils/env.ts | 3 ++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker-publish-canary.yml b/.github/workflows/docker-publish-canary.yml index 1e27cbb..df131ac 100644 --- a/.github/workflows/docker-publish-canary.yml +++ b/.github/workflows/docker-publish-canary.yml @@ -51,3 +51,4 @@ jobs: push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: VERSION=canary-${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 0cfe507..13236b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,10 +17,15 @@ RUN apk add --update --no-cache python3 py3-pip g++ make FROM base AS static WORKDIR /app/tianji +# use with --build-arg VERSION=xxxx +ARG VERSION + COPY . . RUN pnpm install --frozen-lockfile +ENV VITE_VERSION=$VERSION + RUN pnpm build:static # Tianji server ------------------------------ diff --git a/src/client/pages/Layout.tsx b/src/client/pages/Layout.tsx index 227b676..aee0cf5 100644 --- a/src/client/pages/Layout.tsx +++ b/src/client/pages/Layout.tsx @@ -7,12 +7,11 @@ import { Button, Divider, Drawer, Dropdown } from 'antd'; import { useUserStore } from '../store/user'; import { useLogout } from '../api/model/user'; import { ColorSchemeSwitcher } from '../components/ColorSchemeSwitcher'; -import { version } from '@tianji/shared'; +import { version } from '@/utils/env'; import { useIsMobile } from '../hooks/useIsMobile'; import { RiMenuUnfoldLine } from 'react-icons/ri'; import { useTranslation } from '@i18next-toolkit/react'; import { LanguageSelector } from '../components/LanguageSelector'; -import { useGlobalConfig } from '../hooks/useConfig'; export const Layout: React.FC = React.memo(() => { const [params] = useSearchParams(); diff --git a/src/client/pages/Layout/UserConfig.tsx b/src/client/pages/Layout/UserConfig.tsx index 89364c1..a4dd16a 100644 --- a/src/client/pages/Layout/UserConfig.tsx +++ b/src/client/pages/Layout/UserConfig.tsx @@ -20,7 +20,7 @@ import { useCurrentWorkspaceId, useUserInfo, useUserStore } from '@/store/user'; import { languages } from '@/utils/constants'; import { useTranslation, setLanguage } from '@i18next-toolkit/react'; import { useNavigate } from '@tanstack/react-router'; -import { version } from '@tianji/shared'; +import { version } from '@/utils/env'; import React from 'react'; import { LuMoreVertical } from 'react-icons/lu'; diff --git a/src/client/utils/env.ts b/src/client/utils/env.ts index 6bbf6f1..c3b515c 100644 --- a/src/client/utils/env.ts +++ b/src/client/utils/env.ts @@ -1,5 +1,6 @@ -import { version } from '@tianji/shared'; +import { version as packageJsonVersion } from '@tianji/shared'; export const isDev = import.meta.env.MODE === 'development'; +export const version = import.meta.env.VITE_VERSION || packageJsonVersion; export const anonymousTelemetryUrl = `https://tianji.moonrailgun.com/telemetry/clnzoxcy10001vy2ohi4obbi0/cltg3op5n007lrw4gvr3p8syj.gif?name=tianji-oss&url=${window.location.origin}&v=${version}`;