Skip to content

Prune build context and optimize layer caching #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

yarlson
Copy link
Contributor

@yarlson yarlson commented Apr 21, 2025

This change adds a new .dockerignore that excludes everything by default—then whitelists only the files we actually need (/cmd, /internal, go.mod, go.sum, and Makefile). By pruning the build context like this, we send far less data to the Docker daemon on every build.

The Dockerfile itself has been refactored to make better use of Docker’s layer cache. We now copy in just go.mod and go.sum first and run go 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 single RUN instruction. 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!

@yarlson yarlson force-pushed the docker-build-cache branch from 9b7c43a to dfdc1ce Compare April 22, 2025 06:11
- Exclude non-build files from context with `.dockerignore`
- Add `go mod download` step to cache dependencies
- Switch casing on commands
@kevinmcconnell kevinmcconnell merged commit 7609c53 into basecamp:main Apr 22, 2025
@kevinmcconnell
Copy link
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants