mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-10-16 07:25:44 -04:00
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:
5 files changed
+24
-13
No files matched your search
@@ -39,6 +39,10 @@ jobs:
|
|||||||
username: ${{ vars.DOCKERHUB_USERNAME }}
|
username: ${{ vars.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Get app version
|
||||||
|
id: version
|
||||||
|
run: echo "version=$(jq -r .version package.json)" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
- name: Docker metadata
|
- name: Docker metadata
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
@@ -62,6 +66,7 @@ jobs:
|
|||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
build-args: |
|
build-args: |
|
||||||
|
APP_VERSION=${{ steps.version.outputs.version }}
|
||||||
GIT_COMMIT_SHA=${{ github.sha }}
|
GIT_COMMIT_SHA=${{ github.sha }}
|
||||||
cache-from: type=gha
|
cache-from: type=gha
|
||||||
cache-to: type=gha,mode=max
|
cache-to: type=gha,mode=max
|
||||||
+6
-1
@@ -16,8 +16,10 @@ WORKDIR /app
|
|||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
ARG APP_VERSION
|
||||||
ARG GIT_COMMIT_SHA
|
ARG GIT_COMMIT_SHA
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
ENV APP_VERSION=${APP_VERSION}
|
||||||
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
|
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
|
||||||
@@ -27,17 +29,20 @@ RUN bun run build
|
|||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG APP_VERSION
|
||||||
|
ARG GIT_COMMIT_SHA
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV HOSTNAME=0.0.0.0
|
ENV HOSTNAME=0.0.0.0
|
||||||
ENV PORT=3000
|
ENV PORT=3000
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
ENV DATA_DIR=/data
|
ENV DATA_DIR=/data
|
||||||
|
ENV APP_VERSION=${APP_VERSION}
|
||||||
|
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
|
||||||
|
|
||||||
RUN mkdir -p /data \
|
RUN mkdir -p /data \
|
||||||
&& chown bun:bun /data
|
&& chown bun:bun /data
|
||||||
|
|
||||||
COPY --from=builder --chown=bun:bun /app/public ./public
|
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/standalone ./
|
||||||
COPY --from=builder --chown=bun:bun /app/.next/static ./.next/static
|
COPY --from=builder --chown=bun:bun /app/.next/static ./.next/static
|
||||||
COPY --from=builder --chown=bun:bun /app/drizzle ./drizzle
|
COPY --from=builder --chown=bun:bun /app/drizzle ./drizzle
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
getCachedUpdateCheck,
|
getCachedUpdateCheck,
|
||||||
isUpdateCheckEnabled,
|
isUpdateCheckEnabled,
|
||||||
} from "@/lib/services/update-check";
|
} from "@/lib/services/update-check";
|
||||||
import { APP_VERSION, GIT_COMMIT } from "@/lib/version";
|
|
||||||
import { AccountSection } from "./_components/account-section";
|
import { AccountSection } from "./_components/account-section";
|
||||||
import { BackupRestoreSection } from "./_components/backup-restore-section";
|
import { BackupRestoreSection } from "./_components/backup-restore-section";
|
||||||
import { BackupScheduleSection } from "./_components/backup-schedule-section";
|
import { BackupScheduleSection } from "./_components/backup-schedule-section";
|
||||||
@@ -98,7 +97,9 @@ export default async function SettingsPage() {
|
|||||||
const updateCheck =
|
const updateCheck =
|
||||||
isAdmin && updateCheckEnabled ? getCachedUpdateCheck() : null;
|
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 (
|
return (
|
||||||
<SettingsShell
|
<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">
|
<footer className="border-t border-border/50 pt-6 pb-2 text-center text-xs text-muted-foreground">
|
||||||
<p>
|
<p>
|
||||||
<a
|
<a
|
||||||
href={repoUrl}
|
href={`https://github.com/${GITHUB_REPO}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="font-medium text-primary/80 hover:text-primary transition-colors"
|
className="font-medium text-primary/80 hover:text-primary transition-colors"
|
||||||
@@ -114,17 +115,17 @@ export default async function SettingsPage() {
|
|||||||
Sofa
|
Sofa
|
||||||
</a>{" "}
|
</a>{" "}
|
||||||
v{APP_VERSION}
|
v{APP_VERSION}
|
||||||
{GIT_COMMIT && (
|
{GIT_COMMIT_SHA && (
|
||||||
<>
|
<>
|
||||||
{" "}
|
{" "}
|
||||||
(
|
(
|
||||||
<a
|
<a
|
||||||
href={`${repoUrl}/commit/${GIT_COMMIT}`}
|
href={`https://github.com/${GITHUB_REPO}/commit/${GIT_COMMIT_SHA}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="font-mono hover:text-primary transition-colors"
|
className="font-mono hover:text-primary transition-colors"
|
||||||
>
|
>
|
||||||
{GIT_COMMIT}
|
{GIT_COMMIT_SHA}
|
||||||
</a>
|
</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 className="relative inline-flex h-1.5 w-1.5 rounded-full bg-primary" />
|
||||||
</span>
|
</span>
|
||||||
<a
|
<a
|
||||||
href={updateCheck.releaseUrl ?? `${repoUrl}/releases`}
|
href={
|
||||||
|
updateCheck.releaseUrl ??
|
||||||
|
`https://github.com/${GITHUB_REPO}/releases`
|
||||||
|
}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="hover:underline"
|
className="hover:underline"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { createLogger } from "@/lib/logger";
|
import { createLogger } from "@/lib/logger";
|
||||||
import { getSetting, setSetting } from "@/lib/services/settings";
|
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");
|
const log = createLogger("update-check");
|
||||||
|
|
||||||
|
|||||||
@@ -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) || "";
|
|
||||||
Reference in new issue
Block a user