feat: report the running build via GET /api/version - #385
Merged
Conversation
Answers "what is this instance actually running?" without shell access to the host. The image already carries version and revision in its OCI labels, but labels are only readable with `docker inspect` on the host, so they cannot answer the question from outside -- and a locally-built image carries no labels at all, which is exactly the case that came up: the dev container's provenance was simply unrecoverable. Labels are also invisible from inside the container, so the values are now passed as Docker build args and baked into the environment. CI supplies them from the same metadata that produces the labels; any build that omits them reports "unknown" instead of failing, so `dotnet run` and local `docker build` keep working. Anonymous on purpose: the point is checking a deployment without credentials. The repository is public, so the commit SHA is already visible on GitHub, and the response exposes no configuration or secret. Verified end to end, not just by unit test: built the image with build args and confirmed they land in the environment; built it without and confirmed the "unknown" fallback; then ran the container against a throwaway MariaDB and `GET /api/version` returned the injected values as JSON. That last step matters because `/api/version` previously returned index.html -- the SPA catch-all was swallowing it -- so routing precedence was the one thing unit tests could not prove.
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.
Answers "what is this instance actually running?" with one request, no shell access to the host.
Why the OCI labels were not enough
The image already carries
org.opencontainers.image.versionand.revision. Two problems:docker inspecton the host. They cannot answer the question from outside, which is when you usually want it.poracleweb.net:oidc-dev-fixed, built by hand, carrying only the Ubuntu base version. Which commit dev was on turned out to be unrecoverable.Labels are also invisible from inside the container, so the values are passed as build args and baked into the environment instead.
Change
VersionController.csGET /api/versionDockerfileBUILD_VERSION/BUILD_REVISION/BUILD_DATEargs → env, defaulting tounknowndocker-publish.ymlBuilds that omit the args report
unknownrather than failing, sodotnet runand a plain localdocker buildkeep working unchanged.Anonymous by design. The point is checking a deployment without credentials. The repository is public, so the commit SHA is already visible on GitHub, and the response exposes no configuration, secret, or host detail beyond the ASP.NET environment name.
Verification
Five unit tests cover the controller: values from configuration, 7-character shortening, the
unknownfallback when no build args were supplied, blank/whitespace values treated as unknown (an unset build arg arrives as an empty string, not a missing key), and a revision shorter than seven characters not being truncated.Unit tests cannot prove the two parts that actually worried me, so both were checked for real:
Build-arg plumbing — built the image with args and confirmed they land in the environment:
then built it without args and confirmed all three read
unknown.Routing precedence — ran the container against a throwaway MariaDB and hit the endpoint over HTTP:
This mattered:
/api/versionpreviously returnedindex.html, because the SPA catch-all swallowed it. A 200 alone proves nothing here — only the JSON body does.Full backend suite: 1462 tests pass. Test containers, image and network cleaned up afterwards.
Follow-up
Once merged, CI publishes
:betaand the dev watchtower picks it up within ~60s, socurl https://alerts.pgandev.us/api/versionbecomes the standing answer for dev. Prod reports it from the next release build.