From 0808747add96562cd425396c6dd162f910a4bd9d Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 28 May 2024 23:01:14 -0400 Subject: [PATCH] Added application/vnd.docker.distribution.manifest.v2+json mediatype to the list of mediatypes we return the original bytes for when calling *Resolver.Combine rather than adding it to a newly created manifest list Signed-off-by: Tim Smith --- tests/imagetools.go | 36 +++++++++++++----------------------- util/imagetools/create.go | 2 +- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/imagetools.go b/tests/imagetools.go index b6d21b49..cca1c75b 100644 --- a/tests/imagetools.go +++ b/tests/imagetools.go @@ -61,23 +61,7 @@ func testImagetoolsCopyManifest(t *testing.T, sb integration.Sandbox) { var idx2 ocispecs.Index err = json.Unmarshal(dt, &idx2) require.NoError(t, err) - require.Equal(t, images.MediaTypeDockerSchema2ManifestList, idx2.MediaType) - require.Equal(t, 1, len(idx2.Manifests)) - - cmd = buildxCmd(sb, withArgs("imagetools", "inspect", target2+"@"+string(idx2.Manifests[0].Digest), "--raw")) - dt, err = cmd.CombinedOutput() - require.NoError(t, err, string(dt)) - - var mfst2 ocispecs.Manifest - err = json.Unmarshal(dt, &mfst2) - require.NoError(t, err) - require.Equal(t, images.MediaTypeDockerSchema2Manifest, mfst2.MediaType) - - require.Equal(t, mfst.Config.Digest, mfst2.Config.Digest) - require.Equal(t, len(mfst.Layers), len(mfst2.Layers)) - for i := range mfst.Layers { - require.Equal(t, mfst.Layers[i].Digest, mfst2.Layers[i].Digest) - } + require.Equal(t, images.MediaTypeDockerSchema2Manifest, idx2.MediaType) } func testImagetoolsCopyIndex(t *testing.T, sb integration.Sandbox) { @@ -161,7 +145,15 @@ func testImagetoolsInspectAndFilter(t *testing.T, sb integration.Sandbox) { mfst = idx.Manifests[1] require.Equal(t, "linux/arm64", platforms.Format(*mfst.Platform)) - // create amd64 only image + cmd = buildxCmd(sb, withArgs("imagetools", "inspect", target+"@"+string(idx.Manifests[1].Digest), "--raw")) + dt, err = cmd.CombinedOutput() + require.NoError(t, err, string(dt)) + + var armMfst ocispecs.Manifest + err = json.Unmarshal(dt, &armMfst) + require.NoError(t, err) + + // create arm64 only image cmd = buildxCmd(sb, withArgs("imagetools", "create", "-t", target+"-arm64", target+"@"+string(idx.Manifests[1].Digest))) dt, err = cmd.CombinedOutput() require.NoError(t, err, string(dt)) @@ -170,14 +162,12 @@ func testImagetoolsInspectAndFilter(t *testing.T, sb integration.Sandbox) { dt, err = cmd.CombinedOutput() require.NoError(t, err, string(dt)) - var idx2 ocispecs.Index + var idx2 ocispecs.Manifest err = json.Unmarshal(dt, &idx2) require.NoError(t, err) - require.Equal(t, 1, len(idx2.Manifests)) - - require.Equal(t, idx.Manifests[1].Digest, idx2.Manifests[0].Digest) - require.Equal(t, platforms.Format(*idx.Manifests[1].Platform), platforms.Format(*idx2.Manifests[0].Platform)) + require.Equal(t, armMfst.Config.Digest, idx2.Config.Digest) + require.Equal(t, armMfst.MediaType, idx2.MediaType) } func testImagetoolsAnnotation(t *testing.T, sb integration.Sandbox) { diff --git a/util/imagetools/create.go b/util/imagetools/create.go index d1e8dfaa..a8c3241d 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -79,7 +79,7 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann []string) ([ // on single source, return original bytes if len(srcs) == 1 && len(ann) == 0 { - if mt := srcs[0].Desc.MediaType; mt == images.MediaTypeDockerSchema2ManifestList || mt == ocispec.MediaTypeImageIndex { + if mt := srcs[0].Desc.MediaType; mt == images.MediaTypeDockerSchema2ManifestList || mt == images.MediaTypeDockerSchema2Manifest || mt == ocispec.MediaTypeImageIndex { return dts[0], srcs[0].Desc, nil } }