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

feat: disable cache-copy-layers in multistage builds; closes 2065 #2227

Merged
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
4 changes: 4 additions & 0 deletions pkg/dockerfile/dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func ParseStages(opts *config.KanikoOptions) ([]instructions.Stage, []instructio
return nil, nil, errors.Wrap(err, "parsing dockerfile")
}

if opts.CacheCopyLayers && len(stages) >= 2 {
imjasonh marked this conversation as resolved.
Show resolved Hide resolved
return nil, nil, errors.New("kaniko does not support caching copy layers in multistage builds")
}

metaArgs, err = expandNested(metaArgs, opts.BuildArgs)
if err != nil {
return nil, nil, errors.Wrap(err, "expanding meta ARGs")
Expand Down
33 changes: 33 additions & 0 deletions pkg/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/instructions"
)

func Test_ParseStages_NoMultistageWithCacheCopy(t *testing.T) {
dockerfile := `
FROM scratch as first
COPY testfile /

FROM scratch as second
COPY --from=second testfile /
`
tmpfile, err := ioutil.TempFile("", "Dockerfile.test")
if err != nil {
t.Fatal(err)
}

defer os.Remove(tmpfile.Name())

if _, err := tmpfile.Write([]byte(dockerfile)); err != nil {
t.Fatal(err)
}
if err := tmpfile.Close(); err != nil {
t.Fatal(err)
}

opts := &config.KanikoOptions{
DockerfilePath: tmpfile.Name(),
CacheCopyLayers: true,
}

_, _, err = ParseStages(opts)
if err == nil {
t.Fatal("expected ParseStages to fail on MultiStage build if CacheCopyLayers=true")
}
}

func Test_ParseStages_ArgValueWithQuotes(t *testing.T) {
dockerfile := `
ARG IMAGE="ubuntu:16.04"
Expand Down