2015-09-16 13:42:17 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-10-06 18:45:32 -04:00
|
|
|
|
2018-04-13 04:45:34 -04:00
|
|
|
"github.com/docker/docker/internal/test/registry"
|
2015-10-06 18:45:32 -04:00
|
|
|
"github.com/go-check/check"
|
2015-09-16 13:42:17 -04:00
|
|
|
)
|
|
|
|
|
2017-06-12 08:47:27 -04:00
|
|
|
func makefile(path string, contents string) (string, error) {
|
|
|
|
f, err := ioutil.TempFile(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
|
|
|
}
|
|
|
|
err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm)
|
|
|
|
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.
|
|
|
|
func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
2016-12-30 13:10:04 -05:00
|
|
|
reg, err := registry.NewMock(c)
|
2017-01-11 15:38:52 -05:00
|
|
|
defer reg.Close()
|
2015-10-14 08:10:34 -04:00
|
|
|
c.Assert(err, check.IsNil)
|
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
|
|
|
|
2017-06-12 08:47:27 -04:00
|
|
|
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()))
|
2015-10-14 08:10:34 -04:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2017-06-12 08:47:27 -04:00
|
|
|
s.d.Cmd("build", "--file", dockerfileName, tmp)
|
2015-09-16 13:42:17 -04:00
|
|
|
|
|
|
|
s.d.Cmd("run", repoName)
|
2017-06-12 07:25:26 -04:00
|
|
|
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
2015-09-16 13:42:17 -04:00
|
|
|
s.d.Cmd("tag", "busybox", repoName)
|
|
|
|
s.d.Cmd("push", repoName)
|
|
|
|
s.d.Cmd("pull", repoName)
|
|
|
|
}
|