Improve support for third-party registry images

Update `ReferenceExpand` to support image references from remote
registries. This fixes local image lookup and pulling with newer
versions of Docker.

fixes #4045

Signed-off-by: Jameel Al-Aziz <jameel@bastion.io>
This commit is contained in:
Jameel Al-Aziz 2024-06-18 21:40:37 -07:00
parent 4f89f4f67e
commit 5e42d050a7
No known key found for this signature in database
GPG Key ID: 9E37044CFFF3FDB4

View File

@ -32,8 +32,13 @@ func ReferenceExpand(ref string, options ...ReferenceOption) string {
case 1:
ret = "docker.io/library/" + ref
case 2:
// If the first part is not a domain, assume it is a DockerHub user/org.
// This logic is copied from moby:
// https://github.com/moby/moby/blob/e7347f8a8c2fd3d2abd34b638d6fc8c18b0278d1/registry/search.go#L148C29-L149C71
if !strings.Contains(parts[0], ".") && !strings.Contains(parts[0], ":") && parts[0] != "localhost" {
ret = "docker.io/" + ref
}
}
if opts.withTag && !strings.Contains(ret, ":") {
ret += ":latest"