Skip to content

fix(ko): Default repo for pushing ko:// images #7010

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

Merged
merged 2 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions pkg/skaffold/build/ko/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import (
// identifier. The image identifier is the tag or digest for pushed images, or
// the docker image ID for sideloaded images.
func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact, ref string) (string, error) {
if b.pushImages && strings.HasPrefix(ref, build.StrictScheme) {
return "", fmt.Errorf("default repo must be set when using the 'ko://' prefix and pushing to a registry: %s, see https://skaffold.dev/docs/environment/image-registries/", a.ImageName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps this information should be on the docs page as well - eg: NOTE: the ko builder requires using the default repo flag as ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aaron-prindle, good point. I just pushed another commit to update the docs.

}
koBuilder, err := b.newKoBuilder(ctx, a)
if err != nil {
return "", fmt.Errorf("error creating ko builder: %w", err)
Expand Down
15 changes: 11 additions & 4 deletions pkg/skaffold/build/ko/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,28 @@ import (
func TestBuild(t *testing.T) {
tests := []struct {
description string
pushImages bool
imageRef string
expectedImageIdentifier string
pushImages bool
shouldErr bool
}{
{
description: "pushed image with tag",
pushImages: true,
imageRef: "registry.example.com/repo/image1:tag1",
expectedImageIdentifier: "tag1",
pushImages: true,
},
{
description: "sideloaded image",
pushImages: false,
imageRef: "registry.example.com/repo/image2:any",
expectedImageIdentifier: "ab737430e80b",
pushImages: false,
},
{
description: "error for missing default repo when using ko:// prefix combined with pushing image to a registry",
imageRef: "ko://github.com/google/ko",
pushImages: true,
shouldErr: true,
},
}
for _, test := range tests {
Expand All @@ -66,7 +73,7 @@ func TestBuild(t *testing.T) {
ImageName: importPath,
}
gotImageIdentifier, err := b.Build(context.Background(), nil, artifact, test.imageRef)
t.CheckNoError(err)
t.CheckErrorAndFailNow(test.shouldErr, err)
t.CheckDeepEqual(test.expectedImageIdentifier, gotImageIdentifier)
})
}
Expand Down