Skip to content

Commit

Permalink
Allow plain registries as KO_DOCKER_REPO
Browse files Browse the repository at this point in the history
This allows you to use e.g. localhost:5000 as KO_DOCKER_REPO.

Fixes ko-build#93.
  • Loading branch information
jonjohnsonjr committed Oct 1, 2019
1 parent 241d532 commit 2bb97e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions pkg/publish/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 2bb97e8

Please sign in to comment.