diff --git a/Dockerfile b/Dockerfile index 1c6a9eb..8010409 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG APP_VERSION ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - APP_VERSION=${APP_VERSION} + BERT_BUILD_VERSION=${APP_VERSION} WORKDIR /app COPY requirements.txt . diff --git a/README.md b/README.md index a568629..faaa6ed 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,10 @@ ADMIN_PASSWORD=replace-with-a-long-unique-password APP_SECRET_KEY=replace-with-the-generated-secret ``` +Do not set `APP_VERSION` in `.env`. Release versions are embedded into the +container image at build time; a runtime override can otherwise make the UI +report a stale version. + Start Bert: ```bash diff --git a/app/version.py b/app/version.py index 2779f2c..33aad4c 100644 --- a/app/version.py +++ b/app/version.py @@ -2,4 +2,6 @@ DEFAULT_VERSION = "17.2.2" -VERSION = (os.getenv("APP_VERSION") or DEFAULT_VERSION).removeprefix("v") +VERSION = ( + os.getenv("BERT_BUILD_VERSION") or os.getenv("APP_VERSION") or DEFAULT_VERSION +).removeprefix("v") diff --git a/tests/test_release_container.py b/tests/test_release_container.py index 45d1b37..b1fbd48 100644 --- a/tests/test_release_container.py +++ b/tests/test_release_container.py @@ -26,7 +26,7 @@ def test_release_workflow_uses_release_tag_as_application_version(): def test_container_exposes_release_version_to_application(): dockerfile = Path("Dockerfile").read_text(encoding="utf-8") assert "ARG APP_VERSION" in dockerfile - assert "APP_VERSION=${APP_VERSION}" in dockerfile + assert "BERT_BUILD_VERSION=${APP_VERSION}" in dockerfile def test_application_version_uses_release_build_version(monkeypatch): @@ -36,9 +36,18 @@ def test_application_version_uses_release_build_version(monkeypatch): assert runpy.run_path("app/version.py")["VERSION"] == "23.4.5" +def test_baked_release_version_wins_over_stale_runtime_override(monkeypatch): + import runpy + + monkeypatch.setenv("BERT_BUILD_VERSION", "v24.0.0") + monkeypatch.setenv("APP_VERSION", "v19.1.3") + assert runpy.run_path("app/version.py")["VERSION"] == "24.0.0" + + def test_application_version_keeps_source_fallback(monkeypatch): import runpy + monkeypatch.delenv("BERT_BUILD_VERSION", raising=False) monkeypatch.delenv("APP_VERSION", raising=False) assert runpy.run_path("app/version.py")["VERSION"] == "17.2.2"