Skip to content

Commit

Permalink
Handle private registries w/ port
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
jwilder committed May 2, 2014
1 parent 736de57 commit ad77c84
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
9 changes: 4 additions & 5 deletions docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ func splitDockerImage(img string) (string, string, string) {
repository = img[index:]
}

if strings.Contains(img, ":") {
separator := strings.Index(img, ":")
repository = img[index:separator]
index = separator + 1
tag = img[index:]
if strings.Contains(repository, ":") {
separator := strings.Index(repository, ":")
tag = repository[separator+1:]
repository = repository[0:separator]
}

return registry, repository, tag
Expand Down
25 changes: 25 additions & 0 deletions docker-gen_test.go → docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,28 @@ func TestSplitDockerImageWithRepositoryAndTag(t *testing.T) {
}

}

func TestSplitDockerImageWithLocalRepositoryAndTag(t *testing.T) {
registry, repository, tag := splitDockerImage("localhost:8888/ubuntu:12.04")

if registry != "localhost:8888" {
t.Fatalf("registry does not match: expected %s got %s", "localhost:8888", registry)
}

if repository != "ubuntu" {
t.Fatalf("repository does not match: expected %s got %s", "ubuntu", repository)
}

if tag != "12.04" {
t.Fatalf("tag does not match: expected %s got %s", "12.04", tag)
}
dockerImage := DockerImage{
Registry: registry,
Repository: repository,
Tag: tag,
}
if "localhost:8888/ubuntu:12.04" != dockerImage.String() {
t.Fail()
}

}

0 comments on commit ad77c84

Please sign in to comment.