fix(version): single-source internal/version, fix dockerfile ldflags #27
Reference in New Issue
Block a user
Delete Branch "fix-version-ldflags"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
A docker-built
:v1.0.0server reportsversion="dev"from/api/version. Reason:deploy/Dockerfile.serverset-X main.version=...but every update / mismatch check (host_update.go:61,hosts.go:94,fleet_update.go:101,ui_handlers.go:284,metrics.go:184) reads frominternal/version.Version, which the Dockerfile never wired. Sohost.AgentVersion ("v1.0.0") == version.Version ("dev")is always false → chip stays "update available" → operator clicks update → agent re-fetches the same v1.0.0 bundled binary → loop. dummy4 hit exactly this.What
Datefield tointernal/versionso it can hold all three build constants.var version/commit/datepackage-locals incmd/{server,agent}/main.go; route every reference throughinternal/version.-X internal/version.{Version,Commit,Date}flags. No more split sources to drift.Test plan
go vet ./...cleango test ./internal/server/http/...greenmake build→ both binaries--versionshow the git-describe tagdocker build --build-arg VERSION=v1.0.1-test ...→ both extracted binaries--versionshowv1.0.1-testalready_up_to_date409 if dispatched again)The Dockerfile only set `-X main.version=...`, so docker-built binaries left `internal/version.Version` at its default "dev". The update logic (host_update.go:61, hosts.go:94, fleet_update.go:101 et al.) compares against `internal/version.Version`, so a v1.0.0 host always looked out-of-date to a v1.0.0 server, the chip never cleared, and pressing "update" re-downloaded the same bundled binary on a loop. Collapse the two version sources: drop the `var version/commit/date` locals in cmd/{server,agent}/main.go, route everything through internal/version (now also carrying Date), and have both the Dockerfile and the Makefile set the same single set of -X flags. Verified end-to-end: make build and docker build both emit binaries whose --version reflects the build VERSION.