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>
Upstream-commit: adee28458c23581ac9afb163b7cce8c6bb1d2dee
Component: engine
This commit is contained in:
Stefan J. Wernli
2016-07-20 16:14:40 -07:00
parent c9d322ff3f
commit 51a6c88912
7 changed files with 58 additions and 10 deletions
+4 -4
View File
@@ -69,14 +69,14 @@ func NewDaemonCli() *DaemonCli {
daemonConfig.LogConfig.Config = make(map[string]string)
daemonConfig.ClusterOpts = make(map[string]string)
if runtime.GOOS != "linux" {
daemonConfig.V2Only = true
}
daemonConfig.InstallFlags(flag.CommandLine, presentInHelp)
configFile := flag.CommandLine.String([]string{daemonConfigFileFlag}, defaultDaemonConfigFile, "Daemon configuration file")
flag.CommandLine.Require(flag.Exact, 0)
if runtime.GOOS != "linux" {
daemonConfig.V2Only = true
}
return &DaemonCli{
Config: daemonConfig,
commonFlags: cliflags.InitCommonFlags(),
+1 -5
View File
@@ -267,7 +267,7 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
configFile := f.Name()
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()
loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
@@ -287,8 +287,4 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
if len(r) != 1 {
t.Fatalf("expected 1 insecure registries, got %d", len(r))
}
if !loadedConfig.V2Only {
t.Fatal("expected disable-legacy-registry to be true, got false")
}
}
@@ -4,6 +4,7 @@ package main
import (
"io/ioutil"
"os"
"testing"
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")
}
}
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")
}
}
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"runtime"
"sync"
"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())}
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)
manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag())
+1 -1
View File
@@ -77,7 +77,7 @@ func (options *ServiceOptions) InstallCliFlags(cmd *flag.FlagSet, usageFn func(s
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("Disable contacting legacy registries"))
options.installCliPlatformFlags(cmd, usageFn)
}
// newServiceConfig returns a new instance of ServiceConfig
@@ -2,6 +2,10 @@
package registry
import (
flag "github.com/docker/docker/pkg/mflag"
)
var (
// CertsDir is the directory where certificates are stored
CertsDir = "/etc/docker/certs.d"
@@ -14,3 +18,8 @@ var (
func cleanPath(s string) string {
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"))
}
@@ -4,6 +4,8 @@ import (
"os"
"path/filepath"
"strings"
flag "github.com/docker/docker/pkg/mflag"
)
// 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 {
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.
}