2014-02-25 11:17:48 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-12-19 05:25:33 -05:00
|
|
|
"os"
|
2014-02-25 11:17:48 -05:00
|
|
|
"os/exec"
|
2015-02-14 01:01:58 -05:00
|
|
|
"strings"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-02-25 11:17:48 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// export an image and try to import it into a new one
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestExportContainerAndImportImage(c *check.C) {
|
2015-04-16 11:50:20 -04:00
|
|
|
containerID := "testexportcontainerandimportimage"
|
|
|
|
|
2015-05-16 10:59:53 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", containerID, "busybox", "true")
|
2014-02-25 11:17:48 -05:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("failed to create a container", out, err)
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:20 -04:00
|
|
|
exportCmd := exec.Command(dockerBinary, "export", containerID)
|
2014-10-14 15:25:46 -04:00
|
|
|
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to export container: %s, %v", out, err)
|
2014-10-14 15:25:46 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-02-14 01:01:58 -05:00
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2014-02-25 11:17:48 -05:00
|
|
|
out, _, err = runCommandWithOutput(importCmd)
|
2014-10-14 15:25:46 -04:00
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to import image: %s, %v", out, err)
|
2014-10-14 15:25:46 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2015-05-16 10:59:53 -04:00
|
|
|
if cleanedImageID == "" {
|
|
|
|
c.Fatalf("output should have been an image id, got: %s", out)
|
2014-10-14 15:25:46 -04:00
|
|
|
}
|
2014-02-25 11:17:48 -05:00
|
|
|
}
|
2014-12-19 05:25:33 -05:00
|
|
|
|
|
|
|
// Used to test output flag in the export command
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestExportContainerWithOutputAndImportImage(c *check.C) {
|
2015-04-16 11:50:20 -04:00
|
|
|
containerID := "testexportcontainerwithoutputandimportimage"
|
|
|
|
|
2015-05-16 10:59:53 -04:00
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", containerID, "busybox", "true")
|
2014-12-19 05:25:33 -05:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal("failed to create a container", out, err)
|
2014-12-19 05:25:33 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:20 -04:00
|
|
|
defer os.Remove("testexp.tar")
|
|
|
|
|
|
|
|
exportCmd := exec.Command(dockerBinary, "export", "--output=testexp.tar", containerID)
|
2014-12-19 05:25:33 -05:00
|
|
|
if out, _, err = runCommandWithOutput(exportCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to export container: %s, %v", out, err)
|
2014-12-19 05:25:33 -05:00
|
|
|
}
|
|
|
|
|
2015-03-17 03:36:56 -04:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command("cat", "testexp.tar"))
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-03-17 03:36:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
importCmd := exec.Command(dockerBinary, "import", "-", "repo/testexp:v1")
|
|
|
|
importCmd.Stdin = strings.NewReader(out)
|
2014-12-19 05:25:33 -05:00
|
|
|
out, _, err = runCommandWithOutput(importCmd)
|
|
|
|
if err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("failed to import image: %s, %v", out, err)
|
2014-12-19 05:25:33 -05:00
|
|
|
}
|
|
|
|
|
2015-04-06 09:21:18 -04:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2015-05-16 10:59:53 -04:00
|
|
|
if cleanedImageID == "" {
|
|
|
|
c.Fatalf("output should have been an image id, got: %s", out)
|
2014-12-19 05:25:33 -05:00
|
|
|
}
|
|
|
|
}
|