From fcbcf1b4869beae0989f59bc45102793fdec87f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20Chi=E1=BA=BFn?= Date: Tue, 30 Jan 2024 01:51:58 -0800 Subject: [PATCH] Fix missing chown/chmod when using parents flag with ADD/COPY command Signed-off-by: Nobi --- frontend/dockerfile/dockerfile2llb/convert.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index a7375949e8bf..fd8cbf18ed3d 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -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 {