Remove a dependency on libimage from pkg/bindings

... by updating for a c/common API change.

[NO NEW TESTS NEEDED]: Only moves unchanged code,
should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2023-08-28 23:22:42 +02:00
parent b4aed53ea6
commit a3c2d6ad2e
9 changed files with 45 additions and 37 deletions

View File

@ -0,0 +1,27 @@
package define
import (
"github.com/containers/image/v5/manifest"
)
// ManifestListDescriptor references a platform-specific manifest.
// Contains exclusive field like `annotations` which is only present in
// OCI spec and not in docker image spec.
type ManifestListDescriptor struct {
manifest.Schema2Descriptor
Platform manifest.Schema2PlatformSpec `json:"platform"`
// Annotations contains arbitrary metadata for the image index.
Annotations map[string]string `json:"annotations,omitempty"`
}
// ManifestListData is a list of platform-specific manifests, specifically used to
// generate output struct for `podman manifest inspect`. Reason for maintaining and
// having this type is to ensure we can have a common type which contains exclusive
// fields from both Docker manifest format and OCI manifest format.
type ManifestListData struct {
SchemaVersion int `json:"schemaVersion"`
MediaType string `json:"mediaType"`
Manifests []ManifestListDescriptor `json:"manifests"`
// Annotations contains arbitrary metadata for the image index.
Annotations map[string]string `json:"annotations,omitempty"`
}

View File

@ -91,13 +91,14 @@ func (i *Image) isCorrupted(name string) error {
return err
}
if _, err := ref.NewImage(context.Background(), nil); err != nil {
img, err := ref.NewImage(context.Background(), nil)
if err != nil {
if name == "" {
name = i.ID()[:12]
}
return fmt.Errorf("Image %s exists in local storage but may be corrupted (remove the image to resolve the issue): %v", name, err)
}
return nil
return img.Close()
}
// Names returns associated names with the image which may be a mix of tags and
@ -872,6 +873,7 @@ func (i *Image) hasDifferentDigestWithSystemContext(ctx context.Context, remoteR
if err != nil {
return false, err
}
defer remoteImg.Close()
rawManifest, rawManifestMIMEType, err := remoteImg.Manifest(ctx)
if err != nil {

View File

@ -6,6 +6,7 @@ import (
"fmt"
"time"
"github.com/containers/common/libimage/define"
"github.com/containers/common/libimage/manifests"
imageCopy "github.com/containers/image/v5/copy"
"github.com/containers/image/v5/docker"
@ -40,28 +41,6 @@ type ManifestList struct {
list manifests.List
}
// ManifestListDescriptor references a platform-specific manifest.
// Contains exclusive field like `annotations` which is only present in
// OCI spec and not in docker image spec.
type ManifestListDescriptor struct {
manifest.Schema2Descriptor
Platform manifest.Schema2PlatformSpec `json:"platform"`
// Annotations contains arbitrary metadata for the image index.
Annotations map[string]string `json:"annotations,omitempty"`
}
// ManifestListData is a list of platform-specific manifests, specifically used to
// generate output struct for `podman manifest inspect`. Reason for maintaining and
// having this type is to ensure we can have a common type which contains exclusive
// fields from both Docker manifest format and OCI manifest format.
type ManifestListData struct {
SchemaVersion int `json:"schemaVersion"`
MediaType string `json:"mediaType"`
Manifests []ManifestListDescriptor `json:"manifests"`
// Annotations contains arbitrary metadata for the image index.
Annotations map[string]string `json:"annotations,omitempty"`
}
// ID returns the ID of the manifest list.
func (m *ManifestList) ID() string {
return m.image.ID()
@ -238,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() (*ManifestListData, error) {
inspectList := ManifestListData{}
func (m *ManifestList) Inspect() (*define.ManifestListData, error) {
inspectList := define.ManifestListData{}
dockerFormat := m.list.Docker()
err := structcopier.Copy(&inspectList, &dockerFormat)
if err != nil {