diff --git a/integration/dockerfiles/Dockerfile_test_maintainer b/integration/dockerfiles/Dockerfile_test_maintainer new file mode 100644 index 000000000..ae44c4265 --- /dev/null +++ b/integration/dockerfiles/Dockerfile_test_maintainer @@ -0,0 +1,4 @@ +FROM scratch +MAINTAINER nobody@domain.test +# Add a file to the image to work around https://github.com/moby/moby/issues/38039 +COPY context/foo /foo diff --git a/integration/images.go b/integration/images.go index e6af511fc..bb254f110 100644 --- a/integration/images.go +++ b/integration/images.go @@ -73,9 +73,10 @@ var additionalDockerFlagsMap = map[string][]string{ // Arguments to build Dockerfiles with when building with kaniko var additionalKanikoFlagsMap = map[string][]string{ - "Dockerfile_test_add": {"--single-snapshot"}, - "Dockerfile_test_scratch": {"--single-snapshot"}, - "Dockerfile_test_target": {"--target=second"}, + "Dockerfile_test_add": {"--single-snapshot"}, + "Dockerfile_test_scratch": {"--single-snapshot"}, + "Dockerfile_test_maintainer": {"--single-snapshot"}, + "Dockerfile_test_target": {"--target=second"}, } // output check to do when building with kaniko diff --git a/pkg/executor/build.go b/pkg/executor/build.go index 25237ae8e..cce78b3a8 100644 --- a/pkg/executor/build.go +++ b/pkg/executor/build.go @@ -424,7 +424,7 @@ func (s *stageBuilder) takeSnapshot(files []string) (string, error) { } func (s *stageBuilder) shouldTakeSnapshot(index int, files []string) bool { - isLastCommand := index == len(s.stage.Commands)-1 + isLastCommand := index == len(s.cmds)-1 // We only snapshot the very end with single snapshot mode on. if s.opts.SingleSnapshot { diff --git a/pkg/executor/build_test.go b/pkg/executor/build_test.go index ff97aa03e..f3d4f363b 100644 --- a/pkg/executor/build_test.go +++ b/pkg/executor/build_test.go @@ -90,28 +90,17 @@ func stage(t *testing.T, d string) config.KanikoStage { } } -type MockCommand struct { - name string -} - -func (m *MockCommand) Name() string { - return m.name -} - func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { - commands := []instructions.Command{ - &MockCommand{name: "command1"}, - &MockCommand{name: "command2"}, - &MockCommand{name: "command3"}, - } - - stage := instructions.Stage{ - Commands: commands, + cmds := []commands.DockerCommand{ + &MockDockerCommand{command: "command1"}, + &MockDockerCommand{command: "command2"}, + &MockDockerCommand{command: "command3"}, } type fields struct { stage config.KanikoStage opts *config.KanikoOptions + cmds []commands.DockerCommand } type args struct { index int @@ -128,8 +117,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { fields: fields{ stage: config.KanikoStage{ Final: true, - Stage: stage, }, + cmds: cmds, }, args: args{ index: 1, @@ -141,11 +130,11 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { fields: fields{ stage: config.KanikoStage{ Final: false, - Stage: stage, }, + cmds: cmds, }, args: args{ - index: len(commands) - 1, + index: len(cmds) - 1, }, want: true, }, @@ -154,8 +143,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { fields: fields{ stage: config.KanikoStage{ Final: false, - Stage: stage, }, + cmds: cmds, }, args: args{ index: 0, @@ -167,9 +156,9 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { fields: fields{ stage: config.KanikoStage{ Final: false, - Stage: stage, }, opts: &config.KanikoOptions{Cache: true}, + cmds: cmds, }, args: args{ index: 0, @@ -186,6 +175,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) { s := &stageBuilder{ stage: tt.fields.stage, opts: tt.fields.opts, + cmds: tt.fields.cmds, } if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files); got != tt.want { t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want)