Skip to content

Commit 02fb16c

Browse files
committed
fix(repository): ensure we parse docker.io repos correctly
1 parent cc3b49a commit 02fb16c

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

repository/repository.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var validRefExprs = map[string]*regexp.Regexp{
3737
}
3838

3939
const defaultRegistry = "registry.hub.docker.com"
40+
const fakeRegistry = "docker.io"
4041

4142
// Repository is a parsed, valid Docker repository reference
4243
type Repository struct {
@@ -86,6 +87,10 @@ func (r *Repository) Path() string {
8687
return "library/" + path
8788
}
8889

90+
if strings.HasPrefix(path, fakeRegistry+"/") {
91+
return strings.TrimPrefix(path, fakeRegistry+"/")
92+
}
93+
8994
return path
9095
}
9196

@@ -220,6 +225,10 @@ func GetRegistry(ref string) string {
220225
registry := strings.Split(ref, "/")[0]
221226

222227
if isHostname(registry) {
228+
if registry == fakeRegistry {
229+
return defaultRegistry
230+
}
231+
223232
return registry
224233
}
225234

@@ -269,7 +278,7 @@ func ParseRef(ref string) (*Repository, error) {
269278
fullRepo = refParts[0]
270279
filterRE = regexp.MustCompile(refParts[1][1 : len(refParts[1])-1])
271280
default:
272-
return nil, fmt.Errorf("unknown repository reference specification: %s", spec)
281+
return nil, fmt.Errorf("unknown repository reference specification: %s", spec)
273282
}
274283

275284
return &Repository{

repository/repository_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ func TestParseRef(t *testing.T) {
2121
}
2222

2323
var testCases = map[string]expectation{
24-
"alpine": {"registry.hub.docker.com", true, "registry.hub.docker.com/alpine", "alpine", "library/alpine", []string{}, ".*", "https://", false, true},
25-
"alp@ne": {"", true, "", "", "", []string{}, "", "", false, false},
26-
"localhost/bitcoin/robot": {"localhost", false, "localhost/bitcoin/robot", "localhost/bitcoin/robot", "bitcoin/robot", []string{}, ".*", "http://", false, true},
27-
"localhost:5000/nada/mindundi": {"localhost:5000", false, "localhost:5000/nada/mindundi", "localhost:5000/nada/mindundi", "nada/mindundi", []string{}, ".*", "http://", false, true},
28-
"localhost:7eff/nada/mindundi": {"", true, "", "", "", []string{}, "", "", false, false},
29-
"quay.io/coreos/awscli:master": {"quay.io", false, "quay.io/coreos/awscli", "quay.io/coreos/awscli", "coreos/awscli", []string{"master"}, "", "https://", true, true},
30-
"registry.org/some/repo=latest,stable": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{"latest", "stable"}, "", "https://", true, true},
31-
"registry.org/some/repo=lat!st,stable": {"", true, "", "", "", []string{}, "", "", false, false},
32-
"registry.org/some/repo~/^v1/": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{}, "^v1", "https://", false, true},
33-
"registry.org/some/repo~|^v1|": {"", true, "", "", "", []string{}, "", "", false, false},
34-
"ivanilves/lstags": {"registry.hub.docker.com", true, "registry.hub.docker.com/ivanilves/lstags", "ivanilves/lstags", "ivanilves/lstags", []string{}, ".*", "https://", false, true},
35-
"quay.io/coreos/flannel:v0.6.1-ppc64le": {"quay.io", false, "quay.io/coreos/flannel", "quay.io/coreos/flannel", "coreos/flannel", []string{"v0.6.1-ppc64le"}, "", "https://", true, true},
24+
"alpine": {"registry.hub.docker.com", true, "registry.hub.docker.com/alpine", "alpine", "library/alpine", []string{}, ".*", "https://", false, true},
25+
"alp@ne": {"", true, "", "", "", []string{}, "", "", false, false},
26+
"localhost/bitcoin/robot": {"localhost", false, "localhost/bitcoin/robot", "localhost/bitcoin/robot", "bitcoin/robot", []string{}, ".*", "http://", false, true},
27+
"localhost:5000/nada/mindundi": {"localhost:5000", false, "localhost:5000/nada/mindundi", "localhost:5000/nada/mindundi", "nada/mindundi", []string{}, ".*", "http://", false, true},
28+
"localhost:7eff/nada/mindundi": {"", true, "", "", "", []string{}, "", "", false, false},
29+
"quay.io/coreos/awscli:master": {"quay.io", false, "quay.io/coreos/awscli", "quay.io/coreos/awscli", "coreos/awscli", []string{"master"}, "", "https://", true, true},
30+
"registry.org/some/repo=latest,stable": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{"latest", "stable"}, "", "https://", true, true},
31+
"registry.org/some/repo=lat!st,stable": {"", true, "", "", "", []string{}, "", "", false, false},
32+
"registry.org/some/repo~/^v1/": {"registry.org", false, "registry.org/some/repo", "registry.org/some/repo", "some/repo", []string{}, "^v1", "https://", false, true},
33+
"registry.org/some/repo~|^v1|": {"", true, "", "", "", []string{}, "", "", false, false},
34+
"ivanilves/lstags": {"registry.hub.docker.com", true, "registry.hub.docker.com/ivanilves/lstags", "ivanilves/lstags", "ivanilves/lstags", []string{}, ".*", "https://", false, true},
35+
"quay.io/coreos/flannel:v0.6.1-ppc64le": {"quay.io", false, "quay.io/coreos/flannel", "quay.io/coreos/flannel", "coreos/flannel", []string{"v0.6.1-ppc64le"}, "", "https://", true, true},
36+
"docker.io/bitnami/zookeeper:3.6.1-debian-10-r37": {"registry.hub.docker.com", true, "registry.hub.docker.com/docker.io/bitnami/zookeeper", "docker.io/bitnami/zookeeper", "bitnami/zookeeper", []string{"3.6.1-debian-10-r37"}, "", "https://", true, true},
3637
}
3738

3839
assert := assert.New(t)

0 commit comments

Comments
 (0)