2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-01-24 21:08:47 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-02-25 16:17:48 +00:00
|
|
|
"os/exec"
|
2015-01-13 18:46:32 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
2015-01-24 21:08:47 +00:00
|
|
|
|
|
|
|
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
2015-04-18 16:46:47 +00:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// pulling an image from the central registry should work
|
2015-04-24 21:16:56 +00:00
|
|
|
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
|
2015-01-13 18:46:32 +00:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
2015-02-27 02:23:50 +00:00
|
|
|
// tag the image to upload it to the private registry
|
2014-02-25 16:17:48 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox", repoName)
|
2014-10-14 21:02:15 +00:00
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("image tagging failed: %s, %v", out, err)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
2015-01-13 18:46:32 +00:00
|
|
|
|
2014-02-25 16:17:48 +00:00
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
2014-10-14 21:02:15 +00:00
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
2014-10-14 21:02:15 +00:00
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pushing an image without a prefix should throw an error
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
|
2014-02-25 16:17:48 +00:00
|
|
|
pushCmd := exec.Command(dockerBinary, "push", "busybox")
|
2014-10-14 21:02:15 +00:00
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
2015-01-13 18:46:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
|
2015-01-13 18:46:32 +00:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
2015-03-04 20:05:17 +00:00
|
|
|
expected := "Repository does not exist"
|
2015-01-13 18:46:32 +00:00
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image to the private registry should have failed: outuput %q", out)
|
2015-01-13 18:46:32 +00:00
|
|
|
} else if !strings.Contains(out, expected) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
2015-01-13 18:46:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
|
2015-01-30 22:20:32 +00:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
|
|
|
|
|
|
|
|
expected := "does not exist"
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image to the private registry should have failed: outuput %q", out)
|
2015-01-30 22:20:32 +00:00
|
|
|
} else if !strings.Contains(out, expected) {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
2015-01-30 22:20:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
2015-01-30 22:20:32 +00:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
repoTag1 := fmt.Sprintf("%v/dockercli/busybox:t1", privateRegistryURL)
|
|
|
|
repoTag2 := fmt.Sprintf("%v/dockercli/busybox:t2", privateRegistryURL)
|
2015-04-23 08:50:41 +00:00
|
|
|
// tag the image and upload it to the private registry
|
2015-01-30 22:20:32 +00:00
|
|
|
tagCmd1 := exec.Command(dockerBinary, "tag", "busybox", repoTag1)
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd1); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("image tagging failed: %s, %v", out, err)
|
2015-01-30 22:20:32 +00:00
|
|
|
}
|
|
|
|
tagCmd2 := exec.Command(dockerBinary, "tag", "busybox", repoTag2)
|
|
|
|
if out, _, err := runCommandWithOutput(tagCmd2); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("image tagging failed: %s, %v", out, err)
|
2015-01-30 22:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
2015-01-30 22:20:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
|
2015-01-13 18:46:32 +00:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
2015-04-23 08:50:41 +00:00
|
|
|
// tag the image and upload it to the private registry
|
2015-04-22 04:58:16 +00:00
|
|
|
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repoName)); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("image tagging failed: %s, %v", out, err)
|
2015-01-13 18:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if err := pushCmd.Start(); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Failed to start pushing to private registry: %v", err)
|
2015-01-13 18:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Interrupt push (yes, we have no idea at what point it will get killed).
|
|
|
|
time.Sleep(200 * time.Millisecond)
|
|
|
|
if err := pushCmd.Process.Kill(); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Failed to kill push process: %v", err)
|
2015-01-13 18:46:32 +00:00
|
|
|
}
|
2015-04-22 04:58:16 +00:00
|
|
|
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repoName)); err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
str := string(out)
|
|
|
|
if !strings.Contains(str, "already in progress") {
|
|
|
|
c.Fatalf("Push should be continued on daemon side, but seems ok: %v, %s", err, out)
|
|
|
|
}
|
2015-01-13 18:46:32 +00:00
|
|
|
}
|
2015-04-22 04:58:16 +00:00
|
|
|
// now wait until all this pushes will complete
|
2015-04-23 08:50:41 +00:00
|
|
|
// if it failed with timeout - there would be some error,
|
|
|
|
// so no logic about it here
|
2015-04-22 04:58:16 +00:00
|
|
|
for exec.Command(dockerBinary, "push", repoName).Run() != nil {
|
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
2015-01-24 21:08:47 +00:00
|
|
|
|
2015-04-24 21:16:56 +00:00
|
|
|
func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
|
2015-01-24 21:08:47 +00:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
|
|
|
|
emptyTarball, err := ioutil.TempFile("", "empty_tarball")
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Unable to create test file: %v", err)
|
2015-01-24 21:08:47 +00:00
|
|
|
}
|
|
|
|
tw := tar.NewWriter(emptyTarball)
|
|
|
|
err = tw.Close()
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Error creating empty tarball: %v", err)
|
2015-01-24 21:08:47 +00:00
|
|
|
}
|
|
|
|
freader, err := os.Open(emptyTarball.Name())
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("Could not open test tarball: %v", err)
|
2015-01-24 21:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", repoName)
|
|
|
|
importCmd.Stdin = freader
|
|
|
|
out, _, err := runCommandWithOutput(importCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("import failed with errors: %v, output: %q", err, out)
|
2015-01-24 21:08:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now verify we can push it
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if out, _, err := runCommandWithOutput(pushCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
2015-01-24 21:08:47 +00:00
|
|
|
}
|
|
|
|
}
|