Skip to content

Commit

Permalink
dockerfile: fix copy non-octal build tag
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tonistiigi committed Jan 3, 2025
1 parent ca25771 commit 21440de
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
24 changes: 16 additions & 8 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1565,7 +1573,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
)

opts := append([]llb.CopyOption{&llb.CopyInfo{
Mode: mode,
Mode: chopt,
CreateDestPath: true,
}}, copyOpt...)

Expand Down
2 changes: 1 addition & 1 deletion frontend/dockerfile/release/labs/tags
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dfrunsecurity dfparents dfexcludepatterns dfchmodnonoctal
dfrunsecurity dfparents dfexcludepatterns dfcopychmodnonoctal
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21440de

Please sign in to comment.