fix(backend): resolve app version in the shipped Docker image#283
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while smoke-testing the
v0.1.0-beta.2release kit end-to-end on the test server:/healthreported"version": "0.0.0+unknown"instead of0.1.0b2.Root cause
src/backend/Dockerfilebuilds dependencies withuv sync --frozen --no-dev --no-install-project, then copies theapp/source on top without ever installing the project itself. Nodist-infois generated in the final image, soimportlib.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 viauv 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 raisesPackageNotFoundError, fall back to parsingpyproject.tomldirectly viatomllibinstead of returning a hardcoded placeholder.Dockerfile: copypyproject.tomlinto the final image so that fallback has something to read.tests/unit/test_app_version.pycovering 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.app.main.APP_VERSIONnow resolves to0.1.0b2(previously0.0.0+unknown).publish.ymlbuilds and ships — the fix is verified against the real artifact, not just source.