fix(version): single-source internal/version, fix dockerfile ldflags #27

Merged
steve merged 1 commits from fix-version-ldflags into main 2026-05-09 15:26:51 +01:00
Owner

Why

A docker-built :v1.0.0 server reports version="dev" from /api/version. Reason: deploy/Dockerfile.server set -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 from internal/version.Version, which the Dockerfile never wired. So host.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

  • Add Date field to internal/version so it can hold all three build constants.
  • Drop the var version/commit/date package-locals in cmd/{server,agent}/main.go; route every reference through internal/version.
  • Dockerfile + Makefile now set the same single set of -X internal/version.{Version,Commit,Date} flags. No more split sources to drift.

Test plan

  • go vet ./... clean
  • go test ./internal/server/http/... green
  • make build → both binaries --version show the git-describe tag
  • docker build --build-arg VERSION=v1.0.1-test ... → both extracted binaries --version show v1.0.1-test
  • After merge + new tagged release: deploy, click "update agent" on dummy4, expect chip to clear (or already_up_to_date 409 if dispatched again)
## Why A docker-built `:v1.0.0` server reports `version="dev"` from `/api/version`. Reason: `deploy/Dockerfile.server` set `-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 from `internal/version.Version`, which the Dockerfile never wired. So `host.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 - Add `Date` field to `internal/version` so it can hold all three build constants. - Drop the `var version/commit/date` package-locals in `cmd/{server,agent}/main.go`; route every reference through `internal/version`. - Dockerfile + Makefile now set the same single set of `-X internal/version.{Version,Commit,Date}` flags. No more split sources to drift. ## Test plan - [x] `go vet ./...` clean - [x] `go test ./internal/server/http/...` green - [x] `make build` → both binaries `--version` show the git-describe tag - [x] `docker build --build-arg VERSION=v1.0.1-test ...` → both extracted binaries `--version` show `v1.0.1-test` - [ ] After merge + new tagged release: deploy, click "update agent" on dummy4, expect chip to clear (or `already_up_to_date` 409 if dispatched again)
steve added 1 commit 2026-05-09 15:20:30 +01:00
fix(version): use internal/version as single source for build constants
CI / Test (store) (pull_request) Successful in 5s
CI / Test (rest) (pull_request) Successful in 9s
CI / Build (windows/amd64) (pull_request) Successful in 7s
CI / Test (server-http) (pull_request) Successful in 17s
CI / Build (linux/amd64) (pull_request) Successful in 7s
CI / Lint (pull_request) Successful in 19s
CI / Build (linux/arm64) (pull_request) Successful in 14s
e2e / Playwright vs docker-compose (pull_request) Successful in 1m27s
8afda7cd8c
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.
steve merged commit f4db0b17e8 into main 2026-05-09 15:26:51 +01:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: steve/restic-manager#27