2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-05-01 18:01:10 -04:00
|
|
|
"archive/tar"
|
2014-02-25 11:17:48 -05:00
|
|
|
"fmt"
|
2015-01-24 16:08:47 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2014-02-25 11:17:48 -05:00
|
|
|
"os/exec"
|
2015-01-13 13:46:32 -05:00
|
|
|
"strings"
|
|
|
|
"time"
|
2015-01-24 16:08:47 -05:00
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
2015-07-07 04:10:37 -04:00
|
|
|
// Pushing an image to a private registry.
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPushBusyboxImage(c *check.C) {
|
2015-01-13 13:46:32 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
2015-02-26 21:23:50 -05:00
|
|
|
// tag the image to upload it to the private registry
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "tag", "busybox", repoName)
|
|
|
|
// push the image to the registry
|
|
|
|
dockerCmd(c, "push", repoName)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// pushing an image without a prefix should throw an error
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestPushUnprefixedRepo(c *check.C) {
|
2015-07-14 02:35:36 -04:00
|
|
|
if out, _, err := dockerCmdWithError(c, "push", "busybox"); err == nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("pushing an unprefixed repo didn't result in a non-zero exit status: %s", out)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2015-01-13 13:46:32 -05:00
|
|
|
}
|
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPushUntagged(c *check.C) {
|
2015-01-13 13:46:32 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
|
|
|
|
2015-03-04 15:05:17 -05:00
|
|
|
expected := "Repository does not exist"
|
2015-07-14 02:35:36 -04:00
|
|
|
if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
|
2015-04-27 16:33:30 -04:00
|
|
|
c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
|
2015-01-13 13:46:32 -05:00
|
|
|
} else if !strings.Contains(out, expected) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
2015-01-13 13:46:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPushBadTag(c *check.C) {
|
2015-01-30 17:20:32 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox:latest", privateRegistryURL)
|
|
|
|
|
|
|
|
expected := "does not exist"
|
2015-07-14 02:35:36 -04:00
|
|
|
|
|
|
|
if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
|
2015-04-27 16:33:30 -04:00
|
|
|
c.Fatalf("pushing the image to the private registry should have failed: output %q", out)
|
2015-01-30 17:20:32 -05:00
|
|
|
} else if !strings.Contains(out, expected) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("pushing the image failed with an unexpected message: expected %q, got %q", expected, out)
|
2015-01-30 17:20:32 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPushMultipleTags(c *check.C) {
|
2015-01-30 17:20:32 -05: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 04:50:41 -04:00
|
|
|
// tag the image and upload it to the private registry
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "tag", "busybox", repoTag1)
|
2015-01-30 17:20:32 -05:00
|
|
|
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "tag", "busybox", repoTag2)
|
|
|
|
|
|
|
|
dockerCmd(c, "push", repoName)
|
2015-01-30 17:20:32 -05:00
|
|
|
}
|
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPushInterrupt(c *check.C) {
|
2015-01-13 13:46:32 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL)
|
2015-04-23 04:50:41 -04:00
|
|
|
// tag the image and upload it to the private registry
|
2015-07-14 02:35:36 -04:00
|
|
|
dockerCmd(c, "tag", "busybox", repoName)
|
2015-01-13 13:46:32 -05:00
|
|
|
|
|
|
|
pushCmd := exec.Command(dockerBinary, "push", repoName)
|
|
|
|
if err := pushCmd.Start(); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Failed to start pushing to private registry: %v", err)
|
2015-01-13 13:46:32 -05: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 12:46:47 -04:00
|
|
|
c.Fatalf("Failed to kill push process: %v", err)
|
2015-01-13 13:46:32 -05:00
|
|
|
}
|
2015-07-14 02:35:36 -04:00
|
|
|
if out, _, err := dockerCmdWithError(c, "push", repoName); err == nil {
|
2015-04-18 12:46:47 -04: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 13:46:32 -05:00
|
|
|
}
|
2015-04-22 00:58:16 -04:00
|
|
|
// now wait until all this pushes will complete
|
2015-04-23 04:50:41 -04:00
|
|
|
// if it failed with timeout - there would be some error,
|
|
|
|
// so no logic about it here
|
2015-04-22 00:58:16 -04:00
|
|
|
for exec.Command(dockerBinary, "push", repoName).Run() != nil {
|
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2015-01-24 16:08:47 -05:00
|
|
|
|
2015-04-24 17:16:56 -04:00
|
|
|
func (s *DockerRegistrySuite) TestPushEmptyLayer(c *check.C) {
|
2015-01-24 16:08:47 -05:00
|
|
|
repoName := fmt.Sprintf("%v/dockercli/emptylayer", privateRegistryURL)
|
|
|
|
emptyTarball, err := ioutil.TempFile("", "empty_tarball")
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Unable to create test file: %v", err)
|
2015-01-24 16:08:47 -05:00
|
|
|
}
|
|
|
|
tw := tar.NewWriter(emptyTarball)
|
|
|
|
err = tw.Close()
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Error creating empty tarball: %v", err)
|
2015-01-24 16:08:47 -05:00
|
|
|
}
|
|
|
|
freader, err := os.Open(emptyTarball.Name())
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Could not open test tarball: %v", err)
|
2015-01-24 16:08:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", repoName)
|
|
|
|
importCmd.Stdin = freader
|
|
|
|
out, _, err := runCommandWithOutput(importCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Errorf("import failed with errors: %v, output: %q", err, out)
|
2015-01-24 16:08:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now verify we can push it
|
2015-07-14 02:35:36 -04:00
|
|
|
if out, _, err := dockerCmdWithError(c, "push", repoName); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("pushing the image to the private registry has failed: %s, %v", out, err)
|
2015-01-24 16:08:47 -05:00
|
|
|
}
|
|
|
|
}
|