From a3c2d6ad2ee7092bd185b8ab87d9d0270a9dc9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 28 Aug 2023 23:22:42 +0200 Subject: [PATCH] Remove a dependency on libimage from pkg/bindings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... 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č --- go.mod | 2 +- go.sum | 4 +-- pkg/api/handlers/libpod/manifests.go | 4 +-- pkg/bindings/manifests/manifests.go | 6 ++--- test/e2e/manifest_test.go | 4 +-- .../common/libimage/define/manifests.go | 27 +++++++++++++++++++ .../containers/common/libimage/image.go | 6 +++-- .../common/libimage/manifest_list.go | 27 +++---------------- vendor/modules.txt | 2 +- 9 files changed, 45 insertions(+), 37 deletions(-) create mode 100644 vendor/github.com/containers/common/libimage/define/manifests.go diff --git a/go.mod b/go.mod index c13db20f42..1f6ce3e820 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/containernetworking/cni v1.1.2 github.com/containernetworking/plugins v1.3.0 github.com/containers/buildah v1.31.1-0.20230722114901-5ece066f82c6 - github.com/containers/common v0.55.1-0.20230828100250-07e4cdeb1499 + github.com/containers/common v0.55.1-0.20230829104013-4a76f1739d43 github.com/containers/conmon v2.0.20+incompatible github.com/containers/image/v5 v5.26.1-0.20230807184415-3fb422379cfa github.com/containers/libhvee v0.4.1-0.20230816135538-b81ee3f10e1e diff --git a/go.sum b/go.sum index 0951840113..84f3a9ec2b 100644 --- a/go.sum +++ b/go.sum @@ -246,8 +246,8 @@ github.com/containernetworking/plugins v1.3.0 h1:QVNXMT6XloyMUoO2wUOqWTC1hWFV62Q github.com/containernetworking/plugins v1.3.0/go.mod h1:Pc2wcedTQQCVuROOOaLBPPxrEXqqXBFt3cZ+/yVg6l0= github.com/containers/buildah v1.31.1-0.20230722114901-5ece066f82c6 h1:K/S8SFQsnnNTF0Ws58SrBD9L0EuClzAG8Zp08d7+6AA= github.com/containers/buildah v1.31.1-0.20230722114901-5ece066f82c6/go.mod h1:0sptTFBBtSznLqoTh80DfvMOCNbdRsNRgVOKhBhrupA= -github.com/containers/common v0.55.1-0.20230828100250-07e4cdeb1499 h1:YxSpAmFtHY/sbLtX29KXOZuoHgIL1ZOu06DQzGYND/o= -github.com/containers/common v0.55.1-0.20230828100250-07e4cdeb1499/go.mod h1:Xcw3UosoUax8jn+MZoxL7LbEbfxKqhUNMZyhdd5s/vk= +github.com/containers/common v0.55.1-0.20230829104013-4a76f1739d43 h1:Or7mn/haMXOsLC3FiwTCaHRCdez5TkqEJE+U+rSwTIo= +github.com/containers/common v0.55.1-0.20230829104013-4a76f1739d43/go.mod h1:Xcw3UosoUax8jn+MZoxL7LbEbfxKqhUNMZyhdd5s/vk= github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg= github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I= github.com/containers/image/v5 v5.26.1-0.20230807184415-3fb422379cfa h1:wDfVQtc6ik2MvsUmu/YRSyBAE5YUxdjcEDtuT1q2KDo= diff --git a/pkg/api/handlers/libpod/manifests.go b/pkg/api/handlers/libpod/manifests.go index 0720920c69..2c53e2162c 100644 --- a/pkg/api/handlers/libpod/manifests.go +++ b/pkg/api/handlers/libpod/manifests.go @@ -11,7 +11,7 @@ import ( "strconv" "strings" - "github.com/containers/common/libimage" + "github.com/containers/common/libimage/define" "github.com/containers/image/v5/docker/reference" "github.com/containers/image/v5/types" "github.com/containers/podman/v4/libpod" @@ -173,7 +173,7 @@ func ManifestInspect(w http.ResponseWriter, r *http.Request) { return } - var schema2List libimage.ManifestListData + var schema2List define.ManifestListData if err := json.Unmarshal(rawManifest, &schema2List); err != nil { utils.Error(w, http.StatusInternalServerError, err) return diff --git a/pkg/bindings/manifests/manifests.go b/pkg/bindings/manifests/manifests.go index 45df54af2c..ec3affce0d 100644 --- a/pkg/bindings/manifests/manifests.go +++ b/pkg/bindings/manifests/manifests.go @@ -11,7 +11,7 @@ import ( "strconv" "strings" - "github.com/containers/common/libimage" + "github.com/containers/common/libimage/define" "github.com/containers/image/v5/manifest" imageTypes "github.com/containers/image/v5/types" "github.com/containers/podman/v4/pkg/auth" @@ -110,7 +110,7 @@ func Inspect(ctx context.Context, name string, options *InspectOptions) (*manife // InspectListData returns a manifest list for a given name. // Contains exclusive field like `annotations` which is only // present in OCI spec and not in docker image spec. -func InspectListData(ctx context.Context, name string, options *InspectOptions) (*libimage.ManifestListData, error) { +func InspectListData(ctx context.Context, name string, options *InspectOptions) (*define.ManifestListData, error) { conn, err := bindings.GetClient(ctx) if err != nil { return nil, err @@ -141,7 +141,7 @@ func InspectListData(ctx context.Context, name string, options *InspectOptions) } defer response.Body.Close() - var list libimage.ManifestListData + var list define.ManifestListData return &list, response.Process(&list) } diff --git a/test/e2e/manifest_test.go b/test/e2e/manifest_test.go index a20522aa10..1cb03e20dd 100644 --- a/test/e2e/manifest_test.go +++ b/test/e2e/manifest_test.go @@ -6,7 +6,7 @@ import ( "path/filepath" "strings" - "github.com/containers/common/libimage" + "github.com/containers/common/libimage/define" podmanRegistry "github.com/containers/podman/v4/hack/podman-registry-go" . "github.com/containers/podman/v4/test/utils" "github.com/containers/storage/pkg/archive" @@ -288,7 +288,7 @@ var _ = Describe("Podman manifest", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - var inspect libimage.ManifestListData + var inspect define.ManifestListData err := json.Unmarshal(session.Out.Contents(), &inspect) Expect(err).ToNot(HaveOccurred()) Expect(inspect.Manifests[0].Annotations).To(Equal(map[string]string{"hoge": "fuga"})) diff --git a/vendor/github.com/containers/common/libimage/define/manifests.go b/vendor/github.com/containers/common/libimage/define/manifests.go new file mode 100644 index 0000000000..1e02984b2a --- /dev/null +++ b/vendor/github.com/containers/common/libimage/define/manifests.go @@ -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"` +} diff --git a/vendor/github.com/containers/common/libimage/image.go b/vendor/github.com/containers/common/libimage/image.go index 5311a23777..640968fd0e 100644 --- a/vendor/github.com/containers/common/libimage/image.go +++ b/vendor/github.com/containers/common/libimage/image.go @@ -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 { diff --git a/vendor/github.com/containers/common/libimage/manifest_list.go b/vendor/github.com/containers/common/libimage/manifest_list.go index 8e688676ae..839892366b 100644 --- a/vendor/github.com/containers/common/libimage/manifest_list.go +++ b/vendor/github.com/containers/common/libimage/manifest_list.go @@ -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 { diff --git a/vendor/modules.txt b/vendor/modules.txt index e46a4910ec..3de158a0ec 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -156,7 +156,7 @@ github.com/containers/buildah/pkg/rusage github.com/containers/buildah/pkg/sshagent github.com/containers/buildah/pkg/util github.com/containers/buildah/util -# github.com/containers/common v0.55.1-0.20230828100250-07e4cdeb1499 +# github.com/containers/common v0.55.1-0.20230829104013-4a76f1739d43 ## explicit; go 1.18 github.com/containers/common/libimage github.com/containers/common/libimage/define