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
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
"github.com/docker/docker/integration-cli/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-06-11 08:39:28 -04:00
|
|
|
// TestV2Only ensures that a daemon by default 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)
|
|
|
|
}
|
|
|
|
|
2017-06-11 08:39:28 -04:00
|
|
|
// TestV1 starts a daemon with legacy registries enabled
|
2015-09-16 13:42:17 -04: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 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
|
|
|
|
|
|
|
v2Pings := 0
|
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
|
|
|
v2Pings++
|
|
|
|
// V2 ping 404 causes fallback to v1
|
|
|
|
w.WriteHeader(404)
|
|
|
|
})
|
|
|
|
|
|
|
|
v1Pings := 0
|
2016-12-30 13:10:04 -05:00
|
|
|
reg.RegisterHandler("/v1/_ping", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 13:42:17 -04:00
|
|
|
v1Pings++
|
|
|
|
})
|
|
|
|
|
|
|
|
v1Logins := 0
|
2016-12-30 13:10:04 -05:00
|
|
|
reg.RegisterHandler("/v1/users/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 13:42:17 -04:00
|
|
|
v1Logins++
|
|
|
|
})
|
|
|
|
|
|
|
|
v1Repo := 0
|
2016-12-30 13:10:04 -05:00
|
|
|
reg.RegisterHandler("/v1/repositories/busybox/", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 13:42:17 -04:00
|
|
|
v1Repo++
|
|
|
|
})
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
reg.RegisterHandler("/v1/repositories/busybox/images", func(w http.ResponseWriter, r *http.Request) {
|
2015-09-16 13:42:17 -04:00
|
|
|
v1Repo++
|
|
|
|
})
|
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
s.d.Start(c, "--insecure-registry", reg.URL(), "--disable-legacy-registry=false")
|
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)
|
2016-03-01 02:07:41 -05:00
|
|
|
c.Assert(v1Repo, check.Equals, 1, check.Commentf("Expected v1 repository access after build"))
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
repoName := fmt.Sprintf("%s/busybox", reg.URL())
|
2015-09-16 13:42:17 -04:00
|
|
|
s.d.Cmd("run", repoName)
|
2016-03-01 02:07:41 -05:00
|
|
|
c.Assert(v1Repo, check.Equals, 2, check.Commentf("Expected v1 repository access after run"))
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
s.d.Cmd("login", "-u", "richard", "-p", "testtest", reg.URL())
|
2016-03-01 02:07:41 -05:00
|
|
|
c.Assert(v1Logins, check.Equals, 1, check.Commentf("Expected v1 login attempt"))
|
2015-09-16 13:42:17 -04:00
|
|
|
|
|
|
|
s.d.Cmd("tag", "busybox", repoName)
|
|
|
|
s.d.Cmd("push", repoName)
|
|
|
|
|
2015-10-14 08:10:34 -04:00
|
|
|
c.Assert(v1Repo, check.Equals, 2)
|
2015-09-16 13:42:17 -04:00
|
|
|
|
|
|
|
s.d.Cmd("pull", repoName)
|
2015-10-14 08:10:34 -04:00
|
|
|
c.Assert(v1Repo, check.Equals, 3, check.Commentf("Expected v1 repository access after pull"))
|
2015-09-16 13:42:17 -04:00
|
|
|
}
|