Skip to content

Commit

Permalink
Handle MAINTAINERS when passing --single-snapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Apr 13, 2020
1 parent 1978f1e commit 8dca848
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
4 changes: 4 additions & 0 deletions integration/dockerfiles/Dockerfile_test_maintainer
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions integration/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 11 additions & 13 deletions pkg/executor/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,16 @@ func (m *MockCommand) Name() string {
}

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
Expand All @@ -126,8 +123,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{
stage: config.KanikoStage{
Final: true,
Stage: stage,
},
cmds: cmds,
},
args: args{
index: 1,
Expand All @@ -139,11 +136,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,
},
Expand All @@ -152,8 +149,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{
stage: config.KanikoStage{
Final: false,
Stage: stage,
},
cmds: cmds,
},
args: args{
index: 0,
Expand All @@ -165,9 +162,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,
Expand All @@ -184,6 +181,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)
Expand Down

0 comments on commit 8dca848

Please sign in to comment.