mirror of https://github.com/docker/cli.git
Add daemon flag to specify public registry mirrors
Adds support for a --registry-mirror=scheme://<host>[: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 <timbot@google.com> (github: timbot)
This commit is contained in:
parent
561b98067f
commit
cc0954586a
23
opts/opts.go
23
opts/opts.go
|
@ -3,6 +3,7 @@ package opts
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -33,6 +34,10 @@ func IPVar(value *net.IP, names []string, defaultValue, usage string) {
|
||||||
flag.Var(NewIpOpt(value, defaultValue), names, usage)
|
flag.Var(NewIpOpt(value, defaultValue), names, usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MirrorListVar(values *[]string, names []string, usage string) {
|
||||||
|
flag.Var(newListOptsRef(values, ValidateMirror), names, usage)
|
||||||
|
}
|
||||||
|
|
||||||
// ListOpts type
|
// ListOpts type
|
||||||
type ListOpts struct {
|
type ListOpts struct {
|
||||||
values *[]string
|
values *[]string
|
||||||
|
@ -190,3 +195,21 @@ func validateDomain(val string) (string, error) {
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("%s is not a valid domain", val)
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue