Skip to content

exporter: add local exporter mode=delete#6561

Open
crazy-max wants to merge 1 commit intomoby:masterfrom
crazy-max:exporter-local-mirror
Open

exporter: add local exporter mode=delete#6561
crazy-max wants to merge 1 commit intomoby:masterfrom
crazy-max:exporter-local-mirror

Conversation

@crazy-max
Copy link
Member

@crazy-max crazy-max commented Mar 6, 2026

partially fixes #2805

This PR adds support for a mode attribute on the local exporter output path.

The default behavior remains mode=copy, which preserves destination files that are not present in the exported result. A new mode=delete behavior is added so the destination matches the exported result by removing stale files and directories.

Because mode=delete can remove files under the destination directory, this feature is intentionally explicit opt-in and should be used only with trusted build definitions and carefully reviewed output destinations.

On client side like Buildx we should probably have some safety gate like --allow local-output-delete (or equivalent) for remote Bake invocations. Optionally block/require explicit allow when dest=. with mode=delete?

Maybe we could have some kind of scope attribute like mode=delete,delete-scope=dist,assets so it only deletes stale files under those relative paths (and reject unsafe scopes like .. or absolute paths)?

Also the backup mode from the issue is intentionally left for a follow-up change. I think we would need changes in fsutil.Receive (or diff callbacks).

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

I'd call it delete like rsync --delete. In Buildx I think we need more restrictions. I'd only allow it for subdirs there, with a second-level opt-in needed to mess with the main workdir or things outside it.

@crazy-max crazy-max changed the title exporter: add local exporter mode=mirror exporter: add local exporter mode=delete Mar 9, 2026
@crazy-max
Copy link
Member Author

I'd call it delete like rsync --delete. In Buildx I think we need more restrictions. I'd only allow it for subdirs there, with a second-level opt-in needed to mess with the main workdir or things outside it.

Agreed, renamed the mode from mirror to delete to align with rsync --delete semantics.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max crazy-max force-pushed the exporter-local-mirror branch from 22b3c81 to 80b1312 Compare March 9, 2026 09:09
@crazy-max crazy-max requested a review from tonistiigi March 9, 2026 09:19
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.

Proposal: Add mode attribute to local exporter

2 participants