2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-01-13 18:19:44 -05:00
|
|
|
"fmt"
|
2014-10-06 21:54:52 -04:00
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
2015-01-13 18:19:44 -05:00
|
|
|
// See issue docker/docker#8141
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPullImageWithAliases(c *check.C) {
|
2015-01-13 18:19:44 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
|
|
|
repos := []string{}
|
|
|
|
for _, tag := range []string{"recent", "fresh"} {
|
|
|
|
repos = append(repos, fmt.Sprintf("%v:%v", repoName, tag))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tag and push the same image multiple times.
|
|
|
|
for _, repo := range repos {
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "tag", "busybox", repo)
|
|
|
|
dockerCmd(c, "push", repo)
|
2015-01-13 18:19:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear local images store.
|
|
|
|
args := append([]string{"rmi"}, repos...)
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, args...)
|
2015-01-13 18:19:44 -05:00
|
|
|
|
|
|
|
// Pull a single tag and verify it doesn't bring down all aliases.
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "pull", repos[0])
|
|
|
|
dockerCmd(c, "inspect", repos[0])
|
2015-01-13 18:19:44 -05:00
|
|
|
for _, repo := range repos[1:] {
|
2015-07-14 02:35:36 -04:00
|
|
|
if _, _, err := dockerCmdWithError(c, "inspect", repo); err == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Image %v shouldn't have been pulled down", repo)
|
2015-01-13 18:19:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-23 18:58:05 -04:00
|
|
|
|
2015-02-05 20:46:55 -05:00
|
|
|
// pulling library/hello-world should show verified message
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPullVerified(c *check.C) {
|
|
|
|
c.Skip("Skipping hub dependent test")
|
2015-04-17 02:05:47 -04:00
|
|
|
|
2015-02-05 20:46:55 -05:00
|
|
|
// Image must be pulled from central repository to get verified message
|
|
|
|
// unless keychain is manually updated to contain the daemon's sign key.
|
2015-01-21 19:12:02 -05:00
|
|
|
|
2015-02-05 20:46:55 -05:00
|
|
|
verifiedName := "hello-world"
|
2015-01-21 19:12:02 -05:00
|
|
|
|
|
|
|
// pull it
|
|
|
|
expected := "The image you are pulling has been verified"
|
2015-07-14 02:35:36 -04:00
|
|
|
if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || !strings.Contains(out, expected) {
|
2015-02-05 20:46:55 -05:00
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
|
2015-02-05 20:46:55 -05:00
|
|
|
}
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("pulling a verified image failed. expected: %s\ngot: %s, %v", expected, out, err)
|
2015-01-21 19:12:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// pull it again
|
2015-07-14 02:35:36 -04:00
|
|
|
if out, exitCode, err := dockerCmdWithError(c, "pull", verifiedName); err != nil || strings.Contains(out, expected) {
|
2015-02-05 20:46:55 -05:00
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Skip(fmt.Sprintf("pulling the '%s' image from the registry has failed: %v", verifiedName, err))
|
2015-02-05 20:46:55 -05:00
|
|
|
}
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("pulling a verified image failed. unexpected verify message\ngot: %s, %v", out, err)
|
2015-01-21 19:12:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-25 11:17:48 -05:00
|
|
|
// pulling an image from the central registry should work
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPullImageFromCentralRegistry(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
2015-02-26 14:20:32 -05:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "pull", "hello-world")
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// pulling a non-existing image from the central registry should return a non-zero exit code
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPullNonExistingImage(c *check.C) {
|
2015-04-22 14:57:23 -04:00
|
|
|
testRequires(c, Network)
|
|
|
|
|
|
|
|
name := "sadfsadfasdf"
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _, err := dockerCmdWithError(c, "pull", name)
|
2015-04-22 14:57:23 -04:00
|
|
|
|
|
|
|
if err == nil || !strings.Contains(out, fmt.Sprintf("Error: image library/%s:latest not found", name)) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 21:54:52 -04:00
|
|
|
|
|
|
|
// pulling an image from the central registry using official names should work
|
|
|
|
// ensure all pulls result in the same image
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPullImageOfficialNames(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
2015-02-27 17:18:11 -05:00
|
|
|
|
2014-10-06 21:54:52 -04:00
|
|
|
names := []string{
|
|
|
|
"library/hello-world",
|
|
|
|
"docker.io/library/hello-world",
|
|
|
|
"index.docker.io/library/hello-world",
|
|
|
|
}
|
|
|
|
for _, name := range names {
|
2015-07-14 02:35:36 -04:00
|
|
|
out, exitCode, err := dockerCmdWithError(c, "pull", name)
|
2014-10-06 21:54:52 -04:00
|
|
|
if err != nil || exitCode != 0 {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
|
2014-10-06 21:54:52 -04:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't have multiple image names.
|
2015-07-14 02:35:36 -04:00
|
|
|
out, _ = dockerCmd(c, "images")
|
|
|
|
if strings.Contains(out, name) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("images should not have listed '%s'", name)
|
2014-10-06 21:54:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-22 17:41:24 -04:00
|
|
|
|
|
|
|
func (s *DockerSuite) TestPullScratchNotAllowed(c *check.C) {
|
|
|
|
testRequires(c, Network)
|
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
out, exitCode, err := dockerCmdWithError(c, "pull", "scratch")
|
2015-04-22 17:41:24 -04:00
|
|
|
if err == nil {
|
|
|
|
c.Fatal("expected pull of scratch to fail, but it didn't")
|
|
|
|
}
|
|
|
|
if exitCode != 1 {
|
|
|
|
c.Fatalf("pulling scratch expected exit code 1, got %d", exitCode)
|
|
|
|
}
|
|
|
|
if strings.Contains(out, "Pulling repository scratch") {
|
|
|
|
c.Fatalf("pulling scratch should not have begun: %s", out)
|
|
|
|
}
|
|
|
|
if !strings.Contains(out, "'scratch' is a reserved name") {
|
|
|
|
c.Fatalf("unexpected output pulling scratch: %s", out)
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 07:47:33 -04:00
|
|
|
|
|
|
|
// pulling an image with --all-tags=true
|
|
|
|
func (s *DockerSuite) TestPullImageWithAllTagFromCentralRegistry(c *check.C) {
|
2015-07-14 02:35:36 -04:00
|
|
|
testRequires(c, Network)
|
2015-07-08 07:47:33 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "pull", "busybox")
|
2015-07-08 07:47:33 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
outImageCmd, _ := dockerCmd(c, "images", "busybox")
|
2015-07-08 07:47:33 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "pull", "--all-tags=true", "busybox")
|
2015-07-08 07:47:33 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
outImageAllTagCmd, _ := dockerCmd(c, "images", "busybox")
|
2015-07-08 07:47:33 -04:00
|
|
|
|
|
|
|
if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
|
|
|
|
c.Fatalf("Pulling with all tags should get more images")
|
|
|
|
}
|
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
// FIXME has probably no effect (tags already pushed)
|
|
|
|
dockerCmd(c, "pull", "-a", "busybox")
|
2015-07-08 07:47:33 -04:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
outImageAllTagCmd, _ = dockerCmd(c, "images", "busybox")
|
2015-07-08 07:47:33 -04:00
|
|
|
|
|
|
|
if strings.Count(outImageCmd, "busybox") >= strings.Count(outImageAllTagCmd, "busybox") {
|
|
|
|
c.Fatalf("Pulling with all tags should get more images")
|
|
|
|
}
|
|
|
|
}
|