Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dockerfile: fix copy non-octal build tag #5626

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading