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