Skip to content

Commit

Permalink
manifest_list: inspect should contain formats OCIv1 and docker
Browse files Browse the repository at this point in the history
ManifestInspect should contain all known formats for a valid manifest
list as of now only supported formats are `OCIv1` and `Docker` so
inspect should support that.

Example output from podman
```console
podman manifest inspect test
{
    "ociv1": {
        "schemaVersion": 2,
        "mediaType": "application/vnd.oci.image.index.v1+json",
        "manifests": [
            {
                "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
                "digest": "sha256:9b2a28eb47540823042a2ba401386845089bb7b62a9637d55816132c4c3c36eb",
                "size": 528,
                "annotations": {
                    "annotationTest1": "annotationTest2"
                },
                "platform": {
                    "architecture": "amd64",
                    "os": "linux"
                }
            }
        ]
    },
    "docker": {
        "schemaVersion": 2,
        "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
        "manifests": [
            {
                "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
                "size": 528,
                "digest": "sha256:9b2a28eb47540823042a2ba401386845089bb7b62a9637d55816132c4c3c36eb",
                "platform": {
                    "architecture": "amd64",
                    "os": "linux"
                }
            }
        ]
    }
}
```

Closes: containers/podman#15069

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Jul 28, 2022
1 parent a043189 commit 9bbd67c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
11 changes: 9 additions & 2 deletions libimage/manifest_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/containers/image/v5/types"
"github.com/containers/storage"
"github.com/opencontainers/go-digest"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
)

// NOTE: the abstractions and APIs here are a first step to further merge
Expand All @@ -39,6 +40,12 @@ type ManifestList struct {
list manifests.List
}

// Manifest metadata, spec and settings, in multiple formats.
type ManifestInspectReport struct {
OCIv1 *v1.Index `json:"ociv1,omitempty"`
Docker *manifest.Schema2List `json:"docker,omitempty"`
}

// ID returns the ID of the manifest list.
func (m *ManifestList) ID() string {
return m.image.ID()
Expand Down Expand Up @@ -210,8 +217,8 @@ func (i *Image) IsManifestList(ctx context.Context) (bool, error) {
}

// Inspect returns a dockerized version of the manifest list.
func (m *ManifestList) Inspect() (*manifest.Schema2List, error) {
return m.list.Docker(), nil
func (m *ManifestList) Inspect() (ManifestInspectReport, error) {
return ManifestInspectReport{m.list.OCIv1(), m.list.Docker()}, nil
}

// Options for adding a manifest list.
Expand Down
30 changes: 30 additions & 0 deletions libimage/manifest_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ func TestCreateManifestList(t *testing.T) {
require.True(t, errors.Is(err, ErrNotAManifestList))
}

// Inspect must contain both formats i.e OCIv1 and docker
func TestCreateAndInspectManifestListt(t *testing.T) {
listName := "testInspect"
runtime, cleanup := testNewRuntime(t)
defer cleanup()
ctx := context.Background()

list, err := runtime.CreateManifestList(listName)
require.NoError(t, err)
require.NotNil(t, list)

manifestListOpts := &ManifestListAddOptions{All: true}
_, err = list.Add(ctx, "docker://busybox", manifestListOpts)
require.NoError(t, err)

list, err = runtime.LookupManifestList(listName)
require.NoError(t, err)
require.NotNil(t, list)

inspectReport, err := list.Inspect()
require.NoError(t, err)
require.NotNil(t, inspectReport)

inspectReportJSON, err := json.Marshal(inspectReport)
require.NoError(t, err)
inspectReportString := string(inspectReportJSON)
require.Contains(t, inspectReportString, "ociv1")
require.Contains(t, inspectReportString, "docker")
}

// Following test ensure that `Tag` tags the manifest list instead of resolved image.
// Both the tags should point to same image id
func TestCreateAndTagManifestList(t *testing.T) {
Expand Down

0 comments on commit 9bbd67c

Please sign in to comment.