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 2, 2025
1 parent ca25771 commit 8c8418a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 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

0 comments on commit 8c8418a

Please sign in to comment.