From e03e4448befcbeb08d71c0bf89b72c6256ec7d02 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Wed, 19 Oct 2022 16:16:37 -0400 Subject: [PATCH] Handle KO_DOCKER_REPO=ko.local/repo and --bare correctly (#820) * Handle KO_DOCKER_REPO=ko.local/repo and --bare correctly * support ko.local/foo for other namers too * more robust defaulting --- pkg/commands/resolver.go | 13 ++++++++++++- pkg/commands/resolver_test.go | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 9f47d3e220..2b341c7d62 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -172,10 +172,21 @@ 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 { + // Default LocalDomain if unset. + if po.LocalDomain == "" { + po.LocalDomain = publish.LocalDomain + } + // 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. + 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) {