diff --git a/integration/copy_test.go b/integration/copy_test.go index f7e337e1..9100543c 100644 --- a/integration/copy_test.go +++ b/integration/copy_test.go @@ -15,9 +15,12 @@ func init() { check.Suite(&CopySuite{}) } +const v2DockerRegistryURL = "localhost:5555" + type CopySuite struct { - cluster *openshiftCluster - gpgHome string + cluster *openshiftCluster + registry *testRegistryV2 + gpgHome string } func (s *CopySuite) SetUpSuite(c *check.C) { @@ -27,7 +30,7 @@ func (s *CopySuite) SetUpSuite(c *check.C) { s.cluster = startOpenshiftCluster(c) // FIXME: Set up TLS for the docker registry port instead of using "--tls-verify=false" all over the place. - for _, stream := range []string{"unsigned", "personal", "official", "naming", "cosigned"} { + for _, stream := range []string{"unsigned", "personal", "official", "naming", "cosigned", "compression"} { isJSON := fmt.Sprintf(`{ "kind": "ImageStream", "apiVersion": "v1", @@ -39,6 +42,8 @@ func (s *CopySuite) SetUpSuite(c *check.C) { runCommandWithInput(c, isJSON, "oc", "create", "-f", "-") } + s.registry = setupRegistryV2At(c, v2DockerRegistryURL, false, false) // FIXME: Set up TLS for the docker registry port instead of using "--tls-verify=false" all over the place. + gpgHome, err := ioutil.TempDir("", "skopeo-gpg") c.Assert(err, check.IsNil) s.gpgHome = gpgHome @@ -60,6 +65,9 @@ func (s *CopySuite) TearDownSuite(c *check.C) { if s.gpgHome != "" { os.RemoveAll(s.gpgHome) } + if s.registry != nil { + s.registry.Close() + } if s.cluster != nil { s.cluster.tearDown() } @@ -242,3 +250,44 @@ func (s *CopySuite) TestCopyDirSignatures(c *check.C) { assertSkopeoFails(c, ".*Source image rejected: .*Signature for identity localhost:5000/myns/personal:dirstaging2 is not accepted.*", "--policy", policy, "copy", topDirDest+"/restricted/badidentity", topDirDest+"/dest") } + +// Compression during copy +func (s *CopySuite) TestCopyCompression(c *check.C) { + const uncompresssedLayerFile = "160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar" + + topDir, err := ioutil.TempDir("", "compression-top") + c.Assert(err, check.IsNil) + defer os.RemoveAll(topDir) + + for i, t := range []struct{ fixture, remote string }{ + //{"uncompressed-image-s1", "docker://" + v2DockerRegistryURL + "/compression/compression:s1"}, // FIXME: depends on push to tag working + //{"uncompressed-image-s2", "docker://" + v2DockerRegistryURL + "/compression/compression:s2"}, // FIXME: depends on push to tag working + {"uncompressed-image-s1", "atomic:localhost:5000/myns/compression:s1"}, + //{"uncompressed-image-s2", "atomic:localhost:5000/myns/compression:s2"}, // FIXME: The unresolved "MANIFEST_UNKNOWN"/"unexpected end of JSON input" failure + } { + dir := filepath.Join(topDir, fmt.Sprintf("case%d", i)) + err := os.MkdirAll(dir, 0755) + c.Assert(err, check.IsNil) + + assertSkopeoSucceeds(c, "", "--tls-verify=false", "copy", "dir:fixtures/"+t.fixture, t.remote) + assertSkopeoSucceeds(c, "", "--tls-verify=false", "copy", t.remote, "dir:"+dir) + + // The original directory contained an uncompressed file, the copy after pushing and pulling doesn't (we use a different name for the compressed file). + _, err = os.Lstat(filepath.Join("fixtures", t.fixture, uncompresssedLayerFile)) + c.Assert(err, check.IsNil) + _, err = os.Lstat(filepath.Join(dir, uncompresssedLayerFile)) + c.Assert(err, check.NotNil) + c.Assert(os.IsNotExist(err), check.Equals, true) + + // All pulled layers are smaller than the uncompressed size of uncompresssedLayerFile. (Note that this includes the manifest in s2, but that works out OK). + dirf, err := os.Open(dir) + c.Assert(err, check.IsNil) + fis, err := dirf.Readdir(-1) + c.Assert(err, check.IsNil) + for _, fi := range fis { + if strings.HasSuffix(fi.Name(), ".tar") { + c.Assert(fi.Size() < 2048, check.Equals, true) + } + } + } +} diff --git a/integration/fixtures/uncompressed-image-s1/160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar b/integration/fixtures/uncompressed-image-s1/160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar new file mode 100644 index 00000000..58342e8d Binary files /dev/null and b/integration/fixtures/uncompressed-image-s1/160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar differ diff --git a/integration/fixtures/uncompressed-image-s1/manifest.json b/integration/fixtures/uncompressed-image-s1/manifest.json new file mode 100644 index 00000000..b3d2b035 --- /dev/null +++ b/integration/fixtures/uncompressed-image-s1/manifest.json @@ -0,0 +1,32 @@ +{ + "schemaVersion": 1, + "name": "nonempty", + "tag": "nonempty", + "architecture": "amd64", + "fsLayers": [ + { + "blobSum": "sha256:160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710" + } + ], + "history": [ + { + "v1Compatibility": "{\"architecture\":\"amd64\",\"config\":{\"Hostname\":\"59c20544b2f4\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"],\"Cmd\":null,\"Image\":\"\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":null},\"container\":\"59c20544b2f4ad7a8639433bacb1ec215b7dad4a7bf1a83b5ab4679329a46c1d\",\"container_config\":{\"Hostname\":\"59c20544b2f4\",\"Domainname\":\"\",\"User\":\"\",\"AttachStdin\":false,\"AttachStdout\":false,\"AttachStderr\":false,\"Tty\":false,\"OpenStdin\":false,\"StdinOnce\":false,\"Env\":[\"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"],\"Cmd\":[\"/bin/sh\",\"-c\",\"#(nop) ADD file:14f49faade3db5e596826746d9ed3dfd658490c16c4d61d4886726153ad0591a in /\"],\"Image\":\"\",\"Volumes\":null,\"WorkingDir\":\"\",\"Entrypoint\":null,\"OnBuild\":null,\"Labels\":null},\"created\":\"2016-09-19T18:23:54.9949213Z\",\"docker_version\":\"1.10.3\",\"id\":\"4c224eac5061bb85f523ca4e3316618fd7921a80fe94286979667b1edb8e1bdd\",\"os\":\"linux\"}" + } + ], + "signatures": [ + { + "header": { + "jwk": { + "crv": "P-256", + "kid": "DGWZ:GAUM:WCOC:IMDL:D67M:CEI6:YTVH:M2CM:5HX4:FYDD:77OD:D3F7", + "kty": "EC", + "x": "eprZNqLO9mHZ4Z4GxefucEgov_1gwEi9lehpJR2suRo", + "y": "wIr2ucNg32ROfVCkR_8A5VbBJ-mFmsoIUVa6vt8lIxM" + }, + "alg": "ES256" + }, + "signature": "bvTLWW4YVFRjAanN1EJqwQw60fWSWJPxcGO3UZGFI_gyV6ucGdW4x7jyYL6g06sg925s9cy0wN1lw91CCFv4BA", + "protected": "eyJmb3JtYXRMZW5ndGgiOjE0ODcsImZvcm1hdFRhaWwiOiJDbjBLIiwidGltZSI6IjIwMTYtMDktMTlUMTg6NDM6MzNaIn0" + } + ] +} \ No newline at end of file diff --git a/integration/fixtures/uncompressed-image-s2/160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar b/integration/fixtures/uncompressed-image-s2/160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar new file mode 100644 index 00000000..58342e8d Binary files /dev/null and b/integration/fixtures/uncompressed-image-s2/160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710.tar differ diff --git a/integration/fixtures/uncompressed-image-s2/86ce150e65c72b30f885c261449d18b7c6832596916e7f654e08377b5a67b4ff.tar b/integration/fixtures/uncompressed-image-s2/86ce150e65c72b30f885c261449d18b7c6832596916e7f654e08377b5a67b4ff.tar new file mode 100644 index 00000000..ecd4aa27 --- /dev/null +++ b/integration/fixtures/uncompressed-image-s2/86ce150e65c72b30f885c261449d18b7c6832596916e7f654e08377b5a67b4ff.tar @@ -0,0 +1 @@ +{"architecture":"amd64","config":{"Hostname":"59c20544b2f4","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":null,"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"container":"59c20544b2f4ad7a8639433bacb1ec215b7dad4a7bf1a83b5ab4679329a46c1d","container_config":{"Hostname":"59c20544b2f4","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"Tty":false,"OpenStdin":false,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"Cmd":["/bin/sh","-c","#(nop) ADD file:14f49faade3db5e596826746d9ed3dfd658490c16c4d61d4886726153ad0591a in /"],"Image":"","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":null},"created":"2016-09-19T18:23:54.9949213Z","docker_version":"1.10.3","history":[{"created":"2016-09-19T18:23:54.9949213Z","created_by":"/bin/sh -c #(nop) ADD file:14f49faade3db5e596826746d9ed3dfd658490c16c4d61d4886726153ad0591a in /"}],"os":"linux","rootfs":{"type":"layers","diff_ids":["sha256:160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710"]}} \ No newline at end of file diff --git a/integration/fixtures/uncompressed-image-s2/manifest.json b/integration/fixtures/uncompressed-image-s2/manifest.json new file mode 100644 index 00000000..7a033e6c --- /dev/null +++ b/integration/fixtures/uncompressed-image-s2/manifest.json @@ -0,0 +1,16 @@ +{ + "schemaVersion": 2, + "mediaType": "application/vnd.docker.distribution.manifest.v2+json", + "config": { + "mediaType": "application/octet-stream", + "size": 1272, + "digest": "sha256:86ce150e65c72b30f885c261449d18b7c6832596916e7f654e08377b5a67b4ff" + }, + "layers": [ + { + "mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip", + "size": 2048, + "digest": "sha256:160d823fdc48e62f97ba62df31e55424f8f5eb6b679c865eec6e59adfe304710" + } + ] +}