exporter: add local exporter mode=delete#6561
Conversation
48e766e to
071d3cf
Compare
477e40e to
22b3c81
Compare
tonistiigi
left a comment
There was a problem hiding this comment.
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 |
22b3c81 to
80b1312
Compare
There was a problem hiding this comment.
Looks like there is problem with multi-platform outputs. Added regression test in https://github.com/moby/buildkit/compare/master...tonistiigi:buildkit:exporter-local-mirror-upt?expand=1
The way this seems to work is using the fsutil transfer in merge=false mode that is usually used for context transfer. This is good for performance as existing files are not transfered but there are a couple of problems with it:
- The differ is metadata based. This is considered ok for context transfer for performance, but not sure if that is also the case for outputs. Especially because you can have reproducible builds. This would unexpectedly create wrong output results that should be avoided. I think outputs should use differ based on content checksum.
- The differ is only safe if the output directory is immutable. If it is not then this could lead to breakouts. Using differ in here would require some refactoring. If that refactoring reduces performance then we should use different code for output and context transfer(where we can guarantee immutability).
session/filesync/filesync.go
Outdated
| if outdir, ok := sp.outdirs[id]; ok { | ||
| return syncTargetDiffCopy(stream, outdir) | ||
| mode := outdir.mode | ||
| if v := opts[keyExporterMetaPrefix+ExporterMetaLocalDirMode]; len(v) > 0 { |
There was a problem hiding this comment.
This code is used for context transfer to daemon and shouldn't allow client to control the receive behavior.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
80b1312 to
117013b
Compare
Completely forgot about multi-platform 🙈. I picked your commit adding new tests. I think |
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
117013b to
21840d2
Compare
Addressed in last commit. Now |
|
Hum test fails on Windows https://github.com/moby/buildkit/actions/runs/23750766249/job/69192263818?pr=6561#step:8:268 Seems the destination cleanup happened but the root file was not materialized back. That leaves dest partially empty. |
partially fixes #2805
This PR adds support for a
modeattribute 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 newmode=deletebehavior is added so the destination matches the exported result by removing stale files and directories.Because
mode=deletecan 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 whendest=.withmode=delete?Maybe we could have some kind of scope attribute like
mode=delete,delete-scope=dist,assetsso it only deletes stale files under those relative paths (and reject unsafe scopes like..or absolute paths)?Also the
backupmode from the issue is intentionally left for a follow-up change. I think we would need changes infsutil.Receive(or diff callbacks).