Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sha256 digest image addressing #28

Merged
merged 2 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func NewImage(qname, user, password string, insecureTLS, insecureRegistry bool)
client := http.Client{Transport: tr}
registry := dockerHub
tag := "latest"
var nameParts []string
var nameParts, tagParts []string
var name, port string
state := stateInitial
start := 0
for i, c := range qname {
if c == ':' || c == '/' || i == len(qname)-1 {
if c == ':' || c == '/' || c == '@' || i == len(qname)-1 {
if i == len(qname)-1 {
// ignore a separator, include the last symbol
i += 1
Expand Down Expand Up @@ -90,12 +90,13 @@ func NewImage(qname, user, password string, insecureTLS, insecureRegistry bool)
}
}
case stateTag:
tag = part
tag = ""
tagParts = append(tagParts, part)
case statePort:
state = stateName
port = part
case stateName:
if c == ':' {
if c == ':' || c == '@' {
state = stateTag
}
nameParts = append(nameParts, part)
Expand All @@ -109,6 +110,9 @@ func NewImage(qname, user, password string, insecureTLS, insecureRegistry bool)
if name == "" {
name = strings.Join(nameParts, "/")
}
if tag == "" {
tag = strings.Join(tagParts, ":")
}
if insecureRegistry {
registry = fmt.Sprintf("http://%s/v2", registry)
} else {
Expand Down
10 changes: 8 additions & 2 deletions docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ func TestNewImage(t *testing.T) {
name: "library/postgres",
tag: "9.5.1",
},
"digest": {
image: "postgres@sha256:f6a2b81d981ace74aeafb2ed2982d52984d82958bfe836b82cbe4bf1ba440999",
registry: "https://registry-1.docker.io/v2",
name: "library/postgres",
tag: "sha256:f6a2b81d981ace74aeafb2ed2982d52984d82958bfe836b82cbe4bf1ba440999",
},
}
for name, tc := range tcs {
image, err := NewImage(tc.image, "", "")
image, err := NewImage(tc.image, "", "", false)
if err != nil {
t.Fatalf("%s: Can't parse image name: %s", name, err)
}
Expand All @@ -87,7 +93,7 @@ func TestPull(t *testing.T) {
}))
defer ts.Close()

image, err := NewImage("docker-registry.domain.com/nginx:1b29e1531c", "", "")
image, err := NewImage("docker-registry.domain.com/nginx:1b29e1531c", "", "", false)
image.Registry = ts.URL
err = image.Pull()
if err != nil {
Expand Down