The shipped binary reports version "dev": no -X ldflags in the Makefile or Dockerfile #253
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
cmd/webhooker/main.go:61declaresversion = "dev"with the comment "Build-time variables set via -ldflags", but nothing sets them.Makefile'sbuildtarget andDockerfile:71(go build -ldflags '-extldflags "-static"') both omit-X.Verified by execution during the deployability audit: the built container answers
/.well-known/healthcheckwith"version":"dev", and the UI footer readsWebhooker by @sneak | dev.This is a release-integrity defect, not a cosmetic one. Tagging
v1.0.0produces an artifact that cannot identify itself asv1.0.0, and the documented upgrade procedure asks the operator to confirm the new build is live — which nothing on the healthcheck or in the UI currently allows them to do. It also makes any future bug report ambiguous about which build it came from.Definition of done
make buildand theDockerfileboth stamp version, and the value is derived from git (tag when the build is at a tag, otherwise a describe-style identifier including the short SHA and a dirty marker). A build from a clean checkout at a tag must report exactly that tag./.well-known/healthcheckand the UI footer report the stamped value.Dockerfile:71..git) must still build and report something honest rather than failing or claiming a tag it is not. State what it reports.Verification
make checkgreen.make build, and from adocker build.Plan:
script/versionas the single source of the version string:VERSIONfrom the environment if set and non-empty, elsegit describe --tags --always --dirtywhen a git work tree with metadata is present, elseunknown. No timestamp, no hostname — nothing that varies between two builds of the same commit.Makefile:VERSION ?= $(shell script/version)and aGO_LDFLAGShook, sobuildcompiles with-ldflags '-X main.version=$(VERSION) $(GO_LDFLAGS)'. Both the plain build and the static relink compose flags through that one place rather than each spelling out its own..dockerignoreexcludes.git/, so the image has no git metadata and cannot derive a version itself. The version therefore enters asARG VERSION(defaultunknown, honest for a baredocker build .), andscript/dockerpasses--build-arg VERSION="$(script/version)"from the host, where.gitdoes exist. The static relink atDockerfile:71becomesmake build VERSION=... GO_LDFLAGS='-extldflags "-static"', so it cannot drop the stamp by replacing the flags.internal/versionscriptpackage, mirroringinternal/ciscript: throwaway git repos covering clean-at-a-tag (exact tag, no suffix), untagged, dirty, no-git, andVERSIONoverride./.well-known/healthcheckshould read after step 3.No change to the reporting sites —
main.versionalready reachesglobals.Version, the healthcheck and the footer.Implemented in #260 (branch
issue-253-version-stamping, basenext).Built as planned, with one addition the plan did not anticipate: stamping the binary alone did not fix the footer.
base.htmlrenders.Versionwith a literaldevfallback, and nothing ever putVersioninto the template data — so the footer readdeveven from a correctly stamped binary.renderTemplatenow supplies it.Verified (full output and evidence in the PR body):
make checkgreen withGOFLAGS=-count=1— 21 packages, 572 tests,0 issues.from the containerized linter.v0.0.0-impl253, deleted before pushing: amake buildbinary answers/.well-known/healthcheckwith"version":"v0.0.0-impl253"— exactly the tag, no suffix.make dockerimage at the same tag reports the same on the healthcheck, in the footer (<span>v0.0.0-impl253</span>) and in the startup log. Read off the running binary, so the stamp survives the static relink; it is running on Alpine, which a non-static binary could not.make buildruns of one commit are byte-identical (dc38ae7e...4349twice). Nothing time- or host-dependent is stamped.git archivetarball and a baredocker build .both build, run, and report"version":"unknown".Tests: new
internal/versionscriptpackage (eleven cases over throwaway repositories, plus guards that theMakefilekeeps composing both halves of the linker flags and that no rawgo buildreturns to theDockerfile), andTestFooterReportsStampedVersionininternal/handlers.