From 2bb97e861badd766c1cd68d7e51572f0d15794d9 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Tue, 1 Oct 2019 10:23:18 -0700 Subject: [PATCH] Allow plain registries as KO_DOCKER_REPO This allows you to use e.g. localhost:5000 as KO_DOCKER_REPO. Fixes #93. --- pkg/commands/resolver.go | 7 ++++--- pkg/publish/options.go | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index a7654f62e6..e06d7a8bd7 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -93,9 +93,10 @@ func makePublisher(no *options.NameOptions, lo *options.LocalOptions, ta *option if repoName == "" { return nil, errors.New("KO_DOCKER_REPO environment variable is unset") } - _, err := name.NewRepository(repoName) - if err != nil { - return nil, fmt.Errorf("failed to parse environment variable KO_DOCKER_REPO=%q as repository: %v", repoName, err) + if _, err := name.NewRegistry(repoName); err != nil { + if _, err := name.NewRepository(repoName); err != nil { + return nil, fmt.Errorf("failed to parse environment variable KO_DOCKER_REPO=%q as repository: %v", repoName, err) + } } return publish.NewDefault(repoName, diff --git a/pkg/publish/options.go b/pkg/publish/options.go index 5df8c98b22..f8f839e27b 100644 --- a/pkg/publish/options.go +++ b/pkg/publish/options.go @@ -48,11 +48,16 @@ func WithAuthFromKeychain(keys authn.Keychain) Option { // means that docker.io/mattmoor actually gets interpreted as // docker.io/library/mattmoor, which gets tricky when we start // appending things to it in the publisher. - repo, err := name.NewRepository(i.base) + reg, err := name.NewRegistry(i.base) if err != nil { - return err + // Workaround for localhost:5000 as KO_DOCKER_REPO. + repo, err := name.NewRepository(i.base) + if err != nil { + return err + } + reg = repo.Registry } - auth, err := keys.Resolve(repo.Registry) + auth, err := keys.Resolve(reg) if err != nil { return err }