Merge pull request #8100 from QiWang19/mirror-manifest

manifest list inspect single image
This commit is contained in:
OpenShift Merge Robot
2020-10-31 00:19:52 +01:00
committed by GitHub
2 changed files with 20 additions and 8 deletions

View File

@ -25,6 +25,7 @@ import (
"github.com/containers/podman/v2/pkg/domain/entities" "github.com/containers/podman/v2/pkg/domain/entities"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1" imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/sirupsen/logrus"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -90,10 +91,6 @@ func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte
continue continue
} }
if !manifest.MIMETypeIsMultiImage(manifestType) {
appendErr(errors.Errorf("manifest is of type %s (not a list type)", manifestType))
continue
}
result = manifestBytes result = manifestBytes
manType = manifestType manType = manifestType
break break
@ -101,7 +98,18 @@ func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte
if len(result) == 0 && latestErr != nil { if len(result) == 0 && latestErr != nil {
return nil, latestErr return nil, latestErr
} }
if manType != manifest.DockerV2ListMediaType {
switch manType {
case manifest.DockerV2Schema2MediaType:
logrus.Warnf("Warning! The manifest type %s is not a manifest list but a single image.", manType)
schema2Manifest, err := manifest.Schema2FromManifest(result)
if err != nil {
return nil, errors.Wrapf(err, "error parsing manifest blob %q as a %q", string(result), manType)
}
if result, err = schema2Manifest.Serialize(); err != nil {
return nil, err
}
default:
listBlob, err := manifest.ListFromBlob(result, manType) listBlob, err := manifest.ListFromBlob(result, manType)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "error parsing manifest blob %q as a %q", string(result), manType) return nil, errors.Wrapf(err, "error parsing manifest blob %q as a %q", string(result), manType)
@ -113,10 +121,9 @@ func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte
if result, err = list.Serialize(); err != nil { if result, err = list.Serialize(); err != nil {
return nil, err return nil, err
} }
} }
err = json.Indent(&b, result, "", " ")
if err != nil { if err = json.Indent(&b, result, "", " "); err != nil {
return nil, errors.Wrapf(err, "error rendering manifest %s for display", name) return nil, errors.Wrapf(err, "error rendering manifest %s for display", name)
} }
return b.Bytes(), nil return b.Bytes(), nil

View File

@ -58,6 +58,11 @@ var _ = Describe("Podman manifest", func() {
session = podmanTest.PodmanNoCache([]string{"manifest", "inspect", "quay.io/libpod/busybox"}) session = podmanTest.PodmanNoCache([]string{"manifest", "inspect", "quay.io/libpod/busybox"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0)) Expect(session).Should(Exit(0))
// inspect manifest of single image
session = podmanTest.PodmanNoCache([]string{"manifest", "inspect", "quay.io/libpod/busybox@sha256:6655df04a3df853b029a5fac8836035ac4fab117800c9a6c4b69341bb5306c3d"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
}) })
It("podman manifest add", func() { It("podman manifest add", func() {