From cc0954586a520b00f6de8a45bd69c26f15ef9c83 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Fri, 18 Jul 2014 18:48:19 +0000 Subject: [PATCH] Add daemon flag to specify public registry mirrors Adds support for a --registry-mirror=scheme://[:port] daemon flag. The flag may be present multiple times. If provided, mirrors are prepended to the list of endpoints used for image pull. Note that only mirrors of the public index.docker.io registry are supported, and image/tag resolution is still performed via the official index. Docker-DCO-1.1-Signed-off-by: Tim Smith (github: timbot) --- opts/opts.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/opts/opts.go b/opts/opts.go index 65806f3698..0ed0f62bcd 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -3,6 +3,7 @@ package opts import ( "fmt" "net" + "net/url" "os" "path/filepath" "regexp" @@ -33,6 +34,10 @@ func IPVar(value *net.IP, names []string, defaultValue, usage string) { flag.Var(NewIpOpt(value, defaultValue), names, usage) } +func MirrorListVar(values *[]string, names []string, usage string) { + flag.Var(newListOptsRef(values, ValidateMirror), names, usage) +} + // ListOpts type type ListOpts struct { values *[]string @@ -190,3 +195,21 @@ func validateDomain(val string) (string, error) { } return "", fmt.Errorf("%s is not a valid domain", val) } + +// Validates an HTTP(S) registry mirror +func ValidateMirror(val string) (string, error) { + uri, err := url.Parse(val) + if err != nil { + return "", fmt.Errorf("%s is not a valid URI", val) + } + + if uri.Scheme != "http" && uri.Scheme != "https" { + return "", fmt.Errorf("Unsupported scheme %s", uri.Scheme) + } + + if uri.Path != "" || uri.RawQuery != "" || uri.Fragment != "" { + return "", fmt.Errorf("Unsupported path/query/fragment at end of the URI") + } + + return fmt.Sprintf("%s://%s/v1/", uri.Scheme, uri.Host), nil +}