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