Skip to content

Commit

Permalink
Fix missing chown/chmod when using parents flag with ADD/COPY command
Browse files Browse the repository at this point in the history
Signed-off-by: Nobi <[email protected]>
  • Loading branch information
nobiit committed Jan 31, 2024
1 parent ef61ad1 commit aeea2aa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
16 changes: 8 additions & 8 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,24 +1219,24 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
return errors.Wrap(err, "removing drive letter")
}

var patterns []string
if cfg.parents {
path := strings.TrimPrefix(src, "/")
patterns = []string{path}
src = "/"
}

opts := append([]llb.CopyOption{&llb.CopyInfo{
Mode: mode,
FollowSymlinks: true,
CopyDirContentsOnly: true,
IncludePatterns: patterns,
AttemptUnpack: cfg.isAddCommand,
CreateDestPath: true,
AllowWildcard: true,
AllowEmptyWildcard: true,
}}, copyOpt...)

if cfg.parents {
path := strings.TrimPrefix(src, "/")
opts = append(opts, &llb.CopyInfo{
IncludePatterns: []string{path},
})
src = "/"
}

if a == nil {
a = llb.Copy(cfg.source, src, dest, opts...)
} else {
Expand Down
37 changes: 37 additions & 0 deletions patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/dockerfile/dockerfile2llb/convert.go b/dockerfile/dockerfile2llb/convert.go
index eca634b..f64ab2b 100644
--- a/frontend/dockerfile/dockerfile2llb/convert.go
+++ b/frontend/dockerfile/dockerfile2llb/convert.go
@@ -1218,24 +1218,24 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
return errors.Wrap(err, "removing drive letter")
}

+ var patterns []string
+ if cfg.parents {
+ path := strings.TrimPrefix(src, "/")
+ patterns = []string{path}
+ src = "/"
+ }
+
opts := append([]llb.CopyOption{&llb.CopyInfo{
Mode: mode,
FollowSymlinks: true,
CopyDirContentsOnly: true,
+ IncludePatterns: patterns,
AttemptUnpack: cfg.isAddCommand,
CreateDestPath: true,
AllowWildcard: true,
AllowEmptyWildcard: true,
}}, copyOpt...)

- if cfg.parents {
- path := strings.TrimPrefix(src, "/")
- opts = append(opts, &llb.CopyInfo{
- IncludePatterns: []string{path},
- })
- src = "/"
- }
-
if a == nil {
a = llb.Copy(cfg.source, src, dest, opts...)
} else {

0 comments on commit aeea2aa

Please sign in to comment.