2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-01-13 18:19:44 -05:00
|
|
|
"fmt"
|
2014-02-25 11:17:48 -05:00
|
|
|
"os/exec"
|
2014-10-06 21:54:52 -04:00
|
|
|
"strings"
|
2014-02-25 11:17:48 -05:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-01-13 18:19:44 -05:00
|
|
|
// See issue docker/docker#8141
|
|
|
|
func TestPullImageWithAliases(t *testing.T) {
|
|
|
|
defer setupRegistry(t)()
|
|
|
|
|
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
defer deleteImages(repoName)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil {
|
|
|
|
t.Fatalf("Failed to tag image %v: error %v, output %q", repos, err, out)
|
|
|
|
}
|
2015-01-30 17:20:32 -05:00
|
|
|
defer deleteImages(repo)
|
2015-01-13 18:19:44 -05:00
|
|
|
if out, err := exec.Command(dockerBinary, "push", repo).CombinedOutput(); err != nil {
|
2015-02-02 17:53:20 -05:00
|
|
|
t.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out))
|
2015-01-13 18:19:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear local images store.
|
|
|
|
args := append([]string{"rmi"}, repos...)
|
|
|
|
if out, err := exec.Command(dockerBinary, args...).CombinedOutput(); err != nil {
|
|
|
|
t.Fatalf("Failed to clean images: error %v, output %q", err, string(out))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pull a single tag and verify it doesn't bring down all aliases.
|
|
|
|
pullCmd := exec.Command(dockerBinary, "pull", repos[0])
|
|
|
|
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
|
|
|
|
t.Fatalf("Failed to pull %v: error %v, output %q", repoName, err, out)
|
|
|
|
}
|
|
|
|
if err := exec.Command(dockerBinary, "inspect", repos[0]).Run(); err != nil {
|
|
|
|
t.Fatalf("Image %v was not pulled down", repos[0])
|
|
|
|
}
|
|
|
|
for _, repo := range repos[1:] {
|
|
|
|
if err := exec.Command(dockerBinary, "inspect", repo).Run(); err == nil {
|
|
|
|
t.Fatalf("Image %v shouldn't have been pulled down", repo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logDone("pull - image with aliases")
|
|
|
|
}
|
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-01-21 19:12:02 -05:00
|
|
|
func TestPullVerified(t *testing.T) {
|
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"
|
|
|
|
defer deleteImages(verifiedName)
|
2015-01-21 19:12:02 -05:00
|
|
|
|
|
|
|
// pull it
|
|
|
|
expected := "The image you are pulling has been verified"
|
2015-02-05 20:46:55 -05:00
|
|
|
pullCmd := exec.Command(dockerBinary, "pull", verifiedName)
|
|
|
|
if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || !strings.Contains(out, expected) {
|
|
|
|
if err != nil || exitCode != 0 {
|
|
|
|
t.Skipf("pulling the '%s' image from the registry has failed: %s", verifiedName, err)
|
|
|
|
}
|
2015-01-21 19:12:02 -05:00
|
|
|
t.Fatalf("pulling a verified image failed. expected: %s\ngot: %s, %v", expected, out, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pull it again
|
2015-02-05 20:46:55 -05:00
|
|
|
pullCmd = exec.Command(dockerBinary, "pull", verifiedName)
|
|
|
|
if out, exitCode, err := runCommandWithOutput(pullCmd); err != nil || strings.Contains(out, expected) {
|
|
|
|
if err != nil || exitCode != 0 {
|
|
|
|
t.Skipf("pulling the '%s' image from the registry has failed: %s", verifiedName, err)
|
|
|
|
}
|
|
|
|
t.Fatalf("pulling a verified image failed. unexpected verify message\ngot: %s, %v", out, err)
|
2015-01-21 19:12:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
logDone("pull - pull verified")
|
|
|
|
}
|
|
|
|
|
2014-02-25 11:17:48 -05:00
|
|
|
// pulling an image from the central registry should work
|
|
|
|
func TestPullImageFromCentralRegistry(t *testing.T) {
|
2015-02-26 14:20:32 -05:00
|
|
|
testRequires(t, Network)
|
|
|
|
|
2015-02-05 20:46:55 -05:00
|
|
|
defer deleteImages("hello-world")
|
|
|
|
|
2014-10-28 17:06:23 -04:00
|
|
|
pullCmd := exec.Command(dockerBinary, "pull", "hello-world")
|
2014-10-14 17:09:40 -04:00
|
|
|
if out, _, err := runCommandWithOutput(pullCmd); err != nil {
|
2014-10-28 17:06:23 -04:00
|
|
|
t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2014-10-28 17:06:23 -04:00
|
|
|
logDone("pull - 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
|
|
|
|
func TestPullNonExistingImage(t *testing.T) {
|
|
|
|
pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234")
|
2014-10-14 17:09:40 -04:00
|
|
|
if out, _, err := runCommandWithOutput(pullCmd); err == nil {
|
2014-11-05 11:26:22 -05:00
|
|
|
t.Fatalf("expected non-zero exit status when pulling non-existing image: %s", out)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
logDone("pull - pull fooblahblah1234 (non-existing image)")
|
|
|
|
}
|
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
|
|
|
|
func TestPullImageOfficialNames(t *testing.T) {
|
2015-02-27 17:18:11 -05:00
|
|
|
testRequires(t, Network)
|
|
|
|
|
2014-10-06 21:54:52 -04:00
|
|
|
names := []string{
|
|
|
|
"docker.io/hello-world",
|
|
|
|
"index.docker.io/hello-world",
|
|
|
|
"library/hello-world",
|
|
|
|
"docker.io/library/hello-world",
|
|
|
|
"index.docker.io/library/hello-world",
|
|
|
|
}
|
|
|
|
for _, name := range names {
|
|
|
|
pullCmd := exec.Command(dockerBinary, "pull", name)
|
|
|
|
out, exitCode, err := runCommandWithOutput(pullCmd)
|
|
|
|
if err != nil || exitCode != 0 {
|
|
|
|
t.Errorf("pulling the '%s' image from the registry has failed: %s", name, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure we don't have multiple image names.
|
|
|
|
imagesCmd := exec.Command(dockerBinary, "images")
|
|
|
|
out, _, err = runCommandWithOutput(imagesCmd)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("listing images failed with errors: %v", err)
|
|
|
|
} else if strings.Contains(out, name) {
|
|
|
|
t.Errorf("images should not have listed '%s'", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
logDone("pull - pull official names")
|
|
|
|
}
|