Skip to content

client: add reset option for local cache exporter#6612

Open
jirimoravcik wants to merge 1 commit intomoby:masterfrom
jirimoravcik:feat-add-local-cache-reset
Open

client: add reset option for local cache exporter#6612
jirimoravcik wants to merge 1 commit intomoby:masterfrom
jirimoravcik:feat-add-local-cache-reset

Conversation

@jirimoravcik
Copy link
Copy Markdown
Contributor

@jirimoravcik jirimoravcik commented Mar 25, 2026

Add reset=true attribute to the local cache exporter that removes unreferenced blobs from the cache directory after export, preventing unbounded growth.

The logic is very simple:

  1. Go through the index.json to get all the referenced manifests or indexes
  2. Create a set of referenced blobs (check each referenced manifest or index, works recursively as well)
  3. Walk all the blobs in the cache directory, if there's a blob that is not referenced by any manifest, flag it for deletion
  4. Delete all blobs flagged for deletion

I think cleanup could also work as the attribute name.

Resolves #1896

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

Adds a reset=true option to the local cache exporter so exported cache directories can be cleaned up (unreferenced blobs removed) after export, preventing unbounded growth. This fits into the client-side cache export flow that already updates the local index.json after a solve.

Changes:

  • Parse a new reset attribute for type=local cache exports and trigger a post-export cleanup.
  • Implement resetCacheStore to compute referenced blobs from index.json and delete unreferenced blobs.
  • Add unit + integration tests and document the new option in README.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
client/solve.go Parses reset attr, tracks stores to reset, and implements blob cleanup after export.
client/solve_resetcache_test.go Unit tests for resetCacheStore behavior (currently image-manifest oriented).
client/client_test.go Integration test for reset=true behavior with local cache export.
README.md Documents the new reset=<true|false> option for local cache exporter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jirimoravcik
Copy link
Copy Markdown
Contributor Author

Fixed the lint, other errors seem to be 50x responses from DockerHub API.

client/solve.go Outdated

referenced := make(map[digest.Digest]struct{})

for _, manifestDesc := range index.Manifests {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should use images.Dispatch for walking the descriptors instead of handwritten logic.

Also makes sure it works with image-manifest=false case that has nested indexes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @tonistiigi, thanks for the review.

I've updated the code to use images.Dispatch.
I also did a deep dive into the codebase and fixed the logic for image-manifest=false, which can have nested indexes, now the logic is recursive (which is handled nicely by images.Dispatch.
Using images.IsIndexType and images.IsManifestType to determine the type - that should be future-proof.

I also added more tests that cover nested indexes and Docker media types.

Let me know if there's anything else to fix or improve

Add `reset=true` attribute to the local cache exporter that removes
unreferenced blobs from the cache directory after export, preventing
unbounded growth.

Signed-off-by: Jiří Moravčík <jiri.moravcik@gmail.com>
@jirimoravcik jirimoravcik force-pushed the feat-add-local-cache-reset branch from 20a5427 to 195fa8e Compare April 11, 2026 21:33
@jirimoravcik jirimoravcik requested a review from tonistiigi April 11, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add cache cleanup option to local cache exporter

3 participants