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 ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
COPY . .
|
||||||
|
# VERSION must be copied into the build context before `docker build`.
|
||||||
|
# In CI / deploy scripts run: cp VERSION backend/VERSION (or pass --build-arg)
|
||||||
|
COPY VERSION ./
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Production
|
# Stage 2: Production
|
||||||
@@ -17,9 +20,10 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci --omit=dev && npm cache clean --force
|
RUN npm ci --omit=dev && npm cache clean --force
|
||||||
|
|
||||||
# Copy compiled output and New Relic preload from builder
|
# Copy compiled output, New Relic preload, and VERSION from builder
|
||||||
COPY --from=builder /app/dist ./dist
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/newrelic-preload.js ./newrelic-preload.js
|
COPY --from=builder /app/newrelic-preload.js ./newrelic-preload.js
|
||||||
|
COPY --from=builder /app/VERSION ./VERSION
|
||||||
|
|
||||||
# New Relic agent — configured entirely via environment variables
|
# New Relic agent — configured entirely via environment variables
|
||||||
ENV NEW_RELIC_NO_CONFIG_FILE=true
|
ENV NEW_RELIC_NO_CONFIG_FILE=true
|
||||||
|
|||||||
@@ -1,4 +1,20 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
import { Controller, Get } from '@nestjs/common';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
|
// Read at module load time — one I/O call for the lifetime of the process.
|
||||||
|
// VERSION file lives at the container root (/app/VERSION), mounted from the
|
||||||
|
// repo root via docker-compose. Falls back to package.json version if absent
|
||||||
|
// (e.g. in environments that pass APP_VERSION as an env var instead).
|
||||||
|
function readAppVersion(): string {
|
||||||
|
try {
|
||||||
|
return readFileSync(resolve(process.cwd(), 'VERSION'), 'utf-8').trim();
|
||||||
|
} catch {
|
||||||
|
return process.env.APP_VERSION ?? 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const APP_VERSION = readAppVersion();
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
@@ -13,6 +29,7 @@ export class AppController {
|
|||||||
getRoot() {
|
getRoot() {
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
|
version: APP_VERSION,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
service: 'hoa-financial-platform',
|
service: 'hoa-financial-platform',
|
||||||
};
|
};
|
||||||
@@ -23,6 +40,7 @@ export class AppController {
|
|||||||
getHealth() {
|
getHealth() {
|
||||||
return {
|
return {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
|
version: APP_VERSION,
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
service: 'hoa-financial-platform',
|
service: 'hoa-financial-platform',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a meaningful New Relic transaction name for every HTTP request.
|
* Sets a meaningful New Relic transaction name for every HTTP request and
|
||||||
|
* tags each transaction with the running app version.
|
||||||
*
|
*
|
||||||
* Without this, NestJS's setGlobalPrefix('api') causes the New Relic Express
|
* Without the name override, NestJS's setGlobalPrefix('api') causes the New Relic
|
||||||
* instrumentation to group ALL requests under the generic bucket
|
* Express instrumentation to group ALL requests under the generic bucket
|
||||||
* "Expressjs/GET/api$" (the compiled regex for the global prefix router),
|
* "Expressjs/GET/api$" (the compiled regex for the global prefix router),
|
||||||
* making per-endpoint APM data completely blind.
|
* making per-endpoint APM data completely blind.
|
||||||
*
|
*
|
||||||
@@ -14,12 +17,25 @@ import { Request } from 'express';
|
|||||||
* the matched pattern, e.g. "/api/accounts/:id") and calls newrelic.setTransactionName()
|
* the matched pattern, e.g. "/api/accounts/:id") and calls newrelic.setTransactionName()
|
||||||
* to override the auto-detected name with "METHOD /route/pattern".
|
* to override the auto-detected name with "METHOD /route/pattern".
|
||||||
*
|
*
|
||||||
|
* The appVersion custom attribute lets you filter / compare releases in NRQL:
|
||||||
|
* SELECT average(duration) FROM Transaction WHERE appVersion = '2026.5.22'
|
||||||
|
*
|
||||||
* Gracefully no-ops when:
|
* Gracefully no-ops when:
|
||||||
* - NEW_RELIC_ENABLED is not 'true' (dev / CI)
|
* - NEW_RELIC_ENABLED is not 'true' (dev / CI)
|
||||||
* - newrelic package is not installed
|
* - newrelic package is not installed
|
||||||
* - The NR agent fails to load for any reason
|
* - The NR agent fails to load for any reason
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function readAppVersion(): string {
|
||||||
|
try {
|
||||||
|
return readFileSync(resolve(process.cwd(), 'VERSION'), 'utf-8').trim();
|
||||||
|
} catch {
|
||||||
|
return process.env.APP_VERSION ?? 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const APP_VERSION = readAppVersion();
|
||||||
|
|
||||||
let newrelic: any;
|
let newrelic: any;
|
||||||
try {
|
try {
|
||||||
if (process.env.NEW_RELIC_ENABLED === 'true') {
|
if (process.env.NEW_RELIC_ENABLED === 'true') {
|
||||||
@@ -40,6 +56,9 @@ export class NewRelicTransactionInterceptor implements NestInterceptor {
|
|||||||
// 404s get a useful name like "GET /api/unknown-path" instead of "Expressjs/GET/api$".
|
// 404s get a useful name like "GET /api/unknown-path" instead of "Expressjs/GET/api$".
|
||||||
const route: string = (req.route as any)?.path ?? req.path;
|
const route: string = (req.route as any)?.path ?? req.path;
|
||||||
newrelic.setTransactionName(`${req.method} ${route}`);
|
newrelic.setTransactionName(`${req.method} ${route}`);
|
||||||
|
// Tag every transaction with the release version so you can segment NR
|
||||||
|
// dashboards and alerts by deployment.
|
||||||
|
newrelic.addCustomAttribute('appVersion', APP_VERSION);
|
||||||
}
|
}
|
||||||
return next.handle();
|
return next.handle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ services:
|
|||||||
- ./backend/nest-cli.json:/app/nest-cli.json
|
- ./backend/nest-cli.json:/app/nest-cli.json
|
||||||
- ./backend/tsconfig.json:/app/tsconfig.json
|
- ./backend/tsconfig.json:/app/tsconfig.json
|
||||||
- ./backend/tsconfig.build.json:/app/tsconfig.build.json
|
- ./backend/tsconfig.build.json:/app/tsconfig.build.json
|
||||||
|
- ./VERSION:/app/VERSION:ro
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -80,6 +81,7 @@ services:
|
|||||||
- ./frontend/src:/app/src
|
- ./frontend/src:/app/src
|
||||||
- ./frontend/index.html:/app/index.html
|
- ./frontend/index.html:/app/index.html
|
||||||
- ./frontend/vite.config.ts:/app/vite.config.ts
|
- ./frontend/vite.config.ts:/app/vite.config.ts
|
||||||
|
- ./VERSION:/app/VERSION:ro
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ WORKDIR /app
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
COPY . .
|
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
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Serve with nginx
|
# Stage 2: Serve with nginx
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ export function SettingsPage() {
|
|||||||
</Group>
|
</Group>
|
||||||
<Group justify="space-between">
|
<Group justify="space-between">
|
||||||
<Text size="sm" c="dimmed">Version</Text>
|
<Text size="sm" c="dimmed">Version</Text>
|
||||||
<Badge variant="light">2026.4.6</Badge>
|
<Badge variant="light">{__APP_VERSION__}</Badge>
|
||||||
</Group>
|
</Group>
|
||||||
<Group justify="space-between">
|
<Group justify="space-between">
|
||||||
<Text size="sm" c="dimmed">API</Text>
|
<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;
|
const src: string;
|
||||||
export default src;
|
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 { defineConfig } from 'vite';
|
||||||
import react from '@vitejs/plugin-react';
|
import react from '@vitejs/plugin-react';
|
||||||
import path from 'path';
|
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({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
|
define: {
|
||||||
|
// Injected at compile time — use __APP_VERSION__ anywhere in frontend source.
|
||||||
|
__APP_VERSION__: JSON.stringify(APP_VERSION),
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, './src'),
|
'@': path.resolve(__dirname, './src'),
|
||||||
|
|||||||
Reference in New Issue
Block a user