Skip to content

Improve build layer caching#428

Merged
bschwedler merged 2 commits into
mainfrom
layer-caching-improvements
Apr 8, 2026
Merged

Improve build layer caching#428
bschwedler merged 2 commits into
mainfrom
layer-caching-improvements

Conversation

@bschwedler
Copy link
Copy Markdown
Contributor

Summary

  • Only write to the build cache (cache-to) when --push is set. PR and local builds read from the cache but never write to it, preventing cache pollution from divergent layers.
  • Add zstd compression with OCI media types to cache-to for faster cache import on CI runners.

Addresses #138.

Test plan

  • just test passes (barebones suite; basic/multiplatform have pre-existing ToolOptions failure)
  • bakery build --plan --cache-registry ghcr.io/posit-dev shows cache-from but no cache-to
  • bakery build --plan --push --cache-registry ghcr.io/posit-dev shows both cache-from and cache-to with zstd compression
  • CI builds on main push to cache; PR builds do not

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 7, 2026

Test Results

1 268 tests  +4   1 268 ✅ +4   8m 39s ⏱️ -26s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit a10e2b6. ± Comparison against base commit 86320f4.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 --push for both direct builds and buildx bake plans.
  • Add compression=zstd and oci-mediatypes=true to 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.

Comment thread posit-bakery/posit_bakery/config/config.py Outdated
@bschwedler bschwedler force-pushed the layer-caching-improvements branch from dfc24e6 to e1d4fc4 Compare April 7, 2026 15:49
Copy link
Copy Markdown
Contributor

@ianpittwood ianpittwood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bschwedler bschwedler force-pushed the layer-caching-improvements branch from e1d4fc4 to a6a97a0 Compare April 8, 2026 13:22
@bschwedler bschwedler enabled auto-merge April 8, 2026 13:23
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.
@ianpittwood ianpittwood force-pushed the layer-caching-improvements branch from a6a97a0 to a10e2b6 Compare April 8, 2026 20:56
@bschwedler bschwedler added this pull request to the merge queue Apr 8, 2026
Merged via the queue into main with commit 9e8e2db Apr 8, 2026
16 checks passed
@bschwedler bschwedler deleted the layer-caching-improvements branch April 8, 2026 21:17
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.

3 participants