浏览代码

Fixing v2 registry restriction for non-linux platforms.

This fixes the hard coded restriction for non-linux platforms to v2 registries.  Previously, the check was above the flag parsing, which would overwrite the hard coded value and prevent correct operation.  This change also removes the related daemon flag from Windows to avoid confusion, as it has no meaning when the value is going to always be hard coded to true.

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>
Stefan J. Wernli 9 年之前
父节点
当前提交
adee28458c

+ 4 - 4
cmd/dockerd/daemon.go

@@ -69,14 +69,14 @@ func NewDaemonCli() *DaemonCli {
 	daemonConfig.LogConfig.Config = make(map[string]string)
 	daemonConfig.LogConfig.Config = make(map[string]string)
 	daemonConfig.ClusterOpts = make(map[string]string)
 	daemonConfig.ClusterOpts = make(map[string]string)
 
 
-	if runtime.GOOS != "linux" {
-		daemonConfig.V2Only = true
-	}
-
 	daemonConfig.InstallFlags(flag.CommandLine, presentInHelp)
 	daemonConfig.InstallFlags(flag.CommandLine, presentInHelp)
 	configFile := flag.CommandLine.String([]string{daemonConfigFileFlag}, defaultDaemonConfigFile, "Daemon configuration file")
 	configFile := flag.CommandLine.String([]string{daemonConfigFileFlag}, defaultDaemonConfigFile, "Daemon configuration file")
 	flag.CommandLine.Require(flag.Exact, 0)
 	flag.CommandLine.Require(flag.Exact, 0)
 
 
+	if runtime.GOOS != "linux" {
+		daemonConfig.V2Only = true
+	}
+
 	return &DaemonCli{
 	return &DaemonCli{
 		Config:      daemonConfig,
 		Config:      daemonConfig,
 		commonFlags: cliflags.InitCommonFlags(),
 		commonFlags: cliflags.InitCommonFlags(),

+ 1 - 5
cmd/dockerd/daemon_test.go

@@ -267,7 +267,7 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
 	configFile := f.Name()
 	configFile := f.Name()
 	defer os.Remove(configFile)
 	defer os.Remove(configFile)
 
 
-	f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"], "disable-legacy-registry": true}`))
+	f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"]}`))
 	f.Close()
 	f.Close()
 
 
 	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
 	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
@@ -287,8 +287,4 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
 	if len(r) != 1 {
 	if len(r) != 1 {
 		t.Fatalf("expected 1 insecure registries, got %d", len(r))
 		t.Fatalf("expected 1 insecure registries, got %d", len(r))
 	}
 	}
-
-	if !loadedConfig.V2Only {
-		t.Fatal("expected disable-legacy-registry to be true, got false")
-	}
 }
 }

+ 30 - 0
cmd/dockerd/daemon_unix_test.go

@@ -4,6 +4,7 @@ package main
 
 
 import (
 import (
 	"io/ioutil"
 	"io/ioutil"
+	"os"
 	"testing"
 	"testing"
 
 
 	cliflags "github.com/docker/docker/cli/flags"
 	cliflags "github.com/docker/docker/cli/flags"
@@ -210,3 +211,32 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
 		t.Fatal("expected userland proxy to be enabled, got disabled")
 		t.Fatal("expected userland proxy to be enabled, got disabled")
 	}
 	}
 }
 }
+
+func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
+	c := &daemon.Config{}
+	common := &cliflags.CommonFlags{}
+	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
+	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)
+
+	f, err := ioutil.TempFile("", "docker-config-")
+	if err != nil {
+		t.Fatal(err)
+	}
+	configFile := f.Name()
+	defer os.Remove(configFile)
+
+	f.Write([]byte(`{"disable-legacy-registry": true}`))
+	f.Close()
+
+	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if loadedConfig == nil {
+		t.Fatal("expected configuration, got nil")
+	}
+
+	if !loadedConfig.V2Only {
+		t.Fatal("expected disable-legacy-registry to be true, got false")
+	}
+}

+ 6 - 0
distribution/push_v2.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
+	"runtime"
 	"sync"
 	"sync"
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
@@ -169,6 +170,11 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, ima
 
 
 	putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())}
 	putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())}
 	if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil {
 	if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil {
+		if runtime.GOOS == "windows" {
+			logrus.Warnf("failed to upload schema2 manifest: %v", err)
+			return err
+		}
+
 		logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err)
 		logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err)
 
 
 		manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag())
 		manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag())

+ 1 - 1
registry/config.go

@@ -77,7 +77,7 @@ func (options *ServiceOptions) InstallCliFlags(cmd *flag.FlagSet, usageFn func(s
 	insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName)
 	insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName)
 	cmd.Var(insecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication"))
 	cmd.Var(insecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication"))
 
 
-	cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries"))
+	options.installCliPlatformFlags(cmd, usageFn)
 }
 }
 
 
 // newServiceConfig returns a new instance of ServiceConfig
 // newServiceConfig returns a new instance of ServiceConfig

+ 9 - 0
registry/config_unix.go

@@ -2,6 +2,10 @@
 
 
 package registry
 package registry
 
 
+import (
+	flag "github.com/docker/docker/pkg/mflag"
+)
+
 var (
 var (
 	// CertsDir is the directory where certificates are stored
 	// CertsDir is the directory where certificates are stored
 	CertsDir = "/etc/docker/certs.d"
 	CertsDir = "/etc/docker/certs.d"
@@ -14,3 +18,8 @@ var (
 func cleanPath(s string) string {
 func cleanPath(s string) string {
 	return s
 	return s
 }
 }
+
+// installCliPlatformFlags handles any platform specific flags for the service.
+func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) {
+	cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries"))
+}

+ 7 - 0
registry/config_windows.go

@@ -4,6 +4,8 @@ import (
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
 	"strings"
 	"strings"
+
+	flag "github.com/docker/docker/pkg/mflag"
 )
 )
 
 
 // CertsDir is the directory where certificates are stored
 // CertsDir is the directory where certificates are stored
@@ -16,3 +18,8 @@ var CertsDir = os.Getenv("programdata") + `\docker\certs.d`
 func cleanPath(s string) string {
 func cleanPath(s string) string {
 	return filepath.FromSlash(strings.Replace(s, ":", "", -1))
 	return filepath.FromSlash(strings.Replace(s, ":", "", -1))
 }
 }
+
+// installCliPlatformFlags handles any platform specific flags for the service.
+func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) {
+	// No Windows specific flags.
+}