|
@@ -1,8 +1,10 @@
|
|
package main
|
|
package main
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "archive/tar"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"os"
|
|
"os"
|
|
"os/exec"
|
|
"os/exec"
|
|
@@ -15,10 +17,9 @@ import (
|
|
|
|
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
"github.com/docker/docker/integration-cli/checker"
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
|
"github.com/docker/docker/integration-cli/cli/build"
|
|
- "github.com/docker/docker/pkg/testutil"
|
|
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
|
icmd "github.com/docker/docker/pkg/testutil/cmd"
|
|
"github.com/go-check/check"
|
|
"github.com/go-check/check"
|
|
- "github.com/opencontainers/go-digest"
|
|
|
|
|
|
+ digest "github.com/opencontainers/go-digest"
|
|
)
|
|
)
|
|
|
|
|
|
// save a repo using gz compression and try to load it using stdout
|
|
// save a repo using gz compression and try to load it using stdout
|
|
@@ -32,7 +33,7 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
|
|
|
|
|
|
dockerCmd(c, "inspect", repoName)
|
|
dockerCmd(c, "inspect", repoName)
|
|
|
|
|
|
- repoTarball, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ repoTarball, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command("xz", "-c"),
|
|
exec.Command("xz", "-c"),
|
|
exec.Command("gzip", "-c"))
|
|
exec.Command("gzip", "-c"))
|
|
@@ -61,7 +62,7 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
|
|
|
|
|
|
dockerCmd(c, "inspect", repoName)
|
|
dockerCmd(c, "inspect", repoName)
|
|
|
|
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command("xz", "-c"),
|
|
exec.Command("xz", "-c"),
|
|
exec.Command("gzip", "-c"))
|
|
exec.Command("gzip", "-c"))
|
|
@@ -88,7 +89,7 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
|
out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName)
|
|
out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName)
|
|
cleanedImageID := strings.TrimSpace(out)
|
|
cleanedImageID := strings.TrimSpace(out)
|
|
|
|
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
|
exec.Command("tar", "t"),
|
|
exec.Command("tar", "t"),
|
|
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
|
|
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
|
|
@@ -107,7 +108,7 @@ func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
|
|
c.Assert(len(data), checker.Not(checker.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
|
|
c.Assert(len(data), checker.Not(checker.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
|
|
tarTvTimeFormat := "2006-01-02 15:04"
|
|
tarTvTimeFormat := "2006-01-02 15:04"
|
|
- out, _, err = testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err = RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command("tar", "tv"),
|
|
exec.Command("tar", "tv"),
|
|
exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), digest.Digest(data[0].ID).Hex())))
|
|
exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), digest.Digest(data[0].ID).Hex())))
|
|
@@ -165,7 +166,7 @@ func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
|
|
|
|
|
|
before, _ := dockerCmd(c, "inspect", repoName)
|
|
before, _ := dockerCmd(c, "inspect", repoName)
|
|
|
|
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command(dockerBinary, "save", repoName),
|
|
exec.Command(dockerBinary, "load"))
|
|
exec.Command(dockerBinary, "load"))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
|
@@ -194,7 +195,7 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
|
// Make two images
|
|
// Make two images
|
|
dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
|
|
dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v-two:latest", repoName))
|
|
|
|
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
|
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v-one", repoName), fmt.Sprintf("%v-two:latest", repoName)),
|
|
exec.Command("tar", "xO", "repositories"),
|
|
exec.Command("tar", "xO", "repositories"),
|
|
exec.Command("grep", "-q", "-E", "(-one|-two)"),
|
|
exec.Command("grep", "-q", "-E", "(-one|-two)"),
|
|
@@ -226,7 +227,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
|
deleteImages(repoName)
|
|
deleteImages(repoName)
|
|
|
|
|
|
// create the archive
|
|
// create the archive
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", repoName, "busybox:latest"),
|
|
exec.Command(dockerBinary, "save", repoName, "busybox:latest"),
|
|
exec.Command("tar", "t"))
|
|
exec.Command("tar", "t"))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple images: %s, %v", out, err))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple images: %s, %v", out, err))
|
|
@@ -270,7 +271,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
|
|
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`))
|
|
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`))
|
|
|
|
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", name),
|
|
exec.Command(dockerBinary, "save", name),
|
|
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
|
|
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
|
|
)
|
|
)
|
|
@@ -289,7 +290,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
|
|
defer f.Close()
|
|
defer f.Close()
|
|
|
|
|
|
- entries, err := testutil.ListTar(f)
|
|
|
|
|
|
+ entries, err := listTar(f)
|
|
for _, e := range entries {
|
|
for _, e := range entries {
|
|
if !strings.Contains(e, "dev/") {
|
|
if !strings.Contains(e, "dev/") {
|
|
entriesSansDev = append(entriesSansDev, e)
|
|
entriesSansDev = append(entriesSansDev, e)
|
|
@@ -308,6 +309,23 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func listTar(f io.Reader) ([]string, error) {
|
|
|
|
+ tr := tar.NewReader(f)
|
|
|
|
+ var entries []string
|
|
|
|
+
|
|
|
|
+ for {
|
|
|
|
+ th, err := tr.Next()
|
|
|
|
+ if err == io.EOF {
|
|
|
|
+ // end of tar archive
|
|
|
|
+ return entries, nil
|
|
|
|
+ }
|
|
|
|
+ if err != nil {
|
|
|
|
+ return entries, err
|
|
|
|
+ }
|
|
|
|
+ entries = append(entries, th.Name)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// Test loading a weird image where one of the layers is of zero size.
|
|
// Test loading a weird image where one of the layers is of zero size.
|
|
// The layer.tar file is actually zero bytes, no padding or anything else.
|
|
// The layer.tar file is actually zero bytes, no padding or anything else.
|
|
// See issue: 18170
|
|
// See issue: 18170
|
|
@@ -365,7 +383,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
|
id := inspectField(c, name, "Id")
|
|
id := inspectField(c, name, "Id")
|
|
|
|
|
|
// Test to make sure that save w/o name just shows imageID during load
|
|
// Test to make sure that save w/o name just shows imageID during load
|
|
- out, _, err := testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err := RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", id),
|
|
exec.Command(dockerBinary, "save", id),
|
|
exec.Command(dockerBinary, "load"))
|
|
exec.Command(dockerBinary, "load"))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
|
@@ -376,7 +394,7 @@ func (s *DockerSuite) TestSaveLoadNoTag(c *check.C) {
|
|
c.Assert(out, checker.Contains, id)
|
|
c.Assert(out, checker.Contains, id)
|
|
|
|
|
|
// Test to make sure that save by name shows that name during load
|
|
// Test to make sure that save by name shows that name during load
|
|
- out, _, err = testutil.RunCommandPipelineWithOutput(
|
|
|
|
|
|
+ out, err = RunCommandPipelineWithOutput(
|
|
exec.Command(dockerBinary, "save", name),
|
|
exec.Command(dockerBinary, "save", name),
|
|
exec.Command(dockerBinary, "load"))
|
|
exec.Command(dockerBinary, "load"))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|