Skip to content

Commit f7e0df1

Browse files
ci(release): stage version.json into backend build context (drift fix)
The backend Docker image is built with `context: ./backend`, so the repo-root `version.json` is outside the build context and never reaches the container. Backend `main.py` falls back to a compile- time `_version_info` constant when `/app/version.json` is missing. In practice this produced a real production drift: a successful redeploy of the v1.5.2 tree silently reported `"v1.5.0"` in `/api/version` for a window of releases because the constant in main.py had not been bumped in lockstep with `version.json`, and the canonical file was never available to read inside the container. Fix is workflow-only: * New "stage version.json into backend build context" step (between `read product version` and `set up qemu`) that runs `cp version.json backend/version.json` so the next `docker buildx build` includes it. * `.gitignore` entry for `backend/version.json` keeps `git status` clean for developers (the canonical file remains at repo root; `backend/version.json` is a transient CI artefact). Backend reading logic is unchanged: the loop in `main.py` first tries `/app/version.json`, then falls back to the constant. Post-fix, the first path WILL find the file and produce the correct response; the constant becomes a pure defensive fallback (rather than the production hot path it accidentally became). No code or test changes needed: existing tests assert against the `_version_info` dict regardless of whether it was populated from JSON or the fallback constant.
1 parent d720852 commit f7e0df1

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ jobs:
2626
fi
2727
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
2828
29+
# The backend image is built with `context: ./backend`, so the
30+
# repo-root version.json is OUTSIDE the build context and never
31+
# reaches the container. Backend `main.py` falls back to a
32+
# compile-time constant when /app/version.json is missing, which
33+
# caused a real production drift: a redeploy of the v1.5.2 tree
34+
# silently still reported "v1.5.0" in `/api/version` because the
35+
# constant in main.py had been bumped but the file was not
36+
# available to read. Stage version.json into the backend
37+
# context here so the canonical file IS shipped and the
38+
# constant only serves as a defensive fallback. The staged file
39+
# is gitignored to keep `git status` clean for developers.
40+
- name: stage version.json into backend build context
41+
run: cp version.json backend/version.json
42+
2943
- name: set up qemu
3044
uses: docker/setup-qemu-action@v3
3145

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ venv.bak/
4242
# Docker
4343
.dockerignore
4444

45+
# Build-time staged version.json (CI `cp version.json backend/`).
46+
# The canonical file lives at repo root; this path is a transient
47+
# copy for the backend Docker build context.
48+
backend/version.json
49+
4550
# IDE
4651
.vscode/
4752
.idea/

0 commit comments

Comments
 (0)