Handle KO_DOCKER_REPO=ko.local/repo and --bare correctly#820
Conversation
|
🥳 |
| repoName := po.DockerRepo | ||
| namer := options.MakeNamer(po) | ||
| if strings.HasPrefix(repoName, publish.LocalDomain) || po.Local { | ||
| if po.LocalDomain == "" { |
There was a problem hiding this comment.
Can't you bake this logic in the namer instead ?
There was a problem hiding this comment.
I don't think so, at least not without changing how namers are specified today.
Namers take in the base and importpath, and use them to construct the final image. If they're only passed publish.LocalDomain and the importpath github.com/foo/bar, they don't have the information necessary to construct ko.local/foo/github.com/foo/bar -- they don't know about the first foo component.
We could change the interface so they take a third argument, which we'd append together in the end, but then we'd just have to parse it out of KO_DOCKER_REPO anyway to get it, so we might as well pass it directly through and append them both together and not change the interface.
There was a problem hiding this comment.
I was thinking about something like this:
func bareDockerRepo(po *PublishOptions) func(string, string) string {
return func(base, _ string) string {
if po.LocalDomain != "" {
return po.LocalDomain
}
return base
}
}
func MakeNamer(po *PublishOptions) publish.Namer {
if po.ImageNamer != nil {
return po.ImageNamer
} else if po.PreserveImportPaths {
return preserveImportPath
} else if po.BaseImportPaths {
return baseImportPaths
} else if po.Bare {
return bareDockerRepo(po)
}
return packageWithMD5
}
Not the real logic but you get the idea, bareDockerRepo acts as a namer factory taking PublishOptions arg...
There was a problem hiding this comment.
But I might be completely wrong, first time I look at the code ;-)
There was a problem hiding this comment.
Yeah, that works too. That's more or less how I meant changing the interface. We could do that for all the namers, or we could just pass through the actual local domain that was specified, instead of only the ko.local portion.
As part of this we'll also want to support cases where the local domain is configurable by clients using ko as a library, so that if they configure the local domain to be skaffold.local or whatever, then skaffold.local/foo will also work as expected. I don't know if that's something they plan to support, but it would be nice to be consistent.
There was a problem hiding this comment.
I guess the main point is to have the naming logic written at a single place so that it can be reused in different parts of the code that need it (I had the feeling it was the responsibility of the namer).
Anyway, it can be changed later if necessary.
|
it would be good to release ko v0.13.0 that includes that fix ☝️ |
Fixes #807
cc @developer-guy
See comments in #807 (comment) -- uniformly setting
base: po.LocalDomaininNewDaemonwas fine when we assumed/required thatKO_DOCKER_REPO=ko.localwould only be used without a repo, but we've since changed that assumption/requirement.Note that this also handles
ko.local/foofor other namers: