Skip to content

Commit

Permalink
Merge pull request #5626 from tonistiigi/chmod-nonoctal-tag
Browse files Browse the repository at this point in the history
dockerfile: fix copy non-octal build tag
  • Loading branch information
AkihiroSuda authored Jan 6, 2025
2 parents 45c14e1 + 21440de commit 9744374
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 9744374

Please sign in to comment.