mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
@@ -179,6 +179,8 @@ const (
|
|||||||
StatusTimeout = "timeout"
|
StatusTimeout = "timeout"
|
||||||
StatusKilled = "killed"
|
StatusKilled = "killed"
|
||||||
StatusCancelled = "cancelled"
|
StatusCancelled = "cancelled"
|
||||||
|
|
||||||
|
defaultDomain = "docker.io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@@ -274,23 +276,22 @@ func parseRepositoryTag(repoTag string) (repository string, tag string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseImage(image string) (registry, repo, tag string) {
|
func ParseImage(image string) (registry, repo, tag string) {
|
||||||
|
// registry = defaultDomain // TODO uneasy about this, but it seems wise
|
||||||
repo, tag = parseRepositoryTag(image)
|
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.
|
// Without this, token auth fails.
|
||||||
// Registries must exist at root (https://github.com/moby/moby/issues/7067#issuecomment-54302847)
|
// Registries must exist at root (https://github.com/moby/moby/issues/7067#issuecomment-54302847)
|
||||||
// This cannot support the `library/` shortcut for private registries.
|
// This cannot support the `library/` shortcut for private registries.
|
||||||
parts := strings.Split(repo, "/")
|
parts := strings.SplitN(repo, "/", 2)
|
||||||
switch len(parts) {
|
switch len(parts) {
|
||||||
case 1:
|
case 1:
|
||||||
repo = "library/" + repo
|
repo = "library/" + repo
|
||||||
case 2:
|
default:
|
||||||
if strings.Contains(repo, ".") {
|
// detect if repo has a hostname, otherwise leave it
|
||||||
|
if strings.Contains(parts[0], ".") || strings.Contains(parts[0], ":") || parts[0] == "localhost" {
|
||||||
registry = parts[0]
|
registry = parts[0]
|
||||||
repo = parts[1]
|
repo = parts[1]
|
||||||
}
|
}
|
||||||
case 3:
|
|
||||||
registry = parts[0]
|
|
||||||
repo = parts[1] + "/" + parts[2]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
|
|||||||
@@ -95,15 +95,16 @@ func TestDecimate(t *testing.T) {
|
|||||||
|
|
||||||
func TestParseImage(t *testing.T) {
|
func TestParseImage(t *testing.T) {
|
||||||
cases := map[string][]string{
|
cases := map[string][]string{
|
||||||
"fnproject/hello": {"", "fnproject/hello", "latest"},
|
"fnproject/hello": {"", "fnproject/hello", "latest"},
|
||||||
"fnproject/hello:v1": {"", "fnproject/hello", "v1"},
|
"fnproject/hello:v1": {"", "fnproject/hello", "v1"},
|
||||||
"my.registry/hello": {"my.registry", "hello", "latest"},
|
"my.registry/hello": {"my.registry", "hello", "latest"},
|
||||||
"my.registry/hello:v1": {"my.registry", "hello", "v1"},
|
"my.registry/hello:v1": {"my.registry", "hello", "v1"},
|
||||||
"mongo": {"", "library/mongo", "latest"},
|
"mongo": {"", "library/mongo", "latest"},
|
||||||
"mongo:v1": {"", "library/mongo", "v1"},
|
"mongo:v1": {"", "library/mongo", "v1"},
|
||||||
"quay.com/fnproject/hello": {"quay.com", "fnproject/hello", "latest"},
|
"quay.com/fnproject/hello": {"quay.com", "fnproject/hello", "latest"},
|
||||||
"quay.com:8080/fnproject/hello:v2": {"quay.com:8080", "fnproject/hello", "v2"},
|
"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: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 {
|
for in, out := range cases {
|
||||||
|
|||||||
Reference in New Issue
Block a user