mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-18 17:01:07 +00:00
Merge pull request #4046 from jalaziz/4045
Improve support for third-party registry images
This commit is contained in:
commit
be7dfdd42c
@ -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"
|
||||
|
59
src/cmd/linuxkit/util/reference_test.go
Normal file
59
src/cmd/linuxkit/util/reference_test.go
Normal file
@ -0,0 +1,59 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestReferenceExpand(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ref string
|
||||
options []ReferenceOption
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"basic image name should expand to docker.io/library image",
|
||||
"redis",
|
||||
nil,
|
||||
"docker.io/library/redis",
|
||||
},
|
||||
{
|
||||
"image name with user/org should expand to docker.io image",
|
||||
"foo/bar",
|
||||
nil,
|
||||
"docker.io/foo/bar",
|
||||
},
|
||||
{
|
||||
"custom registry image name should not expand",
|
||||
"myregistry.io/foo",
|
||||
nil,
|
||||
"myregistry.io/foo",
|
||||
},
|
||||
{
|
||||
"image name with more than three parts should not expand",
|
||||
"foo/bar/baz",
|
||||
nil,
|
||||
"foo/bar/baz",
|
||||
},
|
||||
{
|
||||
"with tag should add latest if image does not have tag",
|
||||
"redis",
|
||||
[]ReferenceOption{ReferenceWithTag()},
|
||||
"docker.io/library/redis:latest",
|
||||
},
|
||||
{
|
||||
"with tag should not add latest if image already has tag",
|
||||
"redis:alpine",
|
||||
[]ReferenceOption{ReferenceWithTag()},
|
||||
"docker.io/library/redis:alpine",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := ReferenceExpand(tt.ref, tt.options...)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user