Stamp shared build metadata into banger binaries

Treat `banger`, `bangerd`, and `banger-vsock-agent` as one release by
stamping the same version, commit SHA, and build timestamp into every
binary through a shared ldflag-backed `internal/buildinfo` package.

Add `banger version`, extend daemon ping/status to report the running
daemon's build tuple, and keep the guest helper linked to the same build
metadata without adding a new public version surface for it.

Validate with `GOCACHE=/tmp/banger-gocache go test ./...`, `make build`,
`./build/bin/banger version`, and `./build/bin/banger daemon status`
after the daemon restarts onto the new binary.
This commit is contained in:
Thales Maciel 2026-03-22 17:14:06 -03:00
parent ea2db1e868
commit f798e1db33
No known key found for this signature in database
GPG key ID: 33112E6833C34679
9 changed files with 219 additions and 13 deletions

View file

@ -16,6 +16,7 @@ import (
"time"
"banger/internal/api"
"banger/internal/buildinfo"
"banger/internal/config"
"banger/internal/model"
"banger/internal/paths"
@ -250,7 +251,15 @@ func (d *Daemon) dispatch(ctx context.Context, req rpc.Request) rpc.Response {
}
switch req.Method {
case "ping":
result, _ := rpc.NewResult(api.PingResult{Status: "ok", PID: d.pid, WebURL: d.webURL})
info := buildinfo.Current()
result, _ := rpc.NewResult(api.PingResult{
Status: "ok",
PID: d.pid,
WebURL: d.webURL,
Version: info.Version,
Commit: info.Commit,
BuiltAt: info.BuiltAt,
})
return result
case "shutdown":
go d.Close()

View file

@ -2,14 +2,17 @@ package daemon
import (
"context"
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"banger/internal/api"
"banger/internal/buildinfo"
"banger/internal/model"
"banger/internal/paths"
"banger/internal/rpc"
"banger/internal/system"
)
@ -42,6 +45,28 @@ func TestRegisterImageRequiresKernel(t *testing.T) {
}
}
func TestDispatchPingIncludesBuildInfo(t *testing.T) {
d := &Daemon{pid: 42, webURL: "http://127.0.0.1:7777"}
resp := d.dispatch(context.Background(), rpc.Request{Version: rpc.Version, Method: "ping"})
if !resp.OK {
t.Fatalf("dispatch(ping) = %+v, want ok", resp)
}
var got api.PingResult
if err := json.Unmarshal(resp.Result, &got); err != nil {
t.Fatalf("Unmarshal(PingResult): %v", err)
}
info := buildinfo.Current()
if got.Status != "ok" || got.PID != 42 || got.WebURL != "http://127.0.0.1:7777" {
t.Fatalf("PingResult = %+v, want status/pid/weburl populated", got)
}
if got.Version != info.Version || got.Commit != info.Commit || got.BuiltAt != info.BuiltAt {
t.Fatalf("PingResult build info = %+v, want %+v", got, info)
}
}
func TestPromoteImageCopiesBootArtifactsIntoArtifactDir(t *testing.T) {
dir := t.TempDir()
rootfs := filepath.Join(dir, "rootfs.ext4")