Resolve footer git commit at runtime (no more 'main @ unknown')#35
Merged
Conversation
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.
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.
Problem
The site footer shows
Version v0.1.0 · main @ unknown. The branch resolves (main), but the commit hash isunknown.Why
GIT_BRANCH/GIT_HASHwere baked in at compile time bybuild.rs. In the production image that fails for the commit:.git(.dockerignore), sobuild.rscan't shell out to git.SOURCE_COMMITis no longer injected as a build arg by default (it busted the Docker layer cache). So the build-timeSOURCE_COMMITis empty and the hash falls through tounknown.mainonly because the Dockerfile defaultsARG GIT_BRANCH=main.Coolify does still expose
SOURCE_COMMIT(andCOOLIFY_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_HASHbecomeLazyLock<String>resolved once at startup.GIT_BRANCHenv →COOLIFY_BRANCHenv → build-time →unknownGIT_HASHenv →SOURCE_COMMITenv (first 7 chars) → build-time →unknownunknownvalues are treated as absent so the chain keeps looking.base.html: footer callscrate::git_branch()/crate::git_hash()instead of the old consts.Dockerfile: drop the now-unusedSOURCE_COMMITbuild arg and document the runtime-first behavior.Local dev is unchanged: with
.gitpresent,build.rsstill 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 newusable_filters_out_uninformative_git_valuestest 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.