support deeper / nesting of image names (#765)

closes #764
This commit is contained in:
Reed Allman
2018-02-13 11:26:28 -08:00
committed by GitHub
parent 46caee5815
commit f287ad274e
2 changed files with 18 additions and 16 deletions

View File

@@ -179,6 +179,8 @@ const (
StatusTimeout = "timeout"
StatusKilled = "killed"
StatusCancelled = "cancelled"
defaultDomain = "docker.io"
)
type Config struct {
@@ -274,23 +276,22 @@ func parseRepositoryTag(repoTag string) (repository string, tag string) {
}
func ParseImage(image string) (registry, repo, tag string) {
// registry = defaultDomain // TODO uneasy about this, but it seems wise
repo, tag = parseRepositoryTag(image)
// Officially sanctioned at https://github.com/moby/moby/blob/master/registry/session.go#L319 to deal with "Official Repositories".
// Officially sanctioned at https://github.com/moby/moby/blob/4f0d95fa6ee7f865597c03b9e63702cdcb0f7067/registry/service.go#L155 to deal with "Official Repositories".
// Without this, token auth fails.
// Registries must exist at root (https://github.com/moby/moby/issues/7067#issuecomment-54302847)
// This cannot support the `library/` shortcut for private registries.
parts := strings.Split(repo, "/")
parts := strings.SplitN(repo, "/", 2)
switch len(parts) {
case 1:
repo = "library/" + repo
case 2:
if strings.Contains(repo, ".") {
default:
// detect if repo has a hostname, otherwise leave it
if strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":") || parts[0] == "localhost" {
registry = parts[0]
repo = parts[1]
}
case 3:
registry = parts[0]
repo = parts[1] + "/" + parts[2]
}
if tag == "" {

View File

@@ -95,15 +95,16 @@ func TestDecimate(t *testing.T) {
func TestParseImage(t *testing.T) {
cases := map[string][]string{
"fnproject/hello": {"", "fnproject/hello", "latest"},
"fnproject/hello:v1": {"", "fnproject/hello", "v1"},
"my.registry/hello": {"my.registry", "hello", "latest"},
"my.registry/hello:v1": {"my.registry", "hello", "v1"},
"mongo": {"", "library/mongo", "latest"},
"mongo:v1": {"", "library/mongo", "v1"},
"quay.com/fnproject/hello": {"quay.com", "fnproject/hello", "latest"},
"quay.com:8080/fnproject/hello:v2": {"quay.com:8080", "fnproject/hello", "v2"},
"localhost.localdomain:5000/samalba/hipache:latest": {"localhost.localdomain:5000", "samalba/hipache", "latest"},
"fnproject/hello": {"", "fnproject/hello", "latest"},
"fnproject/hello:v1": {"", "fnproject/hello", "v1"},
"my.registry/hello": {"my.registry", "hello", "latest"},
"my.registry/hello:v1": {"my.registry", "hello", "v1"},
"mongo": {"", "library/mongo", "latest"},
"mongo:v1": {"", "library/mongo", "v1"},
"quay.com/fnproject/hello": {"quay.com", "fnproject/hello", "latest"},
"quay.com:8080/fnproject/hello:v2": {"quay.com:8080", "fnproject/hello", "v2"},
"localhost.localdomain:5000/samalba/hipache:latest": {"localhost.localdomain:5000", "samalba/hipache", "latest"},
"localhost.localdomain:5000/samalba/hipache/isthisallowedeven:latest": {"localhost.localdomain:5000", "samalba/hipache/isthisallowedeven", "latest"},
}
for in, out := range cases {