Dockerfile: cache Go module + build cache to speed up go build - #27
Merged
Conversation
Add BuildKit --mount=type=cache for the Go module cache (/go/pkg/mod) and the build cache (/root/.cache/go-build) on go mod download and go build. GOCACHE and GOMODCACHE are pinned via ENV so the mount targets match Go's cache dirs exactly, regardless of the builder image's HOME/GOPATH. The caches persist on the BuildKit daemon across builds, so on the persistent remote builder only changed packages recompile and only new modules download. Cache mounts are build-time only; the final image is unchanged. Same change as apiserver. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UujJC8ThyuTr9EwZjnwcox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Speed up the slow part of the image build (
go build) by persisting Go's caches across builds with BuildKit cache mounts:GOCACHE/GOMODCACHEare pinned viaENVso the mount targets match Go's cache dirs exactly (no dependence on the builder image's HOME/GOPATH).Why now
Cache mounts live on the BuildKit daemon. On the persistent remote BuildKit they survive across CI runs, so only changed packages recompile and only new modules download. Build-time only — the final image is unchanged. Same change as apiserver#214; part of a workspace-wide rollout.
Note
The paths assume the
public/builderimage's build user is root (matches the officialgolanglayout; noUSERdirective). If it runs non-root the first build fails loudly withpermission denied— no latent risk. It's the same builder image across these repos, so confirming once covers them all.🤖 Generated with Claude Code
https://claude.ai/code/session_01UujJC8ThyuTr9EwZjnwcox