feat: dynamic app version sourced from root VERSION file
Replaces the hardcoded version string in SettingsPage.tsx with a single
source of truth: a /VERSION file at the repo root. To cut a new release,
edit only that one file.
Frontend:
- vite.config.ts reads /VERSION at dev-server startup and injects it as
the __APP_VERSION__ global via Vite's define mechanism (compile-time,
zero runtime cost). Falls back to VITE_APP_VERSION env var for prod
Docker builds that pass it as a build arg.
- vite-env.d.ts adds the TypeScript declaration for __APP_VERSION__.
- SettingsPage.tsx Badge now renders {__APP_VERSION__} instead of the
literal string.
Backend:
- app.controller.ts reads /VERSION once at module load and includes
"version" in both GET /api and GET /api/health responses.
- NewRelicTransactionInterceptor tags every NR transaction with
newrelic.addCustomAttribute('appVersion', version) so releases can be
compared in NRQL: SELECT average(duration) FROM Transaction WHERE
appVersion = '2026.5.22'
Docker:
- docker-compose.yml mounts ./VERSION:/app/VERSION:ro in both backend
and frontend dev containers.
- Production Dockerfiles include COPY VERSION ./ with a comment
instructing CI to copy the root VERSION into each build context before
docker build.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,9 @@ WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY . .
|
||||
# VERSION must be copied into the build context before `docker build`.
|
||||
# In CI / deploy scripts run: cp VERSION frontend/VERSION (or pass VITE_APP_VERSION as build arg)
|
||||
COPY VERSION ./
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: Serve with nginx
|
||||
|
||||
@@ -237,7 +237,7 @@ export function SettingsPage() {
|
||||
</Group>
|
||||
<Group justify="space-between">
|
||||
<Text size="sm" c="dimmed">Version</Text>
|
||||
<Badge variant="light">2026.4.6</Badge>
|
||||
<Badge variant="light">{__APP_VERSION__}</Badge>
|
||||
</Group>
|
||||
<Group justify="space-between">
|
||||
<Text size="sm" c="dimmed">API</Text>
|
||||
|
||||
3
frontend/src/vite-env.d.ts
vendored
3
frontend/src/vite-env.d.ts
vendored
@@ -4,3 +4,6 @@ declare module '*.svg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
/** Injected by vite.config.ts define — value comes from the root /VERSION file. */
|
||||
declare const __APP_VERSION__: string;
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
// Read the canonical version from /VERSION (repo root, mounted at /app/VERSION in Docker).
|
||||
// Falls back to the VITE_APP_VERSION env var so production Docker builds can pass it
|
||||
// as a build arg (--build-arg VITE_APP_VERSION=$(cat VERSION)) without needing the file.
|
||||
function readAppVersion(): string {
|
||||
try {
|
||||
return fs.readFileSync(path.resolve(__dirname, 'VERSION'), 'utf-8').trim();
|
||||
} catch {
|
||||
return process.env.VITE_APP_VERSION ?? 'dev';
|
||||
}
|
||||
}
|
||||
|
||||
const APP_VERSION = readAppVersion();
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
define: {
|
||||
// Injected at compile time — use __APP_VERSION__ anywhere in frontend source.
|
||||
__APP_VERSION__: JSON.stringify(APP_VERSION),
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
|
||||
Reference in New Issue
Block a user