Skip to content

Commit 97351b4

Browse files
InfantLabclaude
andcommitted
fix(version): use runtime config for version display
- Updated nuxt.config.ts to include version 0.3.1 and git hash in public runtime config - Simplified /api/version endpoint to use runtime config instead of filesystem reads - Updated Dockerfile to pass GIT_HASH and GIT_SHORT_HASH as build args and env vars - This fixes the 'vunknown+unknown' issue in production by making version available at build time Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 46671c4 commit 97351b4

3 files changed

Lines changed: 23 additions & 29 deletions

File tree

Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ FROM oven/bun:1-alpine AS builder
33

44
WORKDIR /app
55

6-
# Install build dependencies (CA certs for HTTPS, build tools for native modules)
7-
RUN apk add --no-cache ca-certificates
6+
# Build arguments for version info
7+
ARG GIT_HASH=unknown
8+
ARG GIT_SHORT_HASH=unknown
9+
10+
# Install build dependencies (CA certs for HTTPS, build tools for native modules, git for version)
11+
RUN apk add --no-cache ca-certificates git
812

913
# Copy package files
1014
COPY app/package.json app/bun.lock* ./
@@ -21,6 +25,10 @@ RUN bun run build:docker
2125
# Production stage - Alpine for minimal attack surface
2226
FROM oven/bun:1-alpine AS production
2327

28+
# Build arguments (passed from builder)
29+
ARG GIT_HASH=unknown
30+
ARG GIT_SHORT_HASH=unknown
31+
2432
WORKDIR /app
2533

2634
# Install runtime dependencies
@@ -53,6 +61,8 @@ ENV NODE_ENV=production
5361
ENV DATABASE_URL=file:/data/db.sqlite
5462
ENV HOST=0.0.0.0
5563
ENV PORT=3000
64+
ENV GIT_HASH=${GIT_HASH}
65+
ENV GIT_SHORT_HASH=${GIT_SHORT_HASH}
5666

5767
# Switch to non-root user
5868
USER nuxt

app/nuxt.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ export default defineNuxtConfig({
4747
// Public (exposed to client)
4848
public: {
4949
appName: "Tada",
50-
appVersion: "0.3.0",
50+
appVersion: "0.3.1",
51+
gitHash: process.env["GIT_HASH"] || "",
52+
gitShortHash: process.env["GIT_SHORT_HASH"] || "",
5153
// Voice feature flags
5254
voiceEnabled: process.env["VOICE_ENABLED"] !== "false",
5355
voiceFreeLimit: parseInt(process.env["VOICE_FREE_LIMIT"] || "50", 10),

app/server/api/version.get.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,20 @@
44
* Returns app version and build information
55
*/
66

7-
import { execSync } from "child_process";
8-
import { readFileSync } from "fs";
9-
import { join } from "path";
10-
117
export default defineEventHandler(() => {
12-
// Read version from package.json
13-
let appVersion = "unknown";
14-
try {
15-
const packagePath = join(process.cwd(), "package.json");
16-
const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
17-
appVersion = packageJson.version;
18-
} catch (error) {
19-
console.error("Failed to read package.json version:", error);
20-
}
8+
const config = useRuntimeConfig();
219

22-
// Get git commit hash
23-
let gitHash = "unknown";
24-
let gitShortHash = "unknown";
25-
try {
26-
gitHash = execSync("git rev-parse HEAD", { encoding: "utf-8" }).trim();
27-
gitShortHash = execSync("git rev-parse --short HEAD", {
28-
encoding: "utf-8",
29-
}).trim();
30-
} catch (error) {
31-
// Git not available or not in a git repository
32-
console.warn("Git hash not available:", error);
33-
}
10+
// Get version info from runtime config (set in nuxt.config.ts)
11+
const appVersion = config.public.appVersion;
12+
const gitHash = config.public.gitHash;
13+
const gitShortHash = config.public.gitShortHash;
3414

3515
return {
3616
version: appVersion,
3717
gitHash,
3818
gitShortHash,
39-
fullVersion: `${appVersion}+${gitShortHash}`,
19+
fullVersion: gitShortHash
20+
? `${appVersion}+${gitShortHash}`
21+
: appVersion,
4022
};
4123
});

0 commit comments

Comments
 (0)