Skip to content

fix(docker): stamp emulator.Version so images report their release (#402) - #433

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/402-docker-version
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/402-docker-version

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Fixes #402, exactly as diagnosed in the issue: Dockerfile stamped the root module path, which has no Go files.

--- a/Dockerfile
-    -ldflags "-X main.version=${VERSION} -X github.com/scttfrdmn/substrate.Version=${VERSION}" \
+    -ldflags "-X main.version=${VERSION} -X github.com/scttfrdmn/substrate/emulator.Version=${VERSION}" \

Why it was invisible

go build -X against a symbol that does not exist links cleanly — no warning, no non-zero exit. The variable keeps its default. And substrate --version reads main.version, which was always stamped correctly, so the binary looked fine; only the HTTP endpoints were wrong.

Reproduced from a real image build rather than by reading the flag:

# pre-fix Dockerfile, VERSION=v9.99.99-imagetest
$ curl -s localhost:.../health
{"status":"ok","version":"dev"}
$ substrate --version
substrate version v9.99.99-imagetest      # ← correct, which is why nobody noticed

# post-fix
$ curl -s localhost:.../health
{"status":"ok","version":"v9.99.99-imagetest"}

Guards

The one-line fix is trivial; keeping it fixed is the actual work, since the failure mode is a typo that compiles. Three layers, each catching what the others cannot:

scripts/check-version-stamping.sh — new, wired up as make version-check and a CI job. It builds with the Dockerfile's own -ldflags (extracted from the file, not restated) and asserts the running server reports that version over HTTP. Plus two cheaper checks that name the culprit: Dockerfile and Makefile must stamp the same symbols, and every -X target must resolve via go doc. The runtime assertion is the load-bearing one — the spelling checks only catch mistakes I thought of.

docker.yml — smoke-tests the image it just pushed against github.ref_name. This is the layer CI cannot reach: the VERSION build-arg wiring only exists in a real image build.

ci.yml — the build job omitted emulator.Version entirely. Cosmetic today (that binary isn't published) but it would have drifted from the Makefile the same way, and make version-check would now fail on it.

Verified the guard is load-bearing rather than decorative — reverting Dockerfile to the buggy path:

check-version-stamping: Dockerfile and Makefile stamp different symbols:
-github.com/scttfrdmn/substrate/emulator.Version
+github.com/scttfrdmn/substrate.Version
check-version-stamping: -X github.com/scttfrdmn/substrate.Version: no symbol Version in package …
check-version-stamping: GET /health reported version "dev", want "v9.99.99-stamptest" …
check-version-stamping: GET /_localstack/health reported version "dev" …
check-version-stamping: GET /_localstack/info reported version "dev" …

All three layers fire independently.

Docs

emulator/doc.go — Version's comment now gives the exact -X path and warns that a wrong one fails silently, since that comment is what someone writing a new build recipe will read.

docs/getting-started.md — the /health examples showed {"status":"ok"}, omitting the field this issue is about. They now show version, with a note that it identifies the build answering (the reporter's use case: verifying a pinned tag in CI) and that a plain go build reports dev.

Not done

The issue's alternative suggestion — falling back to runtime/debug.ReadBuildInfo() so a VCS-stamped binary self-reports — is deliberately skipped. It would mask a broken -X rather than surface it, and the CI/release guards make the ldflags path reliable. Worth its own issue if you want go install-ed binaries to report a version.

Verification

gofmt, go build ./..., go vet ./..., golangci-lint run ./... (0 issues), make test (race), test/e2e, make docs-reference-check docs-versions version-check — all clean. shellcheck clean on the new script, matching check-doc-versions.sh. Both workflow files re-parsed as YAML after editing. Image built and run both ways with podman, as shown above.

Closes #402

)

The Dockerfile stamped `github.com/scttfrdmn/substrate.Version` — the root
module path, which contains no Go files. The variable /health and
/_localstack/{health,info} actually serve is
`github.com/scttfrdmn/substrate/emulator.Version`, so every published image
since those endpoints existed reported "dev".

The linker silently ignores -X against a symbol that does not exist: no
warning, no non-zero exit, the variable just keeps its default. Confirmed by
building the same tree both ways — both builds succeeded, one reported the
version and one reported "dev". `substrate --version` reads main.version and
was always correct, which is why this survived five releases unnoticed.

Consumers pinning an image tag for reproducible CI had no runtime way to
confirm which build answered, so a silently-wrong tag or a stale cached image
looked identical to a fresh pull.

Guarded at all three layers, because the failure mode is a typo that links
cleanly:

- scripts/check-version-stamping.sh (make version-check, run by CI) builds
  with the Dockerfile's own -ldflags and asserts the server reports that
  version over HTTP. It also fails if the Dockerfile and Makefile stamp
  different symbols, and if any -X names a symbol that does not exist. It
  asserts the observable outcome rather than the spelling of the flag, since
  the spelling checks can only catch mistakes we thought of.
- docker.yml smoke-tests the image it just pushed against the tag being
  released — the build-arg wiring only a real image can exercise.
- ci.yml's build job now stamps emulator.Version too; it previously omitted
  it and would have drifted from the Makefile the same way.

Verified the guard is load-bearing: reverting the Dockerfile to the buggy path
fails all three of its layers and reproduces `{"status":"ok","version":"dev"}`
from a real image build, while the fixed image reports the sentinel from the
CLI and all three endpoints.

Closes #402
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit f71e8ff into main Aug 1, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/402-docker-version branch August 1, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Released container images report version "dev" from /health and /_localstack/info

1 participant