|
@@ -13,10 +13,20 @@ import (
|
|
|
registrytypes "github.com/docker/engine-api/types/registry"
|
|
|
)
|
|
|
|
|
|
-// Options holds command line options.
|
|
|
-type Options struct {
|
|
|
- Mirrors opts.ListOpts
|
|
|
- InsecureRegistries opts.ListOpts
|
|
|
+// ServiceOptions holds command line options.
|
|
|
+type ServiceOptions struct {
|
|
|
+ Mirrors []string `json:"registry-mirrors,omitempty"`
|
|
|
+ InsecureRegistries []string `json:"insecure-registries,omitempty"`
|
|
|
+
|
|
|
+ // V2Only controls access to legacy registries. If it is set to true via the
|
|
|
+ // command line flag the daemon will not attempt to contact v1 legacy registries
|
|
|
+ V2Only bool `json:"disable-legacy-registry,omitempty"`
|
|
|
+}
|
|
|
+
|
|
|
+// serviceConfig holds daemon configuration for the registry service.
|
|
|
+type serviceConfig struct {
|
|
|
+ registrytypes.ServiceConfig
|
|
|
+ V2Only bool
|
|
|
}
|
|
|
|
|
|
var (
|
|
@@ -42,51 +52,45 @@ var (
|
|
|
// not have the correct form
|
|
|
ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
|
|
|
|
|
|
- emptyServiceConfig = NewServiceConfig(nil)
|
|
|
-
|
|
|
- // V2Only controls access to legacy registries. If it is set to true via the
|
|
|
- // command line flag the daemon will not attempt to contact v1 legacy registries
|
|
|
- V2Only = false
|
|
|
+ emptyServiceConfig = newServiceConfig(ServiceOptions{})
|
|
|
)
|
|
|
|
|
|
// for mocking in unit tests
|
|
|
var lookupIP = net.LookupIP
|
|
|
|
|
|
-// InstallFlags adds command-line options to the top-level flag parser for
|
|
|
+// InstallCliFlags adds command-line options to the top-level flag parser for
|
|
|
// the current process.
|
|
|
-func (options *Options) InstallFlags(cmd *flag.FlagSet, usageFn func(string) string) {
|
|
|
- options.Mirrors = opts.NewListOpts(ValidateMirror)
|
|
|
- cmd.Var(&options.Mirrors, []string{"-registry-mirror"}, usageFn("Preferred Docker registry mirror"))
|
|
|
- options.InsecureRegistries = opts.NewListOpts(ValidateIndexName)
|
|
|
- cmd.Var(&options.InsecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication"))
|
|
|
- cmd.BoolVar(&V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Do not contact legacy registries"))
|
|
|
-}
|
|
|
+func (options *ServiceOptions) InstallCliFlags(cmd *flag.FlagSet, usageFn func(string) string) {
|
|
|
+ mirrors := opts.NewNamedListOptsRef("registry-mirrors", &options.Mirrors, ValidateMirror)
|
|
|
+ cmd.Var(mirrors, []string{"-registry-mirror"}, usageFn("Preferred Docker registry mirror"))
|
|
|
|
|
|
-// NewServiceConfig returns a new instance of ServiceConfig
|
|
|
-func NewServiceConfig(options *Options) *registrytypes.ServiceConfig {
|
|
|
- if options == nil {
|
|
|
- options = &Options{
|
|
|
- Mirrors: opts.NewListOpts(nil),
|
|
|
- InsecureRegistries: opts.NewListOpts(nil),
|
|
|
- }
|
|
|
- }
|
|
|
+ insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName)
|
|
|
+ cmd.Var(insecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication"))
|
|
|
+
|
|
|
+ cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Do not contact legacy registries"))
|
|
|
+}
|
|
|
|
|
|
+// newServiceConfig returns a new instance of ServiceConfig
|
|
|
+func newServiceConfig(options ServiceOptions) *serviceConfig {
|
|
|
// Localhost is by default considered as an insecure registry
|
|
|
// This is a stop-gap for people who are running a private registry on localhost (especially on Boot2docker).
|
|
|
//
|
|
|
// TODO: should we deprecate this once it is easier for people to set up a TLS registry or change
|
|
|
// daemon flags on boot2docker?
|
|
|
- options.InsecureRegistries.Set("127.0.0.0/8")
|
|
|
-
|
|
|
- config := ®istrytypes.ServiceConfig{
|
|
|
- InsecureRegistryCIDRs: make([]*registrytypes.NetIPNet, 0),
|
|
|
- IndexConfigs: make(map[string]*registrytypes.IndexInfo, 0),
|
|
|
- // Hack: Bypass setting the mirrors to IndexConfigs since they are going away
|
|
|
- // and Mirrors are only for the official registry anyways.
|
|
|
- Mirrors: options.Mirrors.GetAll(),
|
|
|
+ options.InsecureRegistries = append(options.InsecureRegistries, "127.0.0.0/8")
|
|
|
+
|
|
|
+ config := &serviceConfig{
|
|
|
+ ServiceConfig: registrytypes.ServiceConfig{
|
|
|
+ InsecureRegistryCIDRs: make([]*registrytypes.NetIPNet, 0),
|
|
|
+ IndexConfigs: make(map[string]*registrytypes.IndexInfo, 0),
|
|
|
+ // Hack: Bypass setting the mirrors to IndexConfigs since they are going away
|
|
|
+ // and Mirrors are only for the official registry anyways.
|
|
|
+ Mirrors: options.Mirrors,
|
|
|
+ },
|
|
|
+ V2Only: options.V2Only,
|
|
|
}
|
|
|
// Split --insecure-registry into CIDR and registry-specific settings.
|
|
|
- for _, r := range options.InsecureRegistries.GetAll() {
|
|
|
+ for _, r := range options.InsecureRegistries {
|
|
|
// Check if CIDR was passed to --insecure-registry
|
|
|
_, ipnet, err := net.ParseCIDR(r)
|
|
|
if err == nil {
|
|
@@ -125,7 +129,7 @@ func NewServiceConfig(options *Options) *registrytypes.ServiceConfig {
|
|
|
// or an IP address. If it is a domain name, then it will be resolved in order to check if the IP is contained
|
|
|
// in a subnet. If the resolving is not successful, isSecureIndex will only try to match hostname to any element
|
|
|
// of insecureRegistries.
|
|
|
-func isSecureIndex(config *registrytypes.ServiceConfig, indexName string) bool {
|
|
|
+func isSecureIndex(config *serviceConfig, indexName string) bool {
|
|
|
// Check for configured index, first. This is needed in case isSecureIndex
|
|
|
// is called from anything besides newIndexInfo, in order to honor per-index configurations.
|
|
|
if index, ok := config.IndexConfigs[indexName]; ok {
|
|
@@ -201,7 +205,7 @@ func validateNoSchema(reposName string) error {
|
|
|
}
|
|
|
|
|
|
// newIndexInfo returns IndexInfo configuration from indexName
|
|
|
-func newIndexInfo(config *registrytypes.ServiceConfig, indexName string) (*registrytypes.IndexInfo, error) {
|
|
|
+func newIndexInfo(config *serviceConfig, indexName string) (*registrytypes.IndexInfo, error) {
|
|
|
var err error
|
|
|
indexName, err = ValidateIndexName(indexName)
|
|
|
if err != nil {
|
|
@@ -233,7 +237,7 @@ func GetAuthConfigKey(index *registrytypes.IndexInfo) string {
|
|
|
}
|
|
|
|
|
|
// newRepositoryInfo validates and breaks down a repository name into a RepositoryInfo
|
|
|
-func newRepositoryInfo(config *registrytypes.ServiceConfig, name reference.Named) (*RepositoryInfo, error) {
|
|
|
+func newRepositoryInfo(config *serviceConfig, name reference.Named) (*RepositoryInfo, error) {
|
|
|
index, err := newIndexInfo(config, name.Hostname())
|
|
|
if err != nil {
|
|
|
return nil, err
|