feat: expose running CalVer version via API (#126) #127

Merged
cal merged 1 commits from issue/126-feat-expose-running-calver-version-via-api into main 2026-04-10 15:54:14 +00:00
Collaborator

Closes #126

Summary

Implements all three approaches from the issue to make the running CalVer version discoverable without cross-referencing timestamps:

1. Build arg → env var (Dockerfile + CI)

  • Dockerfile: ARG BUILD_VERSION=dev baked into ENV APP_VERSION=$BUILD_VERSION — readable at runtime via os.environ.get("APP_VERSION")
  • CI: build-args: BUILD_VERSION=${{ steps.version.outputs.version }} passed to docker/build-push-action — CI already extracts the version from the git tag, now it flows through to the image

2. OCI image label (Dockerfile)

  • LABEL org.opencontainers.image.version=$BUILD_VERSION — visible via docker inspect without running the container

3. /health endpoint (app/main.py)

  • GET /health returns {"status": "ok", "version": "2026.4.1"} — single API call to get the running version
  • Also updates Dockerfile HEALTHCHECK from /api/v3/current (SQL query) to /health (no SQL, lightweight)
  • Local/dev builds default to "dev" when APP_VERSION is not set

Files Changed

  • Dockerfile — build arg, OCI label, env var, HEALTHCHECK URL
  • .gitea/workflows/docker-build.yml — passes BUILD_VERSION build-arg
  • app/main.py — adds GET /health endpoint

Other observations

  • main.py has a duplicate db_connection_middleware definition (lines 74 and 88) — the second shadows the first. Pre-existing, out of scope.
  • main.py has unused imports (datetime, Depends). Pre-existing, out of scope.
Closes #126 ## Summary Implements all three approaches from the issue to make the running CalVer version discoverable without cross-referencing timestamps: ### 1. Build arg → env var (Dockerfile + CI) - `Dockerfile`: `ARG BUILD_VERSION=dev` baked into `ENV APP_VERSION=$BUILD_VERSION` — readable at runtime via `os.environ.get("APP_VERSION")` - CI: `build-args: BUILD_VERSION=${{ steps.version.outputs.version }}` passed to `docker/build-push-action` — CI already extracts the version from the git tag, now it flows through to the image ### 2. OCI image label (Dockerfile) - `LABEL org.opencontainers.image.version=$BUILD_VERSION` — visible via `docker inspect` without running the container ### 3. `/health` endpoint (app/main.py) - `GET /health` returns `{"status": "ok", "version": "2026.4.1"}` — single API call to get the running version - Also updates `Dockerfile` HEALTHCHECK from `/api/v3/current` (SQL query) to `/health` (no SQL, lightweight) - Local/dev builds default to `"dev"` when `APP_VERSION` is not set ## Files Changed - `Dockerfile` — build arg, OCI label, env var, HEALTHCHECK URL - `.gitea/workflows/docker-build.yml` — passes `BUILD_VERSION` build-arg - `app/main.py` — adds `GET /health` endpoint ## Other observations - `main.py` has a duplicate `db_connection_middleware` definition (lines 74 and 88) — the second shadows the first. Pre-existing, out of scope. - `main.py` has unused imports (`datetime`, `Depends`). Pre-existing, out of scope.
Claude added 1 commit 2026-04-10 02:33:10 +00:00
Closes #126

- Dockerfile: ARG BUILD_VERSION=dev baked into ENV APP_VERSION + OCI label
- CI: passes BUILD_VERSION build-arg from git tag to docker build
- main.py: adds GET /health returning {"status": "ok", "version": "..."}
- Dockerfile: updates HEALTHCHECK to use /health (no SQL, lightweight)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude added the
ai-reviewing
label 2026-04-10 02:45:50 +00:00
Claude reviewed 2026-04-10 02:47:16 +00:00
Claude left a comment
Author
Collaborator

AI Code Review

Files Reviewed

  • Dockerfile (modified)
  • .gitea/workflows/docker-build.yml (modified)
  • app/main.py (modified)

Findings

Correctness

No issues found.

  • ARG BUILD_VERSION=devENV APP_VERSION=$BUILD_VERSION is correct Dockerfile syntax. ARG value is in scope for both LABEL and ENV instructions in the same stage.
  • LABEL org.opencontainers.image.version=$BUILD_VERSION bakes the value at image build time — correct.
  • HEALTHCHECK update from /api/v3/current to /health is consistent with the new endpoint.
  • CI build-args: BUILD_VERSION=${{ steps.version.outputs.version }} correctly passes the CalVer tag (or dev) through to the image. For dev tag pushes, version output is dev, which matches the Dockerfile default — harmless redundancy.
  • os.environ.get("APP_VERSION", "dev") in main.py is safe. os is already imported at line 4.
  • /health endpoint is defined after all router includes (line 139+), avoiding any routing conflicts with the existing prefix-based API routes.

Security

No issues found. Version disclosure via /health is intentional and consistent with the feature's purpose. No user input flows into the endpoint.

Style & Conventions

  • No tests added for the new /health endpoint. The endpoint is trivial (env var read + dict return) so this is acceptable, but a basic integration test confirming the response shape would be consistent with the existing test suite.

Suggestions

  • Potential merge conflict with PR #125: PR #125 (currently open) also adds GET /health returning {"status": "ok"} and updates the Dockerfile HEALTHCHECK from /api/v3/current to /health. If #125 merges before #127, this PR will have a conflict on both files. Consider coordinating merge order or superseding #125 with this PR (since #127 is a strict superset of #125's /health work).
  • main.py line 87: duplicate db_connection_middleware registration (pre-existing, out of scope per PR body — noted for awareness).

Verdict: COMMENT

Implementation is correct and complete. All three approaches (build-arg env var, OCI label, /health endpoint) are properly wired end-to-end. Only non-blocking observation is the potential merge conflict with PR #125. Approved — Gitea blocks self-review.


Automated review by Claude PR Reviewer

## AI Code Review ### Files Reviewed - `Dockerfile` (modified) - `.gitea/workflows/docker-build.yml` (modified) - `app/main.py` (modified) ### Findings #### Correctness No issues found. - `ARG BUILD_VERSION=dev` → `ENV APP_VERSION=$BUILD_VERSION` is correct Dockerfile syntax. `ARG` value is in scope for both `LABEL` and `ENV` instructions in the same stage. - `LABEL org.opencontainers.image.version=$BUILD_VERSION` bakes the value at image build time — correct. - HEALTHCHECK update from `/api/v3/current` to `/health` is consistent with the new endpoint. - CI `build-args: BUILD_VERSION=${{ steps.version.outputs.version }}` correctly passes the CalVer tag (or `dev`) through to the image. For `dev` tag pushes, `version` output is `dev`, which matches the Dockerfile default — harmless redundancy. - `os.environ.get("APP_VERSION", "dev")` in `main.py` is safe. `os` is already imported at line 4. - `/health` endpoint is defined after all router includes (line 139+), avoiding any routing conflicts with the existing prefix-based API routes. #### Security No issues found. Version disclosure via `/health` is intentional and consistent with the feature's purpose. No user input flows into the endpoint. #### Style & Conventions - No tests added for the new `/health` endpoint. The endpoint is trivial (env var read + dict return) so this is acceptable, but a basic integration test confirming the response shape would be consistent with the existing test suite. #### Suggestions - **Potential merge conflict with PR #125**: PR #125 (currently open) also adds `GET /health` returning `{"status": "ok"}` and updates the Dockerfile HEALTHCHECK from `/api/v3/current` to `/health`. If #125 merges before #127, this PR will have a conflict on both files. Consider coordinating merge order or superseding #125 with this PR (since #127 is a strict superset of #125's `/health` work). - `main.py` line 87: duplicate `db_connection_middleware` registration (pre-existing, out of scope per PR body — noted for awareness). ### Verdict: COMMENT Implementation is correct and complete. All three approaches (build-arg env var, OCI label, `/health` endpoint) are properly wired end-to-end. Only non-blocking observation is the potential merge conflict with PR #125. Approved — Gitea blocks self-review. --- *Automated review by Claude PR Reviewer*
Claude added
ai-reviewed
and removed
ai-reviewing
labels 2026-04-10 02:47:32 +00:00
cal force-pushed issue/126-feat-expose-running-calver-version-via-api from 9249cb06f0 to 4acf7b2afa 2026-04-10 15:54:00 +00:00 Compare
cal merged commit 6972cbe610 into main 2026-04-10 15:54:14 +00:00
cal deleted branch issue/126-feat-expose-running-calver-version-via-api 2026-04-10 15:54:15 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cal/major-domo-database#127
No description provided.