2015-09-16 13:42:17 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2019-09-09 17:06:12 -04:00
|
|
|
"testing"
|
2015-10-06 18:45:32 -04:00
|
|
|
|
2019-08-29 16:52:40 -04:00
|
|
|
"github.com/docker/docker/testutil/registry"
|
2020-02-07 08:39:24 -05:00
|
|
|
"gotest.tools/v3/assert"
|
2015-09-16 13:42:17 -04:00
|
|
|
)
|
|
|
|
|
2017-06-12 08:47:27 -04:00
|
|
|
func makefile(path string, contents string) (string, error) {
|
2021-08-24 06:10:50 -04:00
|
|
|
f, err := os.CreateTemp(path, "tmp")
|
2015-09-16 13:42:17 -04:00
|
|
|
if err != nil {
|
2017-06-12 08:47:27 -04:00
|
|
|
return "", err
|
2015-09-16 13:42:17 -04:00
|
|
|
}
|
2021-08-24 06:10:50 -04:00
|
|
|
err = os.WriteFile(f.Name(), []byte(contents), os.ModePerm)
|
2015-09-16 13:42:17 -04:00
|
|
|
if err != nil {
|
2017-06-12 08:47:27 -04:00
|
|
|
return "", err
|
2015-09-16 13:42:17 -04:00
|
|
|
}
|
2017-06-12 08:47:27 -04:00
|
|
|
return f.Name(), nil
|
2015-09-16 13:42:17 -04:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:13:43 -05:00
|
|
|
// TestV2Only ensures that a daemon does not
|
2015-09-16 13:42:17 -04:00
|
|
|
// attempt to contact any v1 registry endpoints.
|
2019-09-09 17:05:55 -04:00
|
|
|
func (s *DockerRegistrySuite) TestV2Only(c *testing.T) {
|
2016-12-30 13:10:04 -05:00
|
|
|
reg, err := registry.NewMock(c)
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2019-08-28 13:56:38 -04:00
|
|
|
defer reg.Close()
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 13:42:17 -04:00
|
|
|
w.WriteHeader(404)
|
|
|
|
})
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
reg.RegisterHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 13:42:17 -04:00
|
|
|
c.Fatal("V1 registry contacted")
|
|
|
|
})
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
repoName := fmt.Sprintf("%s/busybox", reg.URL())
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2017-06-11 08:39:28 -04:00
|
|
|
s.d.Start(c, "--insecure-registry", reg.URL())
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2021-08-24 06:10:50 -04:00
|
|
|
tmp, err := os.MkdirTemp("", "integration-cli-")
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err)
|
2017-06-12 08:47:27 -04:00
|
|
|
defer os.RemoveAll(tmp)
|
|
|
|
|
|
|
|
dockerfileName, err := makefile(tmp, fmt.Sprintf("FROM %s/busybox", reg.URL()))
|
2019-04-04 09:23:19 -04:00
|
|
|
assert.NilError(c, err, "Unable to create test dockerfile")
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2019-08-28 13:56:38 -04:00
|
|
|
_, _ = 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)
|
2015-09-16 13:42:17 -04:00
|
|
|
}
|