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
|
|
|
)
|
|
|
|
|
|
|
|
func makefile(contents string) (string, func(), error) {
|
|
|
|
cleanup := func() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := ioutil.TempFile(".", "tmp")
|
|
|
|
if err != nil {
|
|
|
|
return "", cleanup, err
|
|
|
|
}
|
|
|
|
err = ioutil.WriteFile(f.Name(), []byte(contents), os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return "", cleanup, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup = func() {
|
|
|
|
err := os.Remove(f.Name())
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error removing tmpfile")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f.Name(), cleanup, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestV2Only ensures that a daemon in v2-only mode does not
|
|
|
|
// 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
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
s.d.Start(c, "--insecure-registry", reg.URL(), "--disable-legacy-registry=true")
|
2015-09-16 13:42:17 -04:00
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerfileName, cleanup, err := makefile(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
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
s.d.Cmd("build", "--file", dockerfileName, ".")
|
|
|
|
|
|
|
|
s.d.Cmd("run", repoName)
|
2016-12-30 13:10:04 -05:00
|
|
|
s.d.Cmd("login", "-u", "richard", "-p", "testtest", "-e", "testuser@testdomain.com", 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestV1 starts a daemon in 'normal' mode
|
|
|
|
// 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
|
|
|
|
2016-12-30 13:10:04 -05:00
|
|
|
dockerfileName, cleanup, err := makefile(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
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
s.d.Cmd("build", "--file", dockerfileName, ".")
|
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
|
|
|
}
|