Keep Go's build cache between builds (closes #124)
check / check (push) Successful in 1m43s

The Dockerfile runs make test and make build with Go's build cache in a
BuildKit cache mount, so a build compiles only what changed since the
last one instead of the standard library and every dependency from
nothing. The mount has an id of its own, so builds of other repositories,
compiled against other C headers, do not share it. script/test passes
-count=1, so no test result is taken from the cache.

Model: opus-5-5
This commit is contained in:
2026-10-06 12:05:07 +00:00
parent 4ff0d20c10
commit c995ee45fb
5 changed files with 33 additions and 7 deletions
+14 -3
View File
@@ -50,15 +50,26 @@ ARG CHECK_EPOCH
COPY . .
RUN make test
# Go's build cache is kept between builds in this cache mount, which make test
# and make build both use, so each compiles only what changed since the last
# build, not the standard library and every dependency from nothing.
# script/test passes -count=1, so test results are never taken from it.
# The mount has its own id because the default id, its path, is shared with
# other repositories' builds, and Go's cache does not notice changes to C
# libraries: an entry compiled there against other C headers could be reused
# here. It does not notice a change of this image's own C headers either.
RUN --mount=type=cache,id=sneak/secret/go-build,target=/root/.cache/go-build \
make test
# The version stamped into the binary: the VERSION build argument when one
# is given, otherwise `git describe --tags --always` of the .git the build
# context carries: the tag on a tagged commit, tag-N-gHASH on a commit after
# one, the short commit when no tag is reachable. A context that carries .git
# and still yields no version fails the build.
# and still yields no version fails the build. make build uses the same Go
# build cache mount as make test.
ARG VERSION
RUN version="${VERSION:-$(git describe --tags --always)}"; \
RUN --mount=type=cache,id=sneak/secret/go-build,target=/root/.cache/go-build \
version="${VERSION:-$(git describe --tags --always)}"; \
if [ -e .git ] && { [ -z "$version" ] || [ "$version" = dev ] || \
[ "$version" = unknown ]; }; then \
echo "no version could be derived although the build context carries .git" >&2; \