docker: a plain docker build . stamps the git version (closes #210)
check / check (push) Successful in 1m33s
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:
+19
-5
@@ -36,11 +36,25 @@ COPY . .
|
||||
# Run the tests - build fails if any test fails
|
||||
RUN make test
|
||||
|
||||
# Build the binary. .dockerignore leaves out .git, so `git describe` in
|
||||
# the Makefile cannot find the version here: script/docker passes it as
|
||||
# --build-arg VERSION, and a build that passes none reports `dev`.
|
||||
ARG VERSION=dev
|
||||
RUN make build VERSION="${VERSION}"
|
||||
# Version stamped into the binary: the VERSION build arg when one is
|
||||
# given (script/docker passes one), otherwise what `git describe` says of
|
||||
# the .git in the build context, so a plain `docker build .` of a clone
|
||||
# stamps its tag or short commit. The build arg reaches make through the
|
||||
# environment.
|
||||
ARG VERSION
|
||||
|
||||
# A context that carries .git must yield a real version: one that is
|
||||
# empty, `dev` or `unknown` cannot be traced back to a commit.
|
||||
RUN version="$(make version)"; \
|
||||
if [ -d .git ]; then \
|
||||
case "$version" in \
|
||||
"" | dev | unknown) \
|
||||
echo "version is \"$version\" although the build context carries .git" >&2; \
|
||||
exit 1 ;; \
|
||||
esac; \
|
||||
fi
|
||||
|
||||
RUN make build
|
||||
|
||||
# Runtime stage
|
||||
# alpine 3.21, 2026-02-28
|
||||
|
||||
Reference in New Issue
Block a user