From 21440de2d3971abd8ac496d0ff0ea073f77a4f63 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 2 Jan 2025 10:34:51 -0800 Subject: [PATCH] dockerfile: fix copy non-octal build tag It looks like there was some switch in build tags, resulting in the feature not being enabled in the release and the test being skipped. Signed-off-by: Tonis Tiigi --- frontend/dockerfile/dockerfile2llb/convert.go | 24 ++++++++++++------- frontend/dockerfile/release/labs/tags | 2 +- go.mod | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index 934c3a338e3d..791f4d4a50ed 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -46,6 +46,7 @@ import ( digest "github.com/opencontainers/go-digest" ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" + mode "github.com/tonistiigi/dchapes-mode" "golang.org/x/sync/errgroup" ) @@ -1390,19 +1391,26 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { copyOpt = append(copyOpt, llb.WithExcludePatterns(cfg.excludePatterns)) } - var mode *llb.ChmodOpt + var chopt *llb.ChmodOpt if cfg.chmod != "" { - mode = &llb.ChmodOpt{} + chopt = &llb.ChmodOpt{} p, err := strconv.ParseUint(cfg.chmod, 8, 32) nonOctalErr := errors.Errorf("invalid chmod parameter: '%v'. it should be octal string and between 0 and 07777", cfg.chmod) if err == nil { if p > 0o7777 { return nonOctalErr } - mode.Mode = os.FileMode(p) + chopt.Mode = os.FileMode(p) } else { if featureCopyChmodNonOctalEnabled { - mode.ModeStr = cfg.chmod + if _, err := mode.Parse(cfg.chmod); err != nil { + var ne *strconv.NumError + if errors.As(err, &ne) { + return nonOctalErr // return nonOctalErr for compatibility if the value looks numeric + } + return err + } + chopt.ModeStr = cfg.chmod } else { return nonOctalErr } @@ -1467,7 +1475,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { } st := llb.Git(gitRef.Remote, commit, gitOptions...) opts := append([]llb.CopyOption{&llb.CopyInfo{ - Mode: mode, + Mode: chopt, CreateDestPath: true, }}, copyOpt...) if a == nil { @@ -1496,7 +1504,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { st := llb.HTTP(src, llb.Filename(f), llb.WithCustomName(pgName), llb.Checksum(cfg.checksum), dfCmd(cfg.params)) opts := append([]llb.CopyOption{&llb.CopyInfo{ - Mode: mode, + Mode: chopt, CreateDestPath: true, }}, copyOpt...) @@ -1532,7 +1540,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { } opts := append([]llb.CopyOption{&llb.CopyInfo{ - Mode: mode, + Mode: chopt, FollowSymlinks: true, CopyDirContentsOnly: true, IncludePatterns: patterns, @@ -1565,7 +1573,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { ) opts := append([]llb.CopyOption{&llb.CopyInfo{ - Mode: mode, + Mode: chopt, CreateDestPath: true, }}, copyOpt...) diff --git a/frontend/dockerfile/release/labs/tags b/frontend/dockerfile/release/labs/tags index c76b890a4307..1ebdc80f9956 100644 --- a/frontend/dockerfile/release/labs/tags +++ b/frontend/dockerfile/release/labs/tags @@ -1 +1 @@ -dfrunsecurity dfparents dfexcludepatterns dfchmodnonoctal +dfrunsecurity dfparents dfexcludepatterns dfcopychmodnonoctal diff --git a/go.mod b/go.mod index e62c9799e109..98c334bb1bcd 100644 --- a/go.mod +++ b/go.mod @@ -70,6 +70,7 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spdx/tools-golang v0.5.3 github.com/stretchr/testify v1.9.0 + github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205 github.com/tonistiigi/fsutil v0.0.0-20241121093142-31cf1f437184 github.com/tonistiigi/go-actions-cache v0.0.0-20241108014124-394979b8119e github.com/tonistiigi/go-archvariant v1.0.0 @@ -168,7 +169,6 @@ require ( github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect github.com/shibumi/go-pathspec v1.3.0 // indirect - github.com/tonistiigi/dchapes-mode v0.0.0-20241001053921-ca0759fec205 // indirect github.com/vbatts/tar-split v0.11.5 // indirect github.com/vishvananda/netns v0.0.4 // indirect go.opencensus.io v0.24.0 // indirect