Skip to content

Commit 4fb928b

Browse files
committed
feat(gateway): report build_commit in /v1/info (fleet freshness)
The semver Version ("0.1.0-poc") is identical across rebuilds of the same tag, so it can't tell whether an instance is running the latest image. Stamp the git short-SHA into the binary at build time and surface it as /v1/info.build_commit, so the fleet dashboard can flag out-of-date instances. - api: BuildCommit var (default "dev", set via -ldflags -X) + Info.build_commit. - Dockerfile: ARG GIT_COMMIT → ldflags -X …/internal/api.BuildCommit. - gateway-image.yml: pass build-args GIT_COMMIT=${{ github.sha }}. Verified the ldflags value lands in the binary; api tests pass.
1 parent 9dc7058 commit 4fb928b

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

.github/workflows/gateway-image.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ jobs:
7575
push: ${{ github.event_name != 'pull_request' }}
7676
tags: ${{ steps.meta.outputs.tags }}
7777
labels: ${{ steps.meta.outputs.labels }}
78+
# Stamp the git short-SHA into the binary → /v1/info.build_commit, so
79+
# the dashboard can tell which image each instance is actually running.
80+
build-args: |
81+
GIT_COMMIT=${{ github.sha }}
7882
cache-from: type=gha
7983
cache-to: type=gha,mode=max
8084
provenance: false

gateway/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ COPY . .
2525
# SOURCE_DATE_EPOCH lets CI stamp a deterministic build time.
2626
ARG SOURCE_DATE_EPOCH=0
2727
ARG TARGETARCH=amd64
28+
# GIT_COMMIT is stamped into /v1/info so the fleet dashboard can flag out-of-date
29+
# instances (the semver tag doesn't change between rebuilds). Defaults to "dev".
30+
ARG GIT_COMMIT=dev
2831
RUN GOARCH=${TARGETARCH} go build \
2932
-trimpath \
3033
-buildvcs=false \
31-
-ldflags "-s -w -buildid=" \
34+
-ldflags "-s -w -buildid= -X github.com/runonflux/cumulusvpn-gateway/internal/api.BuildCommit=${GIT_COMMIT}" \
3235
-o /out/gateway ./cmd/gateway
3336

3437
# ---- runtime stage ----------------------------------------------------------

gateway/internal/api/api.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ const Version = "0.1.0-poc"
3333
// MinClientVersion is the oldest client the gateway will happily serve.
3434
const MinClientVersion = "0.1.0"
3535

36+
// BuildCommit is the git short-SHA of this build, injected at compile time via
37+
//
38+
// -ldflags "-X github.com/runonflux/cumulusvpn-gateway/internal/api.BuildCommit=<sha>"
39+
//
40+
// It defaults to "dev" for local builds. Surfaced in /v1/info so the fleet
41+
// dashboard can flag instances running an out-of-date image (the semver Version
42+
// string alone can't — it doesn't change between rebuilds of the same tag).
43+
var BuildCommit = "dev"
44+
3645
// dnsServer is advertised to clients; forwarded like any other flow so client
3746
// DNS never leaks via the node resolver (POC: run an in-process DoH/DoT
3847
// resolver and hand out 10.8.0.1 as the DNS instead — docs/03-gateway.md).
@@ -49,6 +58,7 @@ type Info struct {
4958
ServerPubKey string `json:"server_pubkey"` // WG pubkey (base64)
5059
SignPubKey string `json:"sign_pubkey"` // ed25519 verify key (base64)
5160
MinClientVersion string `json:"min_client_version"`
61+
BuildCommit string `json:"build_commit"` // git short-SHA of the image build
5262
}
5363

5464
// Server is the control API.
@@ -91,6 +101,7 @@ func New(cfg *config.Config, dev *wg.Device, ent *entitle.Engine, lim *limiter.M
91101
s.info.SignPubKey = base64.StdEncoding.EncodeToString(s.signKey.Public().(ed25519.PublicKey))
92102
s.info.Version = Version
93103
s.info.MinClientVersion = MinClientVersion
104+
s.info.BuildCommit = BuildCommit
94105
return s
95106
}
96107

0 commit comments

Comments
 (0)