docker: a plain docker build . stamps the git version (closes #210)
check / check (push) Successful in 1m33s

A plain `docker build .`, which is how upaas builds, stamped `dev`:
`.dockerignore` left out `.git` and the builder declared
`ARG VERSION=dev`. `.dockerignore` now sends `.git` and lists no tracked
file, which git in the build would count as deleted and mark `-dirty`.
`ARG VERSION` has no default. The Makefile takes `VERSION` from the
environment with `?=`, so a build arg still wins (`script/docker` keeps
passing one); otherwise `git describe` runs in the builder. A new
`make version` prints the version, and the builder fails when the
context carries `.git` and it comes out empty, `dev` or `unknown`.

Model: opus-5-5
This commit is contained in:
2026-10-02 00:59:44 +00:00
parent c9510a986c
commit 3c1dfe2575
7 changed files with 51 additions and 27 deletions
+13 -6
View File
@@ -534,6 +534,7 @@ provide:
```sh
make build # Build binary to bin/dnswatcher
make version # Print the version make build stamps
make test # Run tests with race detector
make lint # Run golangci-lint in Docker (requires docker)
make fmt # Format code and Markdown (requires docker)
@@ -544,13 +545,19 @@ make clean # Remove build artifacts
### Build-Time Variables
`make build` sets the version with `-ldflags "-X main.Version=..."`, taking it
from `git describe --tags --always --dirty`, or from `VERSION` when given on the
command line (`make build VERSION=1.2.3`). The version appears in the startup
log and in the health check response.
from `VERSION` when given on the command line (`make build VERSION=1.2.3`) or in
the environment, otherwise from `git describe --tags --always --dirty`, and
`dev` without git metadata. The version appears in the startup log and in the
health check response.
The Docker image has no `.git`, so the `Dockerfile` takes the version as
`--build-arg VERSION`. `make docker` passes it; a plain `docker build` passes
none, and that image reports `dev`.
The image takes it the same way, from the `.git` the build context carries, so a
plain `docker build .` of a clone stamps the commit it was built from; a clone
without tags, such as a shallow one, stamps the short commit. A
`--build-arg VERSION=...` takes precedence; `make docker` passes the version
`git describe` gives on the host. The build fails when the context carries
`.git` and the version comes out empty, `dev` or `unknown`. `.dockerignore` must
list no tracked file: git in the build would see it as deleted and mark the
version `-dirty`.
---