Repository navigation
feat(api): public /version endpoint exposes git SHA + build time - #901
Conversation
Adds GitSHA ldflag + a public GET /version returning version, git_sha, and build_time so a running environment's deployed commit can be verified against the branch HEAD (diagnoses deploy-lag). Wires the short SHA through the Docker/Make build.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughThis PR adds a public ChangesPublic /version Endpoint for Deploy Verification
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
…h fallback (#916) isStaticPath() only excluded /api/* and /health, so /version was falling through to the SPA file server on the Lambda Function URL path, returning index.html instead of the JSON build-metadata response added by PR #901. The HTTP/Cloud Run path was unaffected because mux.HandleFunc("/version", ...) is registered before the SPA catch-all in CreateHTTPServer. Add /version to the isStaticPath allowlist (same pattern as /health) so handleLambdaHTTPEvent routes it to app.API.HandleRequest, which already handles it correctly via the ExactPath:/version AuthPublic router entry. Also add test cases for /version and //version (double-slash normalised) to TestIsStaticPath.
Adds GitSHA ldflag + a public GET /version returning version, git_sha, and build_time so a running environment's deployed commit can be verified against the branch HEAD (diagnoses deploy-lag). Wires the short SHA through the Docker/Make build.
Summary
Adds a public
GET /versionendpoint that returns the deployed build's version, git commit SHA, and build timestamp, so deploy-lag (an environment still serving a stale build) can be diagnosed by curling the URL and comparing the SHA to the branch HEAD.Closes #900.
Changes
cmd/server/main.go: newGitSHAldflag var; exportsVERSION,BUILD_TIME, andGIT_SHAto the environment (the api package reads them from env to avoid an import cycle); startup log now includes the SHA.internal/api/handler_version.go:getVersionhandler +VersionResponse{version, git_sha, build_time}, read from env withdev/unknownfallbacks. Carries no account IDs, ARNs, or secrets, so it is safe to expose unauthenticated (not an info leak like sec(api): GET /api/info (unauthenticated) leaks Secrets Manager ARN including AWS account ID and region #437/sec(api): move APIKeySecretURL + DeploymentAWSAccountID out of unauthenticated /api/info (re-scope of #527) #633).internal/api/router.go+middleware.go: registerGET /versionasAuthPublicand add it to the public allowlist.internal/server/http.go: register/versionon the container HTTP mux (a root path, like/health) so it reaches the API router instead of the SPA catch-all whenSTATIC_DIRis set. Deliberately skipsensureDBso the deployed commit stays readable even when the database is down, which is exactly when confirming the build matters.Dockerfile/Makefile: thread the short SHA into the build. The terraform build module already passes--build-arg GIT_COMMITand--build-arg BUILD_DATE; the Dockerfile now declares those ARGs and stampsmain.GitSHA/main.BuildTimefrom them (falling back tounknown/date -uso a baredocker build .still works).make buildstampsGIT_SHAfromgit rev-parse --short HEAD.How the git SHA is injected
Via build-arg, not in-build git. The container build context excludes
.gitreliability, and terraform already computes the short SHA (local.git_commit) and passes it as--build-arg GIT_COMMIT. We consume that existing arg. Localmake buildderives it fromgit rev-parse.Testing
go build ./...clean.go test ./internal/api/... ./internal/server/...— 1692 pass.dev/unknown), env-stamped values, and router dispatch as a public no-auth route.-X main.GitSHA=<sha>and confirmed the SHA is embedded.Verify a deployed environment
Summary by CodeRabbit
/versionendpoint that returns build metadata including version, git SHA, and build time