From 7dfc0c667153ab91ecf916bb74380717a5b6da2f Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Mon, 12 Sep 2022 09:03:37 -0400 Subject: [PATCH 1/3] Handle KO_DOCKER_REPO=ko.local/repo and --bare correctly --- pkg/commands/resolver.go | 8 +++++++- pkg/commands/resolver_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 6c053e2fbe..bfc8728739 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -168,10 +168,16 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) { innerPublisher, err := func() (publish.Interface, error) { repoName := po.DockerRepo namer := options.MakeNamer(po) - if strings.HasPrefix(repoName, publish.LocalDomain) || po.Local { + if po.LocalDomain == "" { + po.LocalDomain = publish.LocalDomain + } + if strings.HasPrefix(repoName, po.LocalDomain) || po.Local { // TODO(jonjohnsonjr): I'm assuming that nobody will // use local with other publishers, but that might // not be true. + if po.Bare { + po.LocalDomain = repoName + } return publish.NewDaemon(namer, po.Tags, publish.WithDockerClient(po.DockerClient), publish.WithLocalDomain(po.LocalDomain), diff --git a/pkg/commands/resolver_test.go b/pkg/commands/resolver_test.go index 21d2d5d610..7031f0669c 100644 --- a/pkg/commands/resolver_test.go +++ b/pkg/commands/resolver_test.go @@ -279,6 +279,15 @@ func TestNewPublisherCanPublish(t *testing.T) { shouldError: true, wantError: errImageLoad, }, + { + description: "bare with local domain and repo", + wantImageName: strings.ToLower(fmt.Sprintf("%s/foo", dockerRepo)), + po: &options.PublishOptions{ + DockerRepo: dockerRepo + "/foo", + Local: true, + Bare: true, + }, + }, } for _, test := range tests { t.Run(test.description, func(t *testing.T) { From 271d63f5d8210d48e70270f670c8bf1bf318e510 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Mon, 12 Sep 2022 10:42:17 -0400 Subject: [PATCH 2/3] support ko.local/foo for other namers too --- pkg/commands/resolver.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index bfc8728739..19618c7230 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -175,9 +175,7 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) { // TODO(jonjohnsonjr): I'm assuming that nobody will // use local with other publishers, but that might // not be true. - if po.Bare { - po.LocalDomain = repoName - } + po.LocalDomain = repoName return publish.NewDaemon(namer, po.Tags, publish.WithDockerClient(po.DockerClient), publish.WithLocalDomain(po.LocalDomain), From eee963989b5a4e31f8aa5b273c568c033c4a7653 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Mon, 12 Sep 2022 10:55:57 -0400 Subject: [PATCH 3/3] more robust defaulting --- pkg/commands/resolver.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 19618c7230..2a85808e4e 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -168,10 +168,17 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) { innerPublisher, err := func() (publish.Interface, error) { repoName := po.DockerRepo namer := options.MakeNamer(po) + // Default LocalDomain if unset. if po.LocalDomain == "" { po.LocalDomain = publish.LocalDomain } - if strings.HasPrefix(repoName, po.LocalDomain) || po.Local { + // If repoName is unset with --local, default it to the local domain. + if po.Local && repoName == "" { + repoName = po.LocalDomain + } + // When in doubt, if repoName is under the local domain, default to --local. + po.Local = strings.HasPrefix(repoName, po.LocalDomain) + if po.Local { // TODO(jonjohnsonjr): I'm assuming that nobody will // use local with other publishers, but that might // not be true.