feat(server): public GET /version with build version and commit
ci / shared (pull_request) Successful in 14s
ci / test (pull_request) Successful in 24m24s
ci / image (pull_request) Skipped

The staff dashboard of the portal shows which build of each service runs
(portal#64). GET /version is public like /healthz and returns
{version, commit}: the latest release tag and the full commit hash, set at
image build time with -ldflags (Dockerfile build args VERSION and COMMIT,
filled by CI). A local build reports "dev" and an empty commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-05 19:44:56 +02:00
1 parent 85934567f1
commit 7d63abbbb0
7 files changed
+60 -2

No files matched your search

+1
View File
@@ -39,6 +39,7 @@ func TestOpenAPISpec_loadsAndIsConsistent(t *testing.T) {
}{
{"GET", "/healthz"},
{"GET", "/readyz"},
{"GET", "/version"},
{"GET", "/v1/tenants/by-slug/acme"},
{"GET", "/v1/entitlements?tenant_id=00000000-0000-0000-0000-000000000001"},
{"GET", "/v1/api-keys?tenant_id=00000000-0000-0000-0000-000000000001"},
+9
View File
@@ -13,6 +13,7 @@ import (
"time"
"git.breakpilot.com/platform/tenant-registry/internal/authn"
"git.breakpilot.com/platform/tenant-registry/internal/buildinfo"
"git.breakpilot.com/platform/tenant-registry/internal/config"
"git.breakpilot.com/platform/tenant-registry/internal/erp"
"git.breakpilot.com/platform/tenant-registry/internal/keycloak"
@@ -78,6 +79,9 @@ func NewRouter(s *Server) http.Handler {
// PUBLIC_EXPLICIT: health + status probes.
root.HandleFunc("GET /healthz", s.healthz)
root.HandleFunc("GET /readyz", s.readyz)
// PUBLIC_EXPLICIT: build version and commit (portal#64), no tenant data;
// the staff dashboard and feedback reports show which build runs.
root.HandleFunc("GET /version", s.version)
// PUBLIC_EXPLICIT: ERPNext webhooks carry no Keycloak token — the body
// is HMAC-signed with ERP_WEBHOOK_SECRET (receiver refuses without it).
root.HandleFunc("POST /v1/internal/erp/webhook", s.erpWebhook)
@@ -219,6 +223,11 @@ func (s *Server) healthz(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
}
// version reports the build (internal/buildinfo, set at image build time).
func (s *Server) version(w http.ResponseWriter, _ *http.Request) {
writeJSON(w, http.StatusOK, map[string]string{"version": buildinfo.Version, "commit": buildinfo.Commit})
}
func (s *Server) readyz(w http.ResponseWriter, r *http.Request) {
if err := s.Store.Ping(r.Context()); err != nil {
writeError(w, http.StatusServiceUnavailable, "store_unavailable", err.Error())
+13
View File
@@ -6,6 +6,7 @@ import (
"testing"
"time"
"git.breakpilot.com/platform/tenant-registry/internal/buildinfo"
"git.breakpilot.com/platform/tenant-registry/internal/store"
)
@@ -18,6 +19,18 @@ func TestHealthz(t *testing.T) {
})
}
func TestVersion(t *testing.T) {
defer func(v, c string) { buildinfo.Version, buildinfo.Commit = v, c }(buildinfo.Version, buildinfo.Commit)
buildinfo.Version, buildinfo.Commit = "v9.9.9", "0123456789abcdef0123456789abcdef01234567"
eachStore(t, func(t *testing.T, h *testHarness) {
resp, raw := h.do("GET", "/version", nil)
got := decode[map[string]string](t, raw)
if resp.StatusCode != 200 || got["version"] != "v9.9.9" || got["commit"] != "0123456789abcdef0123456789abcdef01234567" || len(got) != 2 {
t.Fatalf("version: %d %s", resp.StatusCode, raw)
}
})
}
func TestCreateTenant(t *testing.T) {
eachStore(t, func(t *testing.T, h *testHarness) {
resp, body := h.do("POST", "/v1/tenants", map[string]any{