Skip to content

Commit ad77c84

Browse files
committed
Handle private registries w/ port
Fixes #2
1 parent 736de57 commit ad77c84

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

docker_client.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ func splitDockerImage(img string) (string, string, string) {
2929
repository = img[index:]
3030
}
3131

32-
if strings.Contains(img, ":") {
33-
separator := strings.Index(img, ":")
34-
repository = img[index:separator]
35-
index = separator + 1
36-
tag = img[index:]
32+
if strings.Contains(repository, ":") {
33+
separator := strings.Index(repository, ":")
34+
tag = repository[separator+1:]
35+
repository = repository[0:separator]
3736
}
3837

3938
return registry, repository, tag

docker-gen_test.go docker_client_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,28 @@ func TestSplitDockerImageWithRepositoryAndTag(t *testing.T) {
9797
}
9898

9999
}
100+
101+
func TestSplitDockerImageWithLocalRepositoryAndTag(t *testing.T) {
102+
registry, repository, tag := splitDockerImage("localhost:8888/ubuntu:12.04")
103+
104+
if registry != "localhost:8888" {
105+
t.Fatalf("registry does not match: expected %s got %s", "localhost:8888", registry)
106+
}
107+
108+
if repository != "ubuntu" {
109+
t.Fatalf("repository does not match: expected %s got %s", "ubuntu", repository)
110+
}
111+
112+
if tag != "12.04" {
113+
t.Fatalf("tag does not match: expected %s got %s", "12.04", tag)
114+
}
115+
dockerImage := DockerImage{
116+
Registry: registry,
117+
Repository: repository,
118+
Tag: tag,
119+
}
120+
if "localhost:8888/ubuntu:12.04" != dockerImage.String() {
121+
t.Fail()
122+
}
123+
124+
}

0 commit comments

Comments
 (0)