Repository navigation
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).
| 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.
80b1312 to
117013b
Compare
Completely forgot about multi-platform 🙈. I picked your commit adding new tests. I think |
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. |
21840d2 to
c7edd6c
Compare
9c2f3f6 to
3042d0b
Compare
| defer destRoot.Close() | ||
|
|
||
| var deletePaths []string | ||
| if err := continuityfs.Changes(ctx, destDir, stageDir, func(kind continuityfs.ChangeKind, p string, _ os.FileInfo, err error) error { |
There was a problem hiding this comment.
I'm not sure what's the improvment from the Diffcopy implementation. This still uses continuity with full path and diskwriter what also fsutil uses internally. It does use the os.Root for deletion but I think escaping file via symlink for example is no less risky than escape via remove.
Additionally, this version should be less efficient as a full download needs to happen to the staging area.
So I think to do it safely we still need updates in fsutil or a temporary custom implementation based on os.Root.
The continuity sameFile still seems to have a skip for content check if fixed timestamp is used.
c651962 to
5c0493b
Compare
tonistiigi
left a comment
There was a problem hiding this comment.
The problem seems to be controlling the behavior in case a new client sets delete against a daemon that doesn't support it. There doesn't seem to be a cap detection or alternatively this could be detected with a transfer header. Note that iiuc the new server behavior in here isn't really even related to delete at all, the difference is if the server can initialize a multi-platform result as a single transfer or not.
I think one approach could be to update:
func CopyToCaller(ctx context.Context, fs fsutil.FS, id int, c session.Caller, progress func(int, bool)) error {
method := session.MethodURL(FileSend_ServiceDesc.ServiceName, "diffcopy")
with an extra header on mode=delete and if the client side waiting on Merge:false does not see the header (on multi-platform build) then it would give up and ask for daemon upgrade.
Approved for merge. I suggest you to switch both modes to ReceiveRoot before merge. The compatibility detection can be left after rc1.
| })) | ||
| } | ||
| if !deleteMode { | ||
| return errors.WithStack(fsutil.Receive(ds.Context(), ds, dest, opt)) |
There was a problem hiding this comment.
It looks this could also use ReceiveRoot for better security now. Just with different Merge value.
Differ wouldn't matter as Merge:true means the diff runs against empty destination directory.
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
5c0493b to
73c6767
Compare
|
I will look at compatibility detection for old daemons after merging this one. |
Follow up on moby/buildkit#6561. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
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. The newmode=deletebehavior removes stale files and directories so the destination matches the exported result.The implementation uses fsutil's root-backed receive path for delete mode. The local exporter sends the complete export result through the existing filesync transport, and the client-side sync target opens the destination as an
os.Rootand receives it withfsutil.ReceiveRootandMerge=false.This keeps destination mutation scoped under the selected output directory. Stale path removal is handled by fsutil's root-backed disk writer, so symlinks or path swaps under the destination cannot redirect delete operations outside the destination root.
Multi-platform local exports are sent as one complete filesystem for delete mode. When platform splitting is enabled, the exporter builds a single platform directory filesystem containing all platform outputs before streaming it, so one platform cannot delete another platform directory during receive.
Delete mode currently requests every source file instead of using fsutil content comparison. This is intentional with the current fsutil root-backed receive implementation, because the available content diff path is not root-aware. This keeps the behavior correct, with a performance tradeoff that can be improved later in fsutil.
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.Client frontends like Buildx should add their own safety gate, such as
--allow local-output-deleteor an equivalent allow flag for remote Bake invocations. Buildx may also want stricter handling for risky destinations such asdest=.or paths outside the intended workspace.A scoped delete option may be useful as a follow-up, such as
mode=delete,delete-scope=dist,assets, with validation that rejects unsafe scopes like..or absolute paths.The
backupmode from the issue is intentionally left for a follow-up change.