Handle `MAINTAINERS` when passing `--single-snapshot`.

This commit is contained in:
Tom Prince 2020-04-13 15:54:27 -06:00
parent 1978f1e08e
commit 484d03550c
4 changed files with 20 additions and 25 deletions

View File

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

View File

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

View File

@ -415,7 +415,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 {

View File

@ -88,28 +88,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
@ -126,8 +115,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{
stage: config.KanikoStage{
Final: true,
Stage: stage,
},
cmds: cmds,
},
args: args{
index: 1,
@ -139,11 +128,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,
},
@ -152,8 +141,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{
stage: config.KanikoStage{
Final: false,
Stage: stage,
},
cmds: cmds,
},
args: args{
index: 0,
@ -165,9 +154,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,
@ -184,6 +173,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)