mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(docker): bake CI tag into image, prefer it at runtime
The v1.4.42 docker-publish workflow shipped a stale package.json version baked into the bundle because BuildKit reused the pnpm build layer across the release tag bump -- the COPY . . layer key was content-stable relative to the prior build, the layer was warm, and the runtime /api/version read the cached package.json content instead of the new tag. Thread github.ref_name through as a NEXT_PUBLIC_APP_VERSION build-arg from docker-publish.yml. The Dockerfile picks it up as an ARG/ENV in both the builder and runner stages and bakes it into the build context. src/app/api/version/route.ts now reads the env var first and falls through to package.json only when unset (local pnpm dev). The build-arg becomes part of the layer cache key, so every release tag invalidates every downstream layer and the runtime version can never drift from the tag the workflow ran on.
This commit is contained in:
1 parent
f9cf396f2e
commit
938d840670
4 files changed
+58
-1
No files matched your search
@@ -14,6 +14,7 @@ import { GET } from "../route";
|
||||
beforeEach(() => {
|
||||
delete process.env.NEXT_PUBLIC_APP_BUILD_SHA;
|
||||
delete process.env.NEXT_PUBLIC_APP_BUILT_AT;
|
||||
delete process.env.NEXT_PUBLIC_APP_VERSION;
|
||||
offlineGeoReadyMock.mockReturnValue(false);
|
||||
});
|
||||
|
||||
@@ -57,6 +58,26 @@ describe("GET /api/version", () => {
|
||||
expect(body.data.builtAt).toBe("2026-05-08T12:00:00.000Z");
|
||||
});
|
||||
|
||||
it("prefers NEXT_PUBLIC_APP_VERSION over package.json when set (v1.4.43 B11)", async () => {
|
||||
// Build-arg-injected version wins over the bundled package.json so a
|
||||
// BuildKit layer-cache hit on `pnpm build` cannot ship a stale version
|
||||
// string. The CI tag ref (`v1.4.43`, etc.) is forwarded straight to
|
||||
// the env so the runtime answer can never drift from the release tag.
|
||||
process.env.NEXT_PUBLIC_APP_VERSION = "v1.4.43";
|
||||
const response = await (GET as unknown as () => Promise<Response>)();
|
||||
const body = (await response.json()) as VersionEnvelope;
|
||||
expect(body.data.version).toBe("v1.4.43");
|
||||
});
|
||||
|
||||
it("falls through to package.json when NEXT_PUBLIC_APP_VERSION is blank", async () => {
|
||||
// A whitespace-only env value must NOT shadow the package.json read --
|
||||
// the trim()+OR pattern ensures the fallback still kicks in.
|
||||
process.env.NEXT_PUBLIC_APP_VERSION = " ";
|
||||
const response = await (GET as unknown as () => Promise<Response>)();
|
||||
const body = (await response.json()) as VersionEnvelope;
|
||||
expect(body.data.version).toMatch(/^\d+\.\d+\.\d+(\.\d+)?(-[a-z0-9.-]+)?$/i);
|
||||
});
|
||||
|
||||
it("reports offlineGeoEnabled=false when the GeoLite2 databases are absent", async () => {
|
||||
offlineGeoReadyMock.mockReturnValue(false);
|
||||
const response = await (GET as unknown as () => Promise<Response>)();
|
||||
|
||||
@@ -37,7 +37,15 @@ export const dynamic = "force-dynamic";
|
||||
* first use.
|
||||
*/
|
||||
export const GET = apiHandler(async () => {
|
||||
const version = packageJson.version;
|
||||
// v1.4.43 B11 — prefer the build-arg-injected env var so the runtime
|
||||
// version cannot drift from the CI release tag. The Dockerfile takes
|
||||
// `NEXT_PUBLIC_APP_VERSION` as a build arg from the docker-publish
|
||||
// workflow (`build-args: NEXT_PUBLIC_APP_VERSION=${{ github.ref_name
|
||||
// }}`); when present it wins over the package.json fallback so a
|
||||
// BuildKit-layer cache hit on `pnpm build` can never re-ship the
|
||||
// prior release's version string. Local `pnpm dev` (env unset) falls
|
||||
// through to package.json as before.
|
||||
const version = process.env.NEXT_PUBLIC_APP_VERSION?.trim() || packageJson.version;
|
||||
const buildSha = process.env.NEXT_PUBLIC_APP_BUILD_SHA?.trim() || null;
|
||||
const builtAt = process.env.NEXT_PUBLIC_APP_BUILT_AT?.trim() || null;
|
||||
const offlineGeoEnabled = offlineGeoReady();
|
||||
|
||||
Reference in new issue
Block a user