Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that images that can’t be built are not pushed #1729

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/skaffold/build/local/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b *Builder) buildDocker(ctx context.Context, out io.Writer, workspace stri
return b.localDocker.Push(ctx, out, tag)
}

return imageID, err
return imageID, nil
}

func (b *Builder) dockerCLIBuild(ctx context.Context, out io.Writer, workspace string, a *latest.DockerArtifact, tag string) (string, error) {
Expand Down
55 changes: 43 additions & 12 deletions pkg/skaffold/build/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestLocalRun(t *testing.T) {
artifacts []*latest.Artifact
expected []build.Artifact
expectedWarnings []string
expectedPushed []string
pushImages bool
shouldErr bool
}{
Expand All @@ -69,6 +70,20 @@ func TestLocalRun(t *testing.T) {
Tag: "gcr.io/test/image:1",
}},
},
{
description: "error getting image digest",
artifacts: []*latest.Artifact{{
ImageName: "gcr.io/test/image",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{},
}},
},
tags: tag.ImageTags(map[string]string{"gcr.io/test/image": "gcr.io/test/image:tag"}),
api: testutil.FakeAPIClient{
ErrImageInspect: true,
},
shouldErr: true,
},
{
description: "single build (remote)",
artifacts: []*latest.Artifact{{
Expand All @@ -84,28 +99,42 @@ func TestLocalRun(t *testing.T) {
ImageName: "gcr.io/test/image",
Tag: "gcr.io/test/image:tag@sha256:7368613235363a31e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
}},
expectedPushed: []string{"sha256:7368613235363a31e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
},
{
description: "error image build",
artifacts: []*latest.Artifact{{}},
description: "error build",
artifacts: []*latest.Artifact{{
ImageName: "gcr.io/test/image",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{},
}},
},
tags: tag.ImageTags(map[string]string{"gcr.io/test/image": "gcr.io/test/image:tag"}),
api: testutil.FakeAPIClient{
ErrImageBuild: true,
},
shouldErr: true,
},
{
description: "unkown artifact type",
artifacts: []*latest.Artifact{{}},
shouldErr: true,
},
{
description: "error image inspect",
artifacts: []*latest.Artifact{{}},
description: "dont push on build error",
artifacts: []*latest.Artifact{{
ImageName: "gcr.io/test/image",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{},
}},
},
tags: tag.ImageTags(map[string]string{"gcr.io/test/image": "gcr.io/test/image:tag"}),
pushImages: true,
api: testutil.FakeAPIClient{
ErrImageInspect: true,
ErrImageBuild: true,
},
shouldErr: true,
},
{
description: "unkown artifact type",
artifacts: []*latest.Artifact{{}},
shouldErr: true,
},
{
description: "cache-from images already pulled",
artifacts: []*latest.Artifact{{
Expand Down Expand Up @@ -169,18 +198,19 @@ func TestLocalRun(t *testing.T) {
expectedWarnings: []string{"Cache-From image couldn't be pulled: pull1\n"},
},
{
description: "inspect error",
description: "error checking cache-from image",
artifacts: []*latest.Artifact{{
ImageName: "gcr.io/test/image",
ArtifactType: latest.ArtifactType{
DockerArtifact: &latest.DockerArtifact{
CacheFrom: []string{"pull1"},
CacheFrom: []string{"pull"},
},
}},
},
api: testutil.FakeAPIClient{
ErrImageInspect: true,
},
tags: tag.ImageTags(map[string]string{"gcr.io/test/image": "gcr.io/test/image:tag"}),
shouldErr: true,
},
}
Expand All @@ -206,6 +236,7 @@ func TestLocalRun(t *testing.T) {

testutil.CheckErrorAndDeepEqual(t, test.shouldErr, err, test.expected, res)
testutil.CheckDeepEqual(t, test.expectedWarnings, fakeWarner.Warnings)
testutil.CheckDeepEqual(t, test.expectedPushed, test.api.Pushed)
})
}
}
2 changes: 2 additions & 0 deletions testutil/fake_image_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type FakeAPIClient struct {
ErrStream bool

nextImageID int
Pushed []string
}

type errReader struct{}
Expand Down Expand Up @@ -121,6 +122,7 @@ func (f *FakeAPIClient) ImagePush(_ context.Context, ref string, _ types.ImagePu
}

digest := fmt.Sprintf("sha256:%x", sha256.New().Sum([]byte(f.TagToImageID[ref])))
f.Pushed = append(f.Pushed, digest)

return f.body(digest), nil
}
Expand Down