diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 6c053e2fbe..2a85808e4e 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -168,10 +168,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) {