Skip to content

fix(backend): resolve app version in the shipped Docker image#283

Merged
bihius merged 1 commit into
mainfrom
fix/backend-version-metadata-in-image
Jul 22, 2026
Merged

fix(backend): resolve app version in the shipped Docker image#283
bihius merged 1 commit into
mainfrom
fix/backend-version-metadata-in-image

Conversation

@bihius

@bihius bihius commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Found while smoke-testing the v0.1.0-beta.2 release kit end-to-end on the test server: /health reported "version": "0.0.0+unknown" instead of 0.1.0b2.

Root cause

src/backend/Dockerfile builds dependencies with uv sync --frozen --no-dev --no-install-project, then copies the app/ source on top without ever installing the project itself. No dist-info is generated in the final image, so importlib.metadata.version("guard-proxy-backend") (added in #280 to fix version drift) silently falls back to "0.0.0+unknown" in every shipped container — even though the same lookup works correctly in local dev venvs, where the project is installed editable via uv sync --extra dev. Unit/integration tests all run against the dev venv, so none of them caught this; it only surfaced when actually running the built image.

Fix

  • app/main.py: when package metadata lookup raises PackageNotFoundError, fall back to parsing pyproject.toml directly via tomllib instead of returning a hardcoded placeholder.
  • Dockerfile: copy pyproject.toml into the final image so that fallback has something to read.
  • Added tests/unit/test_app_version.py covering both paths (installed-metadata present, and the Docker-image case where it is absent).

Verification

  • ruff check app/, mypy app/, full backend test suite (566 tests) — all pass.
  • Built the actual Docker image locally and confirmed inside the running container: app.main.APP_VERSION now resolves to 0.1.0b2 (previously 0.0.0+unknown).
  • This is the same image shape that publish.yml builds and ships — the fix is verified against the real artifact, not just source.

The production Dockerfile installs only dependencies (`uv sync --frozen
--no-dev --no-install-project`) and copies app source on top without ever
installing the project itself, so no dist-info exists in the final image.
importlib.metadata.version("guard-proxy-backend") silently falls back to
"0.0.0+unknown" there, even though the same lookup works fine in local dev
venvs where the project is installed editable.

Fall back to parsing pyproject.toml directly via tomllib when package
metadata isn't found, and ship pyproject.toml in the final image so that
fallback has something to read. Verified inside an actual build of the
image: /health now reports the real version instead of the fallback.
Copilot AI review requested due to automatic review settings July 21, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bihius
bihius merged commit cc365e4 into main Jul 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants