diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e917ba3..dbe613a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -127,7 +127,7 @@ jobs: env: SHA: ${{ steps.sha.outputs.sha }} run: | - docker build --build-arg "VERSION=$SHA" -t "$APP-local:$SHA" . + docker build --build-arg "VERSION=$SHA" --build-arg "BUILD_SHA=$SHA" -t "$APP-local:$SHA" . docker save "$APP-local:$SHA" | gzip > image.tar.gz ls -lh image.tar.gz diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 3a8b3a6..dc9665d 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -38,7 +38,7 @@ jobs: - name: Build image run: | - docker build --build-arg "VERSION=$GITHUB_SHA" -t "$APP-local:$GITHUB_SHA" . + docker build --build-arg "VERSION=$GITHUB_SHA" --build-arg "BUILD_SHA=$GITHUB_SHA" -t "$APP-local:$GITHUB_SHA" . docker save "$APP-local:$GITHUB_SHA" | gzip > image.tar.gz ls -lh image.tar.gz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8dc3027..f86efbc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -42,6 +42,7 @@ jobs: ghcr.io/meltforce/vimmary:latest build-args: | VERSION=${{ github.ref_name }} + BUILD_SHA=${{ github.sha }} - name: GitHub release env: diff --git a/Dockerfile b/Dockerfile index 431636b..16fe007 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,10 +22,12 @@ COPY --from=frontend /app/web/dist ./web/dist # /version and the loopback /healthz report it as "build"; pipeline-deploy # waits for the SHA on /version. Without it every build reports "dev". ARG VERSION=dev +# The full commit SHA; /healthz on the real listener reports it as "sha". +ARG BUILD_SHA=dev RUN --mount=type=cache,target=/go/pkg/mod \ --mount=type=cache,target=/root/.cache/go-build \ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -ldflags="-s -w -X main.Version=${VERSION}" -o vimmary ./cmd/vimmary + go build -ldflags="-s -w -X main.Version=${VERSION} -X main.BuildSHA=${BUILD_SHA}" -o vimmary ./cmd/vimmary # Stage 3: Runtime FROM alpine:3.24 diff --git a/cmd/vimmary/main.go b/cmd/vimmary/main.go index afddbfd..1884699 100644 --- a/cmd/vimmary/main.go +++ b/cmd/vimmary/main.go @@ -35,6 +35,10 @@ import ( var Version = "dev" +// BuildSHA is the commit the binary was built from, set at build time via +// -ldflags from the BUILD_SHA build argument. /healthz reports it. +var BuildSHA = "dev" + // The startup sequence is the subject of two entries in INCIDENTS.md, both from // 2026-08-06, and both about the order rather than about any single step. It is // therefore spread over the named functions below in the order they must run: @@ -394,7 +398,7 @@ func runMCPStdio(svc *service.Service, log *slog.Logger) error { // openListener, and keeping the two apart is what lets the health listener come // after everything is mounted. func buildHTTPServer(cfg *config.Config, svc *service.Service, store *storage.DB, authn *auth.Auth, log *slog.Logger) (*server.Server, error) { - srv := server.New(svc, store, Version, log, authn) + srv := server.New(svc, store, Version, BuildSHA, log, authn) // With login configured, /mcp takes personal access tokens with scope // mcp, and WhoIs only while tsnet runs; without it, WhoIs as before. diff --git a/go.mod b/go.mod index 220e8bc..2c34ffb 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/horiagug/youtube-transcript-api-go v0.0.13 github.com/jackc/pgx/v5 v5.13.0 github.com/mark3labs/mcp-go v1.5.0 - github.com/meltforce/meltkit v0.4.0 + github.com/meltforce/meltkit v0.4.1 github.com/pgvector/pgvector-go v0.4.1 github.com/yuin/goldmark v1.8.7 golang.org/x/term v0.48.0 diff --git a/go.sum b/go.sum index 733024c..23eac6c 100644 --- a/go.sum +++ b/go.sum @@ -193,10 +193,8 @@ github.com/mdlayher/sdnotify v1.0.0 h1:Ma9XeLVN/l0qpyx1tNeMSeTjCPH6NtuD6/N9XdTlQ github.com/mdlayher/sdnotify v1.0.0/go.mod h1:HQUmpM4XgYkhDLtd+Uad8ZFK1T9D5+pNxnXQjCeJlGE= github.com/mdlayher/socket v0.7.0 h1:qVREPVwtUMg17pwvveQxpurq0PVisMxi3FGgpsorMYQ= github.com/mdlayher/socket v0.7.0/go.mod h1:f7iKql2EK/rfsWYDKofKjk2Ig7I+6HQWdMIdn1tO4A4= -github.com/meltforce/meltkit v0.3.0 h1:cic5C9gaJUlNFWMAl/Wu1gpC7gSB2sHNJDjSaZTmO8Q= -github.com/meltforce/meltkit v0.3.0/go.mod h1:CYQKT7ZNW2yTZVvll0jbhz1KsZ2K2K6zXf+ZhIX+gDc= -github.com/meltforce/meltkit v0.4.0 h1:+PEITWLt5caApuUXoyORHWZKB26zSWv0mFgZPInHfsk= -github.com/meltforce/meltkit v0.4.0/go.mod h1:CYQKT7ZNW2yTZVvll0jbhz1KsZ2K2K6zXf+ZhIX+gDc= +github.com/meltforce/meltkit v0.4.1 h1:d1IvaZmV9H+0x3XFxqeVB8D5IT2OQ1u2DIJ+LauRGIg= +github.com/meltforce/meltkit v0.4.1/go.mod h1:CYQKT7ZNW2yTZVvll0jbhz1KsZ2K2K6zXf+ZhIX+gDc= github.com/miekg/dns v1.1.73 h1:uhT8nJxmTrPJYClxVxTCX+CVn6qnzSiybRk72Z6DgrE= github.com/miekg/dns v1.1.73/go.mod h1:RW2Obtfd5NZHvOFe3zYG0W8koWOQtAzyHaLo8vASBuQ= github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= diff --git a/internal/server/health_test.go b/internal/server/health_test.go new file mode 100644 index 0000000..1bb3e3b --- /dev/null +++ b/internal/server/health_test.go @@ -0,0 +1,34 @@ +package server + +import ( + "io" + "log/slog" + "net/http" + "net/http/httptest" + "testing" +) + +// /healthz on the real listener reports status and the commit the image was +// built from; "dev" outside a pipeline build. +func TestHealthzReportsBuildSHA(t *testing.T) { + const sha = "0123456789abcdef0123456789abcdef01234567" + log := slog.New(slog.NewTextHandler(io.Discard, nil)) + for _, tc := range []struct{ name, sha, want string }{ + {"pipeline build", sha, `{"status":"ok","sha":"` + sha + `"}`}, + {"local build", "dev", `{"status":"ok","sha":"dev"}`}, + } { + t.Run(tc.name, func(t *testing.T) { + rec := httptest.NewRecorder() + newBase(tc.sha, log).ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/healthz", nil)) + if rec.Code != http.StatusOK { + t.Errorf("status = %d, want 200", rec.Code) + } + if ct := rec.Header().Get("Content-Type"); ct != "application/json" { + t.Errorf("Content-Type = %q, want application/json", ct) + } + if rec.Body.String() != tc.want { + t.Errorf("body = %q, want %q", rec.Body.String(), tc.want) + } + }) + } +} diff --git a/internal/server/server.go b/internal/server/server.go index 0a60366..ca3ebf2 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -32,10 +32,18 @@ type Server struct { isDisabled func(ctx context.Context, userID int) (bool, error) } -// New builds the router. authn is nil when login is not configured. -func New(svc *service.Service, store *storage.DB, version string, log *slog.Logger, authn *auth.Auth) *Server { +// newBase builds the meltkit server, whose /healthz answers +// {"status":"ok","sha":""} (homelab STANDARDS.md § Image registry & +// tagging). +func newBase(sha string, log *slog.Logger) *mkserver.Server { + return mkserver.New(mkserver.WithLogger(log), mkserver.WithBuildSHA(sha)) +} + +// New builds the router. sha is the commit /healthz reports. authn is nil +// when login is not configured. +func New(svc *service.Service, store *storage.DB, version, sha string, log *slog.Logger, authn *auth.Auth) *Server { s := &Server{ - Server: mkserver.New(mkserver.WithLogger(log)), + Server: newBase(sha, log), svc: svc, store: store, version: version, @@ -57,10 +65,9 @@ func (s *Server) routes() { r := s.Router() // Version route — no Tailscale auth, same as /healthz. It reports which - // build is serving, which is what lets a deploy gate tell a real rollout - // from a green pipeline over an unchanged image. meltkit owns /healthz and - // answers a fixed "ok", so this is a route of its own rather than an - // override. + // build is serving and whether the database answers; pipeline-deploy waits + // on it. meltkit owns /healthz, which reports status and the build SHA + // without touching the database, so this is a route of its own. r.Get("/version", s.handleVersion) // Webhook route — no Tailscale auth, uses per-user Bearer token diff --git a/scripts/e2e b/scripts/e2e index 9c9b69a..18961c1 100755 --- a/scripts/e2e +++ b/scripts/e2e @@ -116,7 +116,7 @@ if [[ "$upgrade" == 1 ]]; then fi step "building vimmary-local:${BUILD_SHA}" -docker build -q --build-arg "VERSION=${BUILD_SHA}" -t "vimmary-local:${BUILD_SHA}" . >/dev/null +docker build -q --build-arg "VERSION=${BUILD_SHA}" --build-arg "BUILD_SHA=${BUILD_SHA}" -t "vimmary-local:${BUILD_SHA}" . >/dev/null if [[ "$upgrade" == 1 ]]; then step "1. base image on an empty database"