1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/integration-cli/docker_cli_v2_only_test.go
Sebastiaan van Stijn 8d6df8a0ad
Disallow using legacy (V1) registries
Interacting with v1 registries was deprecated in Docker 1.8.3, disabled by default
in Docker 17.06, and scheduled for removal in Docker 17.12.

This patch disallows enabling V1 registry through the `--disable-legacy-registry`
option, and the `"disable-legacy-registry": false` option in the daemon configuration
file. The actual V1 registry code is still in place, and will be removed separately.

With this patch applied:

    $ dockerd --disable-legacy-registry=false
    ERROR: The '--disable-legacy-registry' flag has been removed. Interacting with legacy (v1) registries is no longer supported

Or, when setting through the `daemon.json` configuration file

    $ mkdir -p /etc/docker/
    $ echo '{"disable-legacy-registry":false}' > /etc/docker/daemon.json
    $ dockerd
    ERROR: The 'disable-legacy-registry' configuration option has been removed. Interacting with legacy (v1) registries is no longer supported

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2017-12-09 02:24:43 -08:00

58 lines
1.4 KiB
Go

package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/docker/docker/integration-cli/registry"
"github.com/go-check/check"
)
func makefile(path string, contents string) (string, error) {
f, err := ioutil.TempFile(path, "tmp")
if err != nil {
return "", err
}
err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm)
if err != nil {
return "", err
}
return f.Name(), nil
}
// TestV2Only ensures that a daemon does not
// attempt to contact any v1 registry endpoints.
func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
reg, err := registry.NewMock(c)
defer reg.Close()
c.Assert(err, check.IsNil)
reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
})
reg.RegisterHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) {
c.Fatal("V1 registry contacted")
})
repoName := fmt.Sprintf("%s/busybox", reg.URL())
s.d.Start(c, "--insecure-registry", reg.URL())
tmp, err := ioutil.TempDir("", "integration-cli-")
c.Assert(err, check.IsNil)
defer os.RemoveAll(tmp)
dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
s.d.Cmd("build", "--file", dockerfileName, tmp)
s.d.Cmd("run", repoName)
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
s.d.Cmd("tag", "busybox", repoName)
s.d.Cmd("push", repoName)
s.d.Cmd("pull", repoName)
}