Replace lib/version.ts with APP_VERSION build arg injected via Docker

Remove the static package.json import in lib/version.ts and instead
pass APP_VERSION as a Docker build arg extracted from package.json by
the CI workflow. Both the builder and runner stages receive APP_VERSION
and GIT_COMMIT_SHA as environment variables, making runtime version
info available via process.env without bundling package.json into the
standalone output.
This commit is contained in:
2026-03-06 13:00:41 -05:00
parent 57ce0fd85d
commit fb24b25d34
5 changed files with 24 additions and 13 deletions
+5
View File
@@ -39,6 +39,10 @@ jobs:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get app version
id: version
run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
@@ -62,6 +66,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
APP_VERSION=${{ steps.version.outputs.version }}
GIT_COMMIT_SHA=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
+6 -1
View File
@@ -16,8 +16,10 @@ WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG APP_VERSION
ARG GIT_COMMIT_SHA
ENV NODE_ENV=production
ENV APP_VERSION=${APP_VERSION}
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
ENV NEXT_TELEMETRY_DISABLED=1
@@ -27,17 +29,20 @@ RUN bun run build
FROM base AS runner
WORKDIR /app
ARG APP_VERSION
ARG GIT_COMMIT_SHA
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
ENV NEXT_TELEMETRY_DISABLED=1
ENV DATA_DIR=/data
ENV APP_VERSION=${APP_VERSION}
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
RUN mkdir -p /data \
&& chown bun:bun /data
COPY --from=builder --chown=bun:bun /app/public ./public
COPY --from=builder --chown=bun:bun /app/package.json ./package.json
COPY --from=builder --chown=bun:bun /app/.next/standalone ./
COPY --from=builder --chown=bun:bun /app/.next/static ./.next/static
COPY --from=builder --chown=bun:bun /app/drizzle ./drizzle
+11 -7
View File
@@ -16,7 +16,6 @@ import {
getCachedUpdateCheck,
isUpdateCheckEnabled,
} from "@/lib/services/update-check";
import { APP_VERSION, GIT_COMMIT } from "@/lib/version";
import { AccountSection } from "./_components/account-section";
import { BackupRestoreSection } from "./_components/backup-restore-section";
import { BackupScheduleSection } from "./_components/backup-schedule-section";
@@ -98,7 +97,9 @@ export default async function SettingsPage() {
const updateCheck =
isAdmin && updateCheckEnabled ? getCachedUpdateCheck() : null;
const repoUrl = "https://github.com/jakejarvis/sofa";
const GITHUB_REPO = "jakejarvis/sofa";
const APP_VERSION = process.env.APP_VERSION || "0.0.0";
const GIT_COMMIT_SHA = process.env.GIT_COMMIT_SHA?.slice(0, 7) || "";
return (
<SettingsShell
@@ -106,7 +107,7 @@ export default async function SettingsPage() {
<footer className="border-t border-border/50 pt-6 pb-2 text-center text-xs text-muted-foreground">
<p>
<a
href={repoUrl}
href={`https://github.com/${GITHUB_REPO}`}
target="_blank"
rel="noopener noreferrer"
className="font-medium text-primary/80 hover:text-primary transition-colors"
@@ -114,17 +115,17 @@ export default async function SettingsPage() {
Sofa
</a>{" "}
v{APP_VERSION}
{GIT_COMMIT && (
{GIT_COMMIT_SHA && (
<>
{" "}
(
<a
href={`${repoUrl}/commit/${GIT_COMMIT}`}
href={`https://github.com/${GITHUB_REPO}/commit/${GIT_COMMIT_SHA}`}
target="_blank"
rel="noopener noreferrer"
className="font-mono hover:text-primary transition-colors"
>
{GIT_COMMIT}
{GIT_COMMIT_SHA}
</a>
)
</>
@@ -136,7 +137,10 @@ export default async function SettingsPage() {
<span className="relative inline-flex h-1.5 w-1.5 rounded-full bg-primary" />
</span>
<a
href={updateCheck.releaseUrl ?? `${repoUrl}/releases`}
href={
updateCheck.releaseUrl ??
`https://github.com/${GITHUB_REPO}/releases`
}
target="_blank"
rel="noopener noreferrer"
className="hover:underline"
+2 -1
View File
@@ -1,6 +1,7 @@
import { createLogger } from "@/lib/logger";
import { getSetting, setSetting } from "@/lib/services/settings";
import { APP_VERSION } from "@/lib/version";
const APP_VERSION = process.env.APP_VERSION || "0.0.0";
const log = createLogger("update-check");
-4
View File
@@ -1,4 +0,0 @@
import packageJson from "../package.json" with { type: "json" };
export const APP_VERSION = packageJson.version;
export const GIT_COMMIT = process.env.GIT_COMMIT_SHA?.slice(0, 7) || "";