Keep configured Dockerfiles outside build context#307
Open
IlyaasK wants to merge 2 commits into
Open
Conversation
Extract the initial buildctl arguments and assert configured Dockerfiles use a different local directory from the source context, preventing the cache regression from returning unnoticed.
a8f78c1 to
9a5a202
Compare
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.
summary
why
Writing a generated Dockerfile into the source directory changes the build context. When that Dockerfile contains per-deploy values,
COPY .sees a different context on every build and cannot reuse its cached layer. Keeping the Dockerfile frontend input separate leaves identical source contexts identical across repeated builds.tests
go test ./lib/builds/builder_agentgo test -race ./lib/builds/builder_agentgo vet ./lib/builds/builder_agentgo test ./lib/builds/...could not initialize in a plain checkout because the embedded Cloud Hypervisor and guest-agent binaries had not been builtNote
Low Risk
Isolated builder-agent Dockerfile handling with tests; behavior for in-archive Dockerfiles is preserved.
Overview
Config-supplied Dockerfiles are no longer written into the source tree.
prepareDockerfileputs them in a temp directory (with cleanup), while archives that already include aDockerfilestill use the source path unchanged.runBuildnow takes a separatedockerfileDirandbaseBuildctlArgspasses--local dockerfile=independently from--local context=(source), so BuildKit’s Dockerfile input does not alter whatCOPY .sees—improving layer cache reuse when the generated Dockerfile varies per deploy.Regression tests cover buildctl arg separation, temp-dir vs source Dockerfile paths, source precedence over config, and the missing-Dockerfile error.
Reviewed by Cursor Bugbot for commit 9a5a202. Bugbot is set up for automated code reviews on this repo. Configure here.