Skip to content

Resolve footer git commit at runtime (no more 'main @ unknown')#35

Merged
mre merged 1 commit into
mainfrom
fix/footer-git-hash
Jun 21, 2026
Merged

Resolve footer git commit at runtime (no more 'main @ unknown')#35
mre merged 1 commit into
mainfrom
fix/footer-git-hash

Conversation

@mre

@mre mre commented Jun 21, 2026

Copy link
Copy Markdown
Member

Problem

The site footer shows Version v0.1.0 · main @ unknown. The branch resolves (main), but the commit hash is unknown.

Why

GIT_BRANCH/GIT_HASH were baked in at compile time by build.rs. In the production image that fails for the commit:

  • The Docker build context excludes .git (.dockerignore), so build.rs can't shell out to git.
  • Since Coolify v450, SOURCE_COMMIT is no longer injected as a build arg by default (it busted the Docker layer cache). So the build-time SOURCE_COMMIT is empty and the hash falls through to unknown.
  • The branch still shows main only because the Dockerfile defaults ARG GIT_BRANCH=main.

Coolify does still expose SOURCE_COMMIT (and COOLIFY_BRANCH) to the running container as runtime env vars.

Fix

Resolve the footer branch/commit at runtime, falling back to the build-time value, then unknown:

  • server.rs: GIT_BRANCH/GIT_HASH become LazyLock<String> resolved once at startup.
    • branch: GIT_BRANCH env → COOLIFY_BRANCH env → build-time → unknown
    • commit: GIT_HASH env → SOURCE_COMMIT env (first 7 chars) → build-time → unknown
    • Empty and literal unknown values are treated as absent so the chain keeps looking.
  • base.html: footer calls crate::git_branch() / crate::git_hash() instead of the old consts.
  • Dockerfile: drop the now-unused SOURCE_COMMIT build arg and document the runtime-first behavior.

Local dev is unchanged: with .git present, build.rs still bakes in the real branch/commit, which the runtime fallback uses when no env vars are set.

Validation

  • cargo test --locked --lib --bins — 9 passed, including a new usable_filters_out_uninformative_git_values test for the normalizer (empty / whitespace / unknown → treated as absent).
  • cargo clippy --locked --lib --bins -- -D warnings — clean (Askama compiles the template, so the new function calls are checked).
  • cargo fmt --all --check — clean.

Note

I went with runtime resolution rather than re-enabling Coolify's build-arg injection because that toggle lives in the Coolify UI (not the repo) and re-enabling it reintroduces the layer-cache busting that v450 fixed. Reading the runtime env keeps the image cacheable and works regardless of that setting.

The footer showed 'main @ unknown' in production. The Docker build excludes
.git, and since Coolify v450 SOURCE_COMMIT is no longer injected as a build
arg by default (it busts the layer cache), so build.rs baked in 'unknown'.

Coolify still exposes SOURCE_COMMIT and COOLIFY_BRANCH to the running
container, so resolve the footer branch/commit from the runtime environment
first, falling back to the build-time value, then 'unknown'. Local dev still
shows the real git info via build.rs. Drops the now-unused SOURCE_COMMIT
build arg from the Dockerfile and adds a unit test for the value normalizer.
@mre mre merged commit 77e66b9 into main Jun 21, 2026
4 checks passed
@mre mre deleted the fix/footer-git-hash branch June 21, 2026 22:53
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.

1 participant