Prune build context and optimize layer caching#129
Merged
kevinmcconnell merged 1 commit intobasecamp:mainfrom Apr 22, 2025
Merged
Prune build context and optimize layer caching#129kevinmcconnell merged 1 commit intobasecamp:mainfrom
kevinmcconnell merged 1 commit intobasecamp:mainfrom
Conversation
9b7c43a to
dfdc1ce
Compare
- Exclude non-build files from context with `.dockerignore` - Add `go mod download` step to cache dependencies - Switch casing on commands
dfdc1ce to
e9d8068
Compare
Collaborator
|
Thanks @yarlson, this looks good! I edited your commit message a bit, just to match the style we tend to use in the project (no category prefixes; first line <= 50 chars) |
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.
This change adds a new
.dockerignorethat excludes everything by default—then whitelists only the files we actually need (/cmd,/internal,go.mod,go.sum, andMakefile). By pruning the build context like this, we send far less data to the Docker daemon on every build.The
Dockerfileitself has been refactored to make better use of Docker’s layer cache. We now copy in justgo.modandgo.sumfirst and rungo mod download, so your dependencies stay cached unless they actually change. The rest of the source code is copied afterward, and we’ve consolidated the user setup, directory creation, and permission adjustments into a singleRUNinstruction. All Docker keywords are properly capitalized and blank lines separate logical stages, with no inline comments to keep things tidy.Together, these tweaks deliver much faster rebuilds (especially in CI), smaller contexts (lower I/O), and a cleaner, more maintainable Dockerfile. Let me know if you’d like any further refinements!