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

This commit is contained in:
dmr 2022-08-25 18:36:56 -07:00 committed by GitHub
parent 06866c0b4c
commit 239d16cd1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -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 {
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")

View File

@ -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"