2014-02-25 16:17:48 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-09-06 11:49:40 +00:00
|
|
|
"io/ioutil"
|
2014-02-25 16:17:48 +00:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2014-09-06 11:49:40 +00:00
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2014-11-11 09:18:22 +00:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2015-04-18 16:46:47 +00:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2014-02-25 16:17:48 +00:00
|
|
|
)
|
|
|
|
|
2014-12-08 20:40:27 +00:00
|
|
|
// save a repo using gz compression and try to load it using stdout
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
|
2015-05-16 14:59:53 +00:00
|
|
|
name := "test-save-xz-and-load-repo-stdout"
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
|
2014-12-08 20:40:27 +00:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to create a container: %v %v", out, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
repoName := "foobar-save-load-test-xz-gz"
|
|
|
|
|
2015-05-16 14:59:53 +00:00
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
|
2014-12-08 20:40:27 +00:00
|
|
|
out, _, err = runCommandWithOutput(commitCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to commit container: %v %v", out, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 14:59:53 +00:00
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
|
2014-12-08 20:40:27 +00:00
|
|
|
before, _, err := runCommandWithOutput(inspectCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("the repo should exist before saving it: %v %v", before, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
repoTarball, _, err := runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
|
|
exec.Command("xz", "-c"),
|
|
|
|
exec.Command("gzip", "-c"))
|
2014-12-08 20:40:27 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save repo: %v %v", out, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
deleteImages(repoName)
|
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
loadCmd := exec.Command(dockerBinary, "load")
|
|
|
|
loadCmd.Stdin = strings.NewReader(repoTarball)
|
2014-12-08 20:40:27 +00:00
|
|
|
out, _, err = runCommandWithOutput(loadCmd)
|
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("expected error, but succeeded with no error and output: %v", out)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
|
|
|
after, _, err := runCommandWithOutput(inspectCmd)
|
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("the repo should not exist: %v", after)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteImages(repoName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// save a repo using xz+gz compression and try to load it using stdout
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
|
2015-05-16 14:59:53 +00:00
|
|
|
name := "test-save-xz-gz-and-load-repo-stdout"
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
|
2014-12-08 20:40:27 +00:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to create a container: %v %v", out, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
repoName := "foobar-save-load-test-xz-gz"
|
|
|
|
|
2015-05-16 14:59:53 +00:00
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
|
2014-12-08 20:40:27 +00:00
|
|
|
out, _, err = runCommandWithOutput(commitCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to commit container: %v %v", out, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 14:59:53 +00:00
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
|
2014-12-08 20:40:27 +00:00
|
|
|
before, _, err := runCommandWithOutput(inspectCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("the repo should exist before saving it: %v %v", before, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
|
|
exec.Command("xz", "-c"),
|
|
|
|
exec.Command("gzip", "-c"))
|
2014-12-08 20:40:27 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save repo: %v %v", out, err)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteImages(repoName)
|
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
loadCmd := exec.Command(dockerBinary, "load")
|
|
|
|
loadCmd.Stdin = strings.NewReader(out)
|
2014-12-08 20:40:27 +00:00
|
|
|
out, _, err = runCommandWithOutput(loadCmd)
|
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("expected error, but succeeded with no error and output: %v", out)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
|
|
|
after, _, err := runCommandWithOutput(inspectCmd)
|
|
|
|
if err == nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("the repo should not exist: %v", after)
|
2014-12-08 20:40:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
2014-07-07 18:58:27 +00:00
|
|
|
repoName := "foobar-save-single-tag-test"
|
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
|
2014-10-14 20:22:06 +00:00
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
idCmd := exec.Command(dockerBinary, "images", "-q", "--no-trunc", repoName)
|
2014-10-14 20:22:06 +00:00
|
|
|
out, _, err := runCommandWithOutput(idCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to get repo ID: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedImageID := strings.TrimSpace(out)
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
|
|
|
exec.Command("tar", "t"),
|
|
|
|
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
2014-07-07 18:58:27 +00:00
|
|
|
repoName := "foobar-save-image-id-test"
|
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
|
2014-10-14 20:22:06 +00:00
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
idLongCmd := exec.Command(dockerBinary, "images", "-q", "--no-trunc", repoName)
|
2014-10-14 20:22:06 +00:00
|
|
|
out, _, err := runCommandWithOutput(idLongCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to get repo ID: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedLongImageID := strings.TrimSpace(out)
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
idShortCmd := exec.Command(dockerBinary, "images", "-q", repoName)
|
2014-07-07 18:58:27 +00:00
|
|
|
out, _, err = runCommandWithOutput(idShortCmd)
|
2014-10-14 20:22:06 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to get repo short ID: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedShortImageID := strings.TrimSpace(out)
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID)
|
|
|
|
tarCmd := exec.Command("tar", "t")
|
|
|
|
tarCmd.Stdin, err = saveCmd.StdoutPipe()
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("cannot set stdout pipe for tar: %v", err)
|
2015-02-14 22:25:13 +00:00
|
|
|
}
|
|
|
|
grepCmd := exec.Command("grep", cleanedLongImageID)
|
|
|
|
grepCmd.Stdin, err = tarCmd.StdoutPipe()
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("cannot set stdout pipe for grep: %v", err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
if err = tarCmd.Start(); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("tar failed with error: %v", err)
|
2015-02-14 22:25:13 +00:00
|
|
|
}
|
|
|
|
if err = saveCmd.Start(); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("docker save failed with error: %v", err)
|
2015-02-14 22:25:13 +00:00
|
|
|
}
|
|
|
|
defer saveCmd.Wait()
|
|
|
|
defer tarCmd.Wait()
|
|
|
|
|
|
|
|
out, _, err = runCommandWithOutput(grepCmd)
|
|
|
|
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save repo with image ID: %s, %v", out, err)
|
2015-02-14 22:25:13 +00:00
|
|
|
}
|
2014-07-07 18:58:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-06-17 01:01:38 +00:00
|
|
|
// save a repo and try to load it using flags
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
|
2015-05-16 14:59:53 +00:00
|
|
|
name := "test-save-and-load-repo-flags"
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "true")
|
2014-06-17 01:01:38 +00:00
|
|
|
out, _, err := runCommandWithOutput(runCmd)
|
2014-10-14 20:22:06 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to create a container: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-06-17 01:01:38 +00:00
|
|
|
repoName := "foobar-save-load-test"
|
|
|
|
|
2015-05-16 14:59:53 +00:00
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", name, repoName)
|
2015-02-14 22:25:13 +00:00
|
|
|
deleteImages(repoName)
|
2014-10-14 20:22:06 +00:00
|
|
|
if out, _, err = runCommandWithOutput(commitCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to commit container: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-06-17 01:01:38 +00:00
|
|
|
|
2015-05-16 14:59:53 +00:00
|
|
|
inspectCmd := exec.Command(dockerBinary, "inspect", repoName)
|
2014-06-17 01:01:38 +00:00
|
|
|
before, _, err := runCommandWithOutput(inspectCmd)
|
2014-10-14 20:22:06 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("the repo should exist before saving it: %s, %v", before, err)
|
2014-06-17 01:01:38 +00:00
|
|
|
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-06-17 01:01:38 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
|
|
exec.Command(dockerBinary, "load"))
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save and load repo: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-06-17 01:01:38 +00:00
|
|
|
|
|
|
|
inspectCmd = exec.Command(dockerBinary, "inspect", repoName)
|
|
|
|
after, _, err := runCommandWithOutput(inspectCmd)
|
2014-10-14 20:22:06 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("the repo should exist after loading it: %s, %v", after, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-06-17 01:01:38 +00:00
|
|
|
|
|
|
|
if before != after {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("inspect is not the same after a save / load")
|
2014-06-17 01:01:38 +00:00
|
|
|
}
|
2014-02-25 16:17:48 +00:00
|
|
|
}
|
2014-08-29 01:33:13 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
2014-08-29 01:33:13 +00:00
|
|
|
repoName := "foobar-save-multi-name-test"
|
|
|
|
|
|
|
|
// Make one image
|
2015-02-14 22:25:13 +00:00
|
|
|
tagCmd := exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-one:latest", repoName))
|
2014-10-14 20:22:06 +00:00
|
|
|
if out, _, err := runCommandWithOutput(tagCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-11-17 16:05:49 +00:00
|
|
|
|
2014-08-29 01:33:13 +00:00
|
|
|
// Make two images
|
2015-02-14 22:25:13 +00:00
|
|
|
tagCmd = exec.Command(dockerBinary, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
|
|
|
|
out, _, err := runCommandWithOutput(tagCmd)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to tag repo: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-08-29 01:33:13 +00:00
|
|
|
|
2015-02-14 22:25:13 +00:00
|
|
|
out, _, err = runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
|
|
|
|
exec.Command("tar", "xO", "repositories"),
|
|
|
|
exec.Command("grep", "-q", "-E", "(-one|-two)"),
|
|
|
|
)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save multiple repos: %s, %v", out, err)
|
2014-10-14 20:22:06 +00:00
|
|
|
}
|
2014-08-29 01:33:13 +00:00
|
|
|
|
|
|
|
}
|
2014-09-06 11:49:40 +00:00
|
|
|
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
2014-11-11 09:18:22 +00:00
|
|
|
|
|
|
|
makeImage := func(from string, tag string) string {
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", from, "true")
|
|
|
|
var (
|
|
|
|
out string
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if out, _, err = runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to create a container: %v %v", out, err)
|
2014-11-11 09:18:22 +00:00
|
|
|
}
|
2015-04-06 13:21:18 +00:00
|
|
|
cleanedContainerID := strings.TrimSpace(out)
|
2014-11-11 09:18:22 +00:00
|
|
|
|
|
|
|
commitCmd := exec.Command(dockerBinary, "commit", cleanedContainerID, tag)
|
|
|
|
if out, _, err = runCommandWithOutput(commitCmd); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to commit container: %v %v", out, err)
|
2014-11-11 09:18:22 +00:00
|
|
|
}
|
2015-04-06 13:21:18 +00:00
|
|
|
imageID := strings.TrimSpace(out)
|
2014-11-11 09:18:22 +00:00
|
|
|
return imageID
|
|
|
|
}
|
|
|
|
|
|
|
|
repoName := "foobar-save-multi-images-test"
|
|
|
|
tagFoo := repoName + ":foo"
|
|
|
|
tagBar := repoName + ":bar"
|
|
|
|
|
|
|
|
idFoo := makeImage("busybox:latest", tagFoo)
|
|
|
|
idBar := makeImage("busybox:latest", tagBar)
|
|
|
|
|
|
|
|
deleteImages(repoName)
|
|
|
|
|
|
|
|
// create the archive
|
2015-02-14 22:25:13 +00:00
|
|
|
out, _, err := runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
|
|
exec.Command("tar", "t"),
|
|
|
|
exec.Command("grep", "VERSION"),
|
|
|
|
exec.Command("cut", "-d", "/", "-f1"))
|
2014-11-11 09:18:22 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to save multiple images: %s, %v", out, err)
|
2014-11-11 09:18:22 +00:00
|
|
|
}
|
2015-04-06 13:21:18 +00:00
|
|
|
actual := strings.Split(strings.TrimSpace(out), "\n")
|
2014-11-11 09:18:22 +00:00
|
|
|
|
|
|
|
// make the list of expected layers
|
2015-02-14 22:25:13 +00:00
|
|
|
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "history", "-q", "--no-trunc", "busybox:latest"))
|
2014-11-11 09:18:22 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to get history: %s, %v", out, err)
|
2014-11-11 09:18:22 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 13:21:18 +00:00
|
|
|
expected := append(strings.Split(strings.TrimSpace(out), "\n"), idFoo, idBar)
|
2014-11-11 09:18:22 +00:00
|
|
|
|
|
|
|
sort.Strings(actual)
|
|
|
|
sort.Strings(expected)
|
|
|
|
if !reflect.DeepEqual(expected, actual) {
|
2015-04-27 20:33:30 +00:00
|
|
|
c.Fatalf("archive does not contains the right layers: got %v, expected %v", actual, expected)
|
2014-11-11 09:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-06 11:49:40 +00:00
|
|
|
// Issue #6722 #5892 ensure directories are included in changes
|
2015-04-18 16:46:47 +00:00
|
|
|
func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
2014-09-06 11:49:40 +00:00
|
|
|
layerEntries := []string{"opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"}
|
2014-09-19 18:08:57 +00:00
|
|
|
layerEntriesAUFS := []string{"./", ".wh..wh.aufs", ".wh..wh.orph/", ".wh..wh.plnk/", "opt/", "opt/a/", "opt/a/b/", "opt/a/b/c"}
|
2014-09-06 11:49:40 +00:00
|
|
|
|
|
|
|
name := "save-directory-permissions"
|
|
|
|
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("failed to create temporary directory: %s", err)
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
2014-10-14 20:22:06 +00:00
|
|
|
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
|
|
|
|
os.Mkdir(extractionDirectory, 0777)
|
|
|
|
|
2014-09-06 11:49:40 +00:00
|
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
_, err = buildImage(name,
|
|
|
|
`FROM busybox
|
|
|
|
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
|
|
|
|
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`,
|
|
|
|
true)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatal(err)
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 23:52:06 +00:00
|
|
|
if out, _, err := runCommandPipelineWithOutput(
|
|
|
|
exec.Command(dockerBinary, "save", name),
|
|
|
|
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
|
|
|
|
); err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("failed to save and extract image: %s", out)
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dirs, err := ioutil.ReadDir(extractionDirectory)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Errorf("failed to get a listing of the layer directories: %s", err)
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
found := false
|
|
|
|
for _, entry := range dirs {
|
2015-02-25 23:53:07 +00:00
|
|
|
var entriesSansDev []string
|
2014-09-06 11:49:40 +00:00
|
|
|
if entry.IsDir() {
|
|
|
|
layerPath := filepath.Join(extractionDirectory, entry.Name(), "layer.tar")
|
|
|
|
|
|
|
|
f, err := os.Open(layerPath)
|
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to open %s: %s", layerPath, err)
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
entries, err := ListTar(f)
|
2015-02-02 00:42:35 +00:00
|
|
|
for _, e := range entries {
|
|
|
|
if !strings.Contains(e, "dev/") {
|
|
|
|
entriesSansDev = append(entriesSansDev, e)
|
|
|
|
}
|
|
|
|
}
|
2014-09-06 11:49:40 +00:00
|
|
|
if err != nil {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("encountered error while listing tar entries: %s", err)
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 00:42:35 +00:00
|
|
|
if reflect.DeepEqual(entriesSansDev, layerEntries) || reflect.DeepEqual(entriesSansDev, layerEntriesAUFS) {
|
2014-09-06 11:49:40 +00:00
|
|
|
found = true
|
2014-09-19 18:08:57 +00:00
|
|
|
break
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
2015-04-18 16:46:47 +00:00
|
|
|
c.Fatalf("failed to find the layer with the right content listing")
|
2014-09-06 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|