Improve build layer caching#428
Merged
Merged
Conversation
96a2a1d to
dfc24e6
Compare
There was a problem hiding this comment.
Pull request overview
This PR refines Docker build cache behavior in posit-bakery to avoid cache pollution by only exporting (cache-to) when builds are explicitly pushing images, and it adds zstd + OCI mediatype settings to improve cache import performance in CI.
Changes:
- Make registry cache export (
cache-to) conditional on--pushfor both direct builds and buildx bake plans. - Add
compression=zstdandoci-mediatypes=trueto cache export configuration. - Update/extend unit tests and expected bake-plan fixtures to cover both non-push and push behaviors.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
posit-bakery/posit_bakery/image/image_target.py |
Only set cache_to when push=True; add zstd + OCI mediatypes options. |
posit-bakery/posit_bakery/image/bake/bake.py |
Thread push through bake plan generation so cache-to is only included when pushing; add zstd + OCI mediatypes fields. |
posit-bakery/posit_bakery/config/config.py |
Pass push into bake-plan generation for --plan output and BAKE strategy builds. |
posit-bakery/posit_bakery/cli/build.py |
Ensure bakery build --plan reflects --push when rendering the bake plan. |
posit-bakery/test/image/test_image_target.py |
Update cache-registry build-args expectations and add a push-specific test case. |
posit-bakery/test/image/bake/test_bake.py |
Split cache-registry plan assertions into non-push vs push scenarios. |
posit-bakery/test/image/bake/testdata/cache_registry/basic_plan.json |
Update expected bake plan cache export options (zstd + OCI mediatypes). |
posit-bakery/test/image/bake/testdata/cache_registry/barebones_plan.json |
Update expected bake plan cache export options (zstd + OCI mediatypes). |
posit-bakery/test/image/bake/testdata/cache_registry/multiplatform_plan.json |
Update expected bake plan cache export options (zstd + OCI mediatypes). |
.github/workflows/bakery-build-native.yml |
Update workflow comment to reflect internal conditional cache-to behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dfc24e6 to
e1d4fc4
Compare
e1d4fc4 to
a6a97a0
Compare
Gate cache-to on the push flag so that local and PR builds read from the registry cache but never write to it. This prevents PR builds from polluting the cache with divergent layers that would be pulled by subsequent main builds. - ImageTarget.build(): only set cache_to when push=True - BakeTarget.from_image_target(): add push parameter, omit cache_to from bake JSON when not pushing - BakePlan.from_image_targets(): pass push through - bake_plan_targets() and CLI --plan: forward push flag so plan output reflects the current invocation - Replace FIXME in bakery-build-native.yml with explanation
Use zstd compression with OCI media types for registry cache exports. zstd decompresses significantly faster than the default gzip, reducing cache import time on CI runners. This invalidates all existing cache images — the first CI run after this lands will rebuild from scratch.
a6a97a0 to
a10e2b6
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
cache-to) when--pushis set. PR and local builds read from the cache but never write to it, preventing cache pollution from divergent layers.cache-tofor faster cache import on CI runners.Addresses #138.
Test plan
just testpasses (barebones suite; basic/multiplatform have pre-existingToolOptionsfailure)bakery build --plan --cache-registry ghcr.io/posit-devshowscache-frombut nocache-tobakery build --plan --push --cache-registry ghcr.io/posit-devshows bothcache-fromandcache-towith zstd compression