2015-09-16 17:42:17 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-10-06 22:45:32 +00:00
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
"github.com/docker/docker/integration-cli/registry"
|
2015-10-06 22:45:32 +00:00
|
|
|
"github.com/go-check/check"
|
2015-09-16 17:42:17 +00:00
|
|
|
)
|
|
|
|
|
2017-06-12 12:47:27 +00:00
|
|
|
func makefile(path string, contents string) (string, error) {
|
|
|
|
f, err := ioutil.TempFile(path, "tmp")
|
2015-09-16 17:42:17 +00:00
|
|
|
if err != nil {
|
2017-06-12 12:47:27 +00:00
|
|
|
return "", err
|
2015-09-16 17:42:17 +00:00
|
|
|
}
|
|
|
|
err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm)
|
|
|
|
if err != nil {
|
2017-06-12 12:47:27 +00:00
|
|
|
return "", err
|
2015-09-16 17:42:17 +00:00
|
|
|
}
|
2017-06-12 12:47:27 +00:00
|
|
|
return f.Name(), nil
|
2015-09-16 17:42:17 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 12:39:28 +00:00
|
|
|
// TestV2Only ensures that a daemon by default does not
|
2015-09-16 17:42:17 +00:00
|
|
|
// attempt to contact any v1 registry endpoints.
|
|
|
|
func (s *DockerRegistrySuite) TestV2Only(c *check.C) {
|
2016-12-30 18:10:04 +00:00
|
|
|
reg, err := registry.NewMock(c)
|
2017-01-11 20:38:52 +00:00
|
|
|
defer reg.Close()
|
2015-10-14 12:10:34 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
w.WriteHeader(404)
|
|
|
|
})
|
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v1/.*", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
c.Fatal("V1 registry contacted")
|
|
|
|
})
|
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
repoName := fmt.Sprintf("%s/busybox", reg.URL())
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2017-06-11 12:39:28 +00:00
|
|
|
s.d.Start(c, "--insecure-registry", reg.URL())
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2017-06-12 12:47:27 +00: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 12:10:34 +00:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2017-06-12 12:47:27 +00:00
|
|
|
s.d.Cmd("build", "--file", dockerfileName, tmp)
|
2015-09-16 17:42:17 +00:00
|
|
|
|
|
|
|
s.d.Cmd("run", repoName)
|
2017-06-12 11:25:26 +00:00
|
|
|
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
2015-09-16 17:42:17 +00:00
|
|
|
s.d.Cmd("tag", "busybox", repoName)
|
|
|
|
s.d.Cmd("push", repoName)
|
|
|
|
s.d.Cmd("pull", repoName)
|
|
|
|
}
|
|
|
|
|
2017-06-11 12:39:28 +00:00
|
|
|
// TestV1 starts a daemon with legacy registries enabled
|
2015-09-16 17:42:17 +00:00
|
|
|
// and ensure v1 endpoints are hit for the following operations:
|
|
|
|
// login, push, pull, build & run
|
|
|
|
func (s *DockerRegistrySuite) TestV1(c *check.C) {
|
2016-12-30 18:10:04 +00:00
|
|
|
reg, err := registry.NewMock(c)
|
2017-01-11 20:38:52 +00:00
|
|
|
defer reg.Close()
|
2015-10-14 12:10:34 +00:00
|
|
|
c.Assert(err, check.IsNil)
|
2015-09-16 17:42:17 +00:00
|
|
|
|
|
|
|
v2Pings := 0
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v2/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
v2Pings++
|
|
|
|
// V2 ping 404 causes fallback to v1
|
|
|
|
w.WriteHeader(404)
|
|
|
|
})
|
|
|
|
|
|
|
|
v1Pings := 0
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v1/_ping", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
v1Pings++
|
|
|
|
})
|
|
|
|
|
|
|
|
v1Logins := 0
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v1/users/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
v1Logins++
|
|
|
|
})
|
|
|
|
|
|
|
|
v1Repo := 0
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v1/repositories/busybox/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
v1Repo++
|
|
|
|
})
|
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
reg.RegisterHandler("/v1/repositories/busybox/images", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 17:42:17 +00:00
|
|
|
v1Repo++
|
|
|
|
})
|
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
s.d.Start(c, "--insecure-registry", reg.URL(), "--disable-legacy-registry=false")
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2017-06-12 12:47:27 +00: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 12:10:34 +00:00
|
|
|
c.Assert(err, check.IsNil, check.Commentf("Unable to create test dockerfile"))
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2017-06-12 12:47:27 +00:00
|
|
|
s.d.Cmd("build", "--file", dockerfileName, tmp)
|
2016-03-01 07:07:41 +00:00
|
|
|
c.Assert(v1Repo, check.Equals, 1, check.Commentf("Expected v1 repository access after build"))
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
repoName := fmt.Sprintf("%s/busybox", reg.URL())
|
2015-09-16 17:42:17 +00:00
|
|
|
s.d.Cmd("run", repoName)
|
2016-03-01 07:07:41 +00:00
|
|
|
c.Assert(v1Repo, check.Equals, 2, check.Commentf("Expected v1 repository access after run"))
|
2015-09-16 17:42:17 +00:00
|
|
|
|
2016-12-30 18:10:04 +00:00
|
|
|
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
2016-03-01 07:07:41 +00:00
|
|
|
c.Assert(v1Logins, check.Equals, 1, check.Commentf("Expected v1 login attempt"))
|
2015-09-16 17:42:17 +00:00
|
|
|
|
|
|
|
s.d.Cmd("tag", "busybox", repoName)
|
|
|
|
s.d.Cmd("push", repoName)
|
|
|
|
|
2015-10-14 12:10:34 +00:00
|
|
|
c.Assert(v1Repo, check.Equals, 2)
|
2015-09-16 17:42:17 +00:00
|
|
|
|
|
|
|
s.d.Cmd("pull", repoName)
|
2015-10-14 12:10:34 +00:00
|
|
|
c.Assert(v1Repo, check.Equals, 3, check.Commentf("Expected v1 repository access after pull"))
|
2015-09-16 17:42:17 +00:00
|
|
|
}
|