Browse code

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 authored on 2016/07/19 06:48:26
Showing 7 changed files
... ...
@@ -69,14 +69,14 @@ func NewDaemonCli() *DaemonCli {
69 69
 	daemonConfig.LogConfig.Config = make(map[string]string)
70 70
 	daemonConfig.ClusterOpts = make(map[string]string)
71 71
 
72
-	if runtime.GOOS != "linux" {
73
-		daemonConfig.V2Only = true
74
-	}
75
-
76 72
 	daemonConfig.InstallFlags(flag.CommandLine, presentInHelp)
77 73
 	configFile := flag.CommandLine.String([]string{daemonConfigFileFlag}, defaultDaemonConfigFile, "Daemon configuration file")
78 74
 	flag.CommandLine.Require(flag.Exact, 0)
79 75
 
76
+	if runtime.GOOS != "linux" {
77
+		daemonConfig.V2Only = true
78
+	}
79
+
80 80
 	return &DaemonCli{
81 81
 		Config:      daemonConfig,
82 82
 		commonFlags: cliflags.InitCommonFlags(),
... ...
@@ -267,7 +267,7 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
267 267
 	configFile := f.Name()
268 268
 	defer os.Remove(configFile)
269 269
 
270
-	f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"], "disable-legacy-registry": true}`))
270
+	f.Write([]byte(`{"registry-mirrors": ["https://mirrors.docker.com"], "insecure-registries": ["https://insecure.docker.com"]}`))
271 271
 	f.Close()
272 272
 
273 273
 	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
... ...
@@ -287,8 +287,4 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
287 287
 	if len(r) != 1 {
288 288
 		t.Fatalf("expected 1 insecure registries, got %d", len(r))
289 289
 	}
290
-
291
-	if !loadedConfig.V2Only {
292
-		t.Fatal("expected disable-legacy-registry to be true, got false")
293
-	}
294 290
 }
... ...
@@ -4,6 +4,7 @@ package main
4 4
 
5 5
 import (
6 6
 	"io/ioutil"
7
+	"os"
7 8
 	"testing"
8 9
 
9 10
 	cliflags "github.com/docker/docker/cli/flags"
... ...
@@ -210,3 +211,32 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
210 210
 		t.Fatal("expected userland proxy to be enabled, got disabled")
211 211
 	}
212 212
 }
213
+
214
+func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
215
+	c := &daemon.Config{}
216
+	common := &cliflags.CommonFlags{}
217
+	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
218
+	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)
219
+
220
+	f, err := ioutil.TempFile("", "docker-config-")
221
+	if err != nil {
222
+		t.Fatal(err)
223
+	}
224
+	configFile := f.Name()
225
+	defer os.Remove(configFile)
226
+
227
+	f.Write([]byte(`{"disable-legacy-registry": true}`))
228
+	f.Close()
229
+
230
+	loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
231
+	if err != nil {
232
+		t.Fatal(err)
233
+	}
234
+	if loadedConfig == nil {
235
+		t.Fatal("expected configuration, got nil")
236
+	}
237
+
238
+	if !loadedConfig.V2Only {
239
+		t.Fatal("expected disable-legacy-registry to be true, got false")
240
+	}
241
+}
... ...
@@ -4,6 +4,7 @@ import (
4 4
 	"errors"
5 5
 	"fmt"
6 6
 	"io"
7
+	"runtime"
7 8
 	"sync"
8 9
 
9 10
 	"github.com/Sirupsen/logrus"
... ...
@@ -169,6 +170,11 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, ima
169 169
 
170 170
 	putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())}
171 171
 	if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil {
172
+		if runtime.GOOS == "windows" {
173
+			logrus.Warnf("failed to upload schema2 manifest: %v", err)
174
+			return err
175
+		}
176
+
172 177
 		logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err)
173 178
 
174 179
 		manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag())
... ...
@@ -77,7 +77,7 @@ func (options *ServiceOptions) InstallCliFlags(cmd *flag.FlagSet, usageFn func(s
77 77
 	insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName)
78 78
 	cmd.Var(insecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication"))
79 79
 
80
-	cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries"))
80
+	options.installCliPlatformFlags(cmd, usageFn)
81 81
 }
82 82
 
83 83
 // newServiceConfig returns a new instance of ServiceConfig
... ...
@@ -2,6 +2,10 @@
2 2
 
3 3
 package registry
4 4
 
5
+import (
6
+	flag "github.com/docker/docker/pkg/mflag"
7
+)
8
+
5 9
 var (
6 10
 	// CertsDir is the directory where certificates are stored
7 11
 	CertsDir = "/etc/docker/certs.d"
... ...
@@ -14,3 +18,8 @@ var (
14 14
 func cleanPath(s string) string {
15 15
 	return s
16 16
 }
17
+
18
+// installCliPlatformFlags handles any platform specific flags for the service.
19
+func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) {
20
+	cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries"))
21
+}
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"os"
5 5
 	"path/filepath"
6 6
 	"strings"
7
+
8
+	flag "github.com/docker/docker/pkg/mflag"
7 9
 )
8 10
 
9 11
 // CertsDir is the directory where certificates are stored
... ...
@@ -16,3 +18,8 @@ var CertsDir = os.Getenv("programdata") + `\docker\certs.d`
16 16
 func cleanPath(s string) string {
17 17
 	return filepath.FromSlash(strings.Replace(s, ":", "", -1))
18 18
 }
19
+
20
+// installCliPlatformFlags handles any platform specific flags for the service.
21
+func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) {
22
+	// No Windows specific flags.
23
+}