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:
Родитель
561b98067f
Коммит
cc0954586a
23
opts/opts.go
23
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
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче