From ea2beac5751c62af0c019f60145c4bc26e094081 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Mon, 4 May 2020 09:06:55 -0700 Subject: [PATCH] Fix -P with passing ko:// through. (#163) Turns out I broke this. Thanks to @bobcatfish for reporting the issue. With this change: ``` ko resolve -Pf cmd/ko/test/test.yaml > /dev/null 2020/05/04 08:44:35 Using base gcr.io/distroless/static:nonroot for github.com/google/ko/cmd/ko/test 2020/05/04 08:44:36 Building github.com/google/ko/cmd/ko/test 2020/05/04 08:44:37 Publishing gcr.io/mattmoor-knative/github.com/google/ko/cmd/ko/test:latest 2020/05/04 08:44:39 Published gcr.io/mattmoor-knative/github.com/google/ko/cmd/ko/test@sha256:ee655510172b429dbce619fc69677621d71cb824cbbf2a21746d700127257ec4 ``` I can cut v0.5.1 once this lands. --- pkg/publish/default.go | 2 ++ pkg/publish/default_test.go | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/publish/default.go b/pkg/publish/default.go index 23604b00a6..985b50001c 100644 --- a/pkg/publish/default.go +++ b/pkg/publish/default.go @@ -24,6 +24,7 @@ import ( "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/remote" + "github.com/google/ko/pkg/build" ) // defalt is intentionally misspelled to avoid keyword collision (and drive Jon nuts). @@ -95,6 +96,7 @@ func NewDefault(base string, options ...Option) (Interface, error) { // Publish implements publish.Interface func (d *defalt) Publish(img v1.Image, s string) (name.Reference, error) { + s = strings.TrimPrefix(s, build.StrictScheme) // https://github.com/google/go-containerregistry/issues/212 s = strings.ToLower(s) diff --git a/pkg/publish/default_test.go b/pkg/publish/default_test.go index aa98c59833..e941b25af9 100644 --- a/pkg/publish/default_test.go +++ b/pkg/publish/default_test.go @@ -26,6 +26,7 @@ import ( "github.com/google/go-containerregistry/pkg/name" "github.com/google/go-containerregistry/pkg/v1/random" + "github.com/google/ko/pkg/build" ) func TestDefault(t *testing.T) { @@ -77,7 +78,7 @@ func TestDefault(t *testing.T) { if err != nil { t.Errorf("NewDefault() = %v", err) } - if d, err := def.Publish(img, importpath); err != nil { + if d, err := def.Publish(img, build.StrictScheme+importpath); err != nil { t.Errorf("Publish() = %v", err) } else if !strings.HasPrefix(d.String(), tag.Repository.String()) { t.Errorf("Publish() = %v, wanted prefix %v", d, tag.Repository) @@ -141,7 +142,7 @@ func TestDefaultWithCustomNamer(t *testing.T) { if err != nil { t.Errorf("NewDefault() = %v", err) } - if d, err := def.Publish(img, importpath); err != nil { + if d, err := def.Publish(img, build.StrictScheme+importpath); err != nil { t.Errorf("Publish() = %v", err) } else if !strings.HasPrefix(d.String(), repoName) { t.Errorf("Publish() = %v, wanted prefix %v", d, tag.Repository) @@ -205,7 +206,7 @@ func TestDefaultWithTags(t *testing.T) { if err != nil { t.Errorf("NewDefault() = %v", err) } - if d, err := def.Publish(img, importpath); err != nil { + if d, err := def.Publish(img, build.StrictScheme+importpath); err != nil { t.Errorf("Publish() = %v", err) } else if !strings.HasPrefix(d.String(), repoName) { t.Errorf("Publish() = %v, wanted prefix %v", d, tag.Repository) @@ -278,7 +279,7 @@ func TestDefaultWithReleaseTag(t *testing.T) { if err != nil { t.Errorf("NewDefault() = %v", err) } - if d, err := def.Publish(img, importpath); err != nil { + if d, err := def.Publish(img, build.StrictScheme+importpath); err != nil { t.Errorf("Publish() = %v", err) } else if !strings.HasPrefix(d.String(), repoName) { t.Errorf("Publish() = %v, wanted prefix %v", d, tag.Repository)