Skip to content

Commit adee284

Browse files
committed
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 <[email protected]>
1 parent a9b3920 commit adee284

File tree

7 files changed

+58
-10
lines changed

7 files changed

+58
-10
lines changed

cmd/dockerd/daemon.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ func NewDaemonCli() *DaemonCli {
6969
daemonConfig.LogConfig.Config = make(map[string]string)
7070
daemonConfig.ClusterOpts = make(map[string]string)
7171

72-
if runtime.GOOS != "linux" {
73-
daemonConfig.V2Only = true
74-
}
75-
7672
daemonConfig.InstallFlags(flag.CommandLine, presentInHelp)
7773
configFile := flag.CommandLine.String([]string{daemonConfigFileFlag}, defaultDaemonConfigFile, "Daemon configuration file")
7874
flag.CommandLine.Require(flag.Exact, 0)
7975

76+
if runtime.GOOS != "linux" {
77+
daemonConfig.V2Only = true
78+
}
79+
8080
return &DaemonCli{
8181
Config: daemonConfig,
8282
commonFlags: cliflags.InitCommonFlags(),

cmd/dockerd/daemon_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
267267
configFile := f.Name()
268268
defer os.Remove(configFile)
269269

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"]}`))
271271
f.Close()
272272

273273
loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
@@ -287,8 +287,4 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
287287
if len(r) != 1 {
288288
t.Fatalf("expected 1 insecure registries, got %d", len(r))
289289
}
290-
291-
if !loadedConfig.V2Only {
292-
t.Fatal("expected disable-legacy-registry to be true, got false")
293-
}
294290
}

cmd/dockerd/daemon_unix_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44

55
import (
66
"io/ioutil"
7+
"os"
78
"testing"
89

910
cliflags "github.com/docker/docker/cli/flags"
@@ -210,3 +211,32 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
210211
t.Fatal("expected userland proxy to be enabled, got disabled")
211212
}
212213
}
214+
215+
func TestLoadDaemonConfigWithLegacyRegistryOptions(t *testing.T) {
216+
c := &daemon.Config{}
217+
common := &cliflags.CommonFlags{}
218+
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
219+
c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)
220+
221+
f, err := ioutil.TempFile("", "docker-config-")
222+
if err != nil {
223+
t.Fatal(err)
224+
}
225+
configFile := f.Name()
226+
defer os.Remove(configFile)
227+
228+
f.Write([]byte(`{"disable-legacy-registry": true}`))
229+
f.Close()
230+
231+
loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
232+
if err != nil {
233+
t.Fatal(err)
234+
}
235+
if loadedConfig == nil {
236+
t.Fatal("expected configuration, got nil")
237+
}
238+
239+
if !loadedConfig.V2Only {
240+
t.Fatal("expected disable-legacy-registry to be true, got false")
241+
}
242+
}

distribution/push_v2.go

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"runtime"
78
"sync"
89

910
"github.com/Sirupsen/logrus"
@@ -169,6 +170,11 @@ func (p *v2Pusher) pushV2Tag(ctx context.Context, ref reference.NamedTagged, ima
169170

170171
putOptions := []distribution.ManifestServiceOption{distribution.WithTag(ref.Tag())}
171172
if _, err = manSvc.Put(ctx, manifest, putOptions...); err != nil {
173+
if runtime.GOOS == "windows" {
174+
logrus.Warnf("failed to upload schema2 manifest: %v", err)
175+
return err
176+
}
177+
172178
logrus.Warnf("failed to upload schema2 manifest: %v - falling back to schema1", err)
173179

174180
manifestRef, err := distreference.WithTag(p.repo.Named(), ref.Tag())

registry/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (options *ServiceOptions) InstallCliFlags(cmd *flag.FlagSet, usageFn func(s
7777
insecureRegistries := opts.NewNamedListOptsRef("insecure-registries", &options.InsecureRegistries, ValidateIndexName)
7878
cmd.Var(insecureRegistries, []string{"-insecure-registry"}, usageFn("Enable insecure registry communication"))
7979

80-
cmd.BoolVar(&options.V2Only, []string{"-disable-legacy-registry"}, false, usageFn("Disable contacting legacy registries"))
80+
options.installCliPlatformFlags(cmd, usageFn)
8181
}
8282

8383
// newServiceConfig returns a new instance of ServiceConfig

registry/config_unix.go

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
package registry
44

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

registry/config_windows.go

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"os"
55
"path/filepath"
66
"strings"
7+
8+
flag "github.com/docker/docker/pkg/mflag"
79
)
810

911
// CertsDir is the directory where certificates are stored
@@ -16,3 +18,8 @@ var CertsDir = os.Getenv("programdata") + `\docker\certs.d`
1618
func cleanPath(s string) string {
1719
return filepath.FromSlash(strings.Replace(s, ":", "", -1))
1820
}
21+
22+
// installCliPlatformFlags handles any platform specific flags for the service.
23+
func (options *ServiceOptions) installCliPlatformFlags(cmd *flag.FlagSet, usageFn func(string) string) {
24+
// No Windows specific flags.
25+
}

0 commit comments

Comments
 (0)