Skip to content

fix(version): /api/version shows 'unknown' on prod/dev deploys — derive version from git #993

Closed

Description

@dolho

Summary

GET /api/version shows version: "unknown" on the dev instance (and any prod-compose deploy). It's two independent delivery bugs in the build/CI path, plus an opportunity to make the version string self-describing from git.

Root causes

1. version field — VERSION file never reaches the prod image.

  • docker/backend/Dockerfile never COPYs VERSION.
  • docker-compose.yml (dev) bind-mounts ./VERSION:/app/VERSION:ro, which masks the bug locally.
  • docker-compose.prod.yml (used by the dev instance) has no such mount.
  • Fallback Path(__file__).parent.parent.parent / "VERSION" resolves to /VERSION (since __file__ = /app/main.py), which doesn't exist → version = "unknown".

2. Git provenance fields (git_commit, git_branch, build_date) — build args stripped by sudo.

  • deploy-dev.yml passes them as sudo GIT_COMMIT=… docker compose build.
  • Under default Ubuntu sudoers (env_reset on, setenv off), command-line VAR=val assignments don't reliably reach the command's environment, so docker compose interpolation falls back to ${VAR:-unknown}.
  • scripts/deploy/start.sh works because it runs docker compose without sudo.

Decision

Make the version string dynamic from git (Option B): curated semver from the VERSION file + git short-sha suffix, e.g. 0.9.0+g4c640b6e (.dirty when the tree is dirty). git_commit_short continues to carry the bare commit separately in the payload.

Pure git describe (Option A) was rejected because the last platform tag (v0.5.0) lags the curated file (0.9.0), and cli-v* tags pollute describe — it would regress the displayed version.

Changes

  • docker/backend/Dockerfile — add ARG VERSION=unknown + ENV VERSION=${VERSION} in the existing provenance block.
  • docker-compose.yml + docker-compose.prod.yml — add VERSION: ${VERSION:-unknown} to backend.build.args.
  • src/backend/main.py _build_version_payload — prefer os.getenv("VERSION"), fall back to the VERSION file, then "unknown".
  • scripts/deploy/start.sh — compute VERSION="$(cat VERSION)+g$(git rev-parse --short=8 HEAD)[.dirty]" and export it.
  • .github/workflows/deploy-dev.yml — compute the same VERSION, and switch the build invocation to sudo env VAR=val … docker compose build so VERSION and the existing git fields actually reach the build.

Acceptance criteria

  • GET /api/version on a prod-compose deploy returns a real version (e.g. 0.9.0+g<sha>), not unknown.
  • git_commit / git_branch / build_date populated on the dev deploy (no longer unknown).
  • Dev and prod compose report the same version for the same commit.
  • No reliance on the /app/VERSION bind-mount for correctness.

Out of scope

Activity

  1. self-assigned this
    on Jun 1, 2026
  2. added
    status-in-progress
    on Jun 1, 2026
  3. added
    status-in-dev
    theme-infrastructure
    and removed
    status-in-progress
    on Jun 3, 2026
  4. removed
    status-in-dev
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

theme-infrastructuretype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions