Merge pull request #1192 from tp-tc/snapshot-maintainers

Handle `MAINTAINERS` when passing `--single-snapshot`.
This commit is contained in:
Tejal Desai 2020-05-03 20:45:48 -07:00 committed by GitHub
commit a2af3272cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 // Arguments to build Dockerfiles with when building with kaniko
var additionalKanikoFlagsMap = map[string][]string{ var additionalKanikoFlagsMap = map[string][]string{
"Dockerfile_test_add": {"--single-snapshot"}, "Dockerfile_test_add": {"--single-snapshot"},
"Dockerfile_test_scratch": {"--single-snapshot"}, "Dockerfile_test_scratch": {"--single-snapshot"},
"Dockerfile_test_target": {"--target=second"}, "Dockerfile_test_maintainer": {"--single-snapshot"},
"Dockerfile_test_target": {"--target=second"},
} }
// output check to do when building with kaniko // output check to do when building with kaniko

View File

@ -424,7 +424,7 @@ func (s *stageBuilder) takeSnapshot(files []string) (string, error) {
} }
func (s *stageBuilder) shouldTakeSnapshot(index int, files []string) bool { 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. // We only snapshot the very end with single snapshot mode on.
if s.opts.SingleSnapshot { if s.opts.SingleSnapshot {

View File

@ -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) { func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
commands := []instructions.Command{ cmds := []commands.DockerCommand{
&MockCommand{name: "command1"}, &MockDockerCommand{command: "command1"},
&MockCommand{name: "command2"}, &MockDockerCommand{command: "command2"},
&MockCommand{name: "command3"}, &MockDockerCommand{command: "command3"},
}
stage := instructions.Stage{
Commands: commands,
} }
type fields struct { type fields struct {
stage config.KanikoStage stage config.KanikoStage
opts *config.KanikoOptions opts *config.KanikoOptions
cmds []commands.DockerCommand
} }
type args struct { type args struct {
index int index int
@ -128,8 +117,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{ fields: fields{
stage: config.KanikoStage{ stage: config.KanikoStage{
Final: true, Final: true,
Stage: stage,
}, },
cmds: cmds,
}, },
args: args{ args: args{
index: 1, index: 1,
@ -141,11 +130,11 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{ fields: fields{
stage: config.KanikoStage{ stage: config.KanikoStage{
Final: false, Final: false,
Stage: stage,
}, },
cmds: cmds,
}, },
args: args{ args: args{
index: len(commands) - 1, index: len(cmds) - 1,
}, },
want: true, want: true,
}, },
@ -154,8 +143,8 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{ fields: fields{
stage: config.KanikoStage{ stage: config.KanikoStage{
Final: false, Final: false,
Stage: stage,
}, },
cmds: cmds,
}, },
args: args{ args: args{
index: 0, index: 0,
@ -167,9 +156,9 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
fields: fields{ fields: fields{
stage: config.KanikoStage{ stage: config.KanikoStage{
Final: false, Final: false,
Stage: stage,
}, },
opts: &config.KanikoOptions{Cache: true}, opts: &config.KanikoOptions{Cache: true},
cmds: cmds,
}, },
args: args{ args: args{
index: 0, index: 0,
@ -186,6 +175,7 @@ func Test_stageBuilder_shouldTakeSnapshot(t *testing.T) {
s := &stageBuilder{ s := &stageBuilder{
stage: tt.fields.stage, stage: tt.fields.stage,
opts: tt.fields.opts, opts: tt.fields.opts,
cmds: tt.fields.cmds,
} }
if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files); got != tt.want { if got := s.shouldTakeSnapshot(tt.args.index, tt.args.files); got != tt.want {
t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want) t.Errorf("stageBuilder.shouldTakeSnapshot() = %v, want %v", got, tt.want)