Skip to content

Commit

Permalink
Handle KO_DOCKER_REPO=ko.local/repo and --bare correctly (ko-build#820)
Browse files Browse the repository at this point in the history
* Handle KO_DOCKER_REPO=ko.local/repo and --bare correctly

* support ko.local/foo for other namers too

* more robust defaulting
  • Loading branch information
imjasonh authored Oct 19, 2022
1 parent 43cdbd2 commit e03e444
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/commands/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions pkg/commands/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e03e444

Please sign in to comment.