summaryrefslogtreecommitdiff
path: root/libpod/image/manifests.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-04-22 08:01:12 +0200
committerValentin Rothberg <rothberg@redhat.com>2021-05-05 11:30:12 +0200
commit0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21 (patch)
tree192e52054de2abf0c92d83ecdbc71d498c2ec947 /libpod/image/manifests.go
parent8eefca5a257121b177562742c972e39e1686140d (diff)
downloadpodman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.tar.gz
podman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.tar.bz2
podman-0f7d54b0260c1be992ee3b9cee359ef3a9e8bd21.zip
migrate Podman to containers/common/libimage
Migrate the Podman code base over to `common/libimage` which replaces `libpod/image` and a lot of glue code entirely. Note that I tried to leave bread crumbs for changed tests. Miscellaneous changes: * Some errors yield different messages which required to alter some tests. * I fixed some pre-existing issues in the code. Others were marked as `//TODO`s to prevent the PR from exploding. * The `NamesHistory` of an image is returned as is from the storage. Previously, we did some filtering which I think is undesirable. Instead we should return the data as stored in the storage. * Touched handlers use the ABI interfaces where possible. * Local image resolution: previously Podman would match "foo" on "myfoo". This behaviour has been changed and Podman will now only match on repository boundaries such that "foo" would match "my/foo" but not "myfoo". I consider the old behaviour to be a bug, at the very least an exotic corner case. * Futhermore, "foo:none" does *not* resolve to a local image "foo" without tag anymore. It's a hill I am (almost) willing to die on. * `image prune` prints the IDs of pruned images. Previously, in some cases, the names were printed instead. The API clearly states ID, so we should stick to it. * Compat endpoint image removal with _force_ deletes the entire not only the specified tag. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/image/manifests.go')
-rw-r--r--libpod/image/manifests.go209
1 files changed, 0 insertions, 209 deletions
diff --git a/libpod/image/manifests.go b/libpod/image/manifests.go
deleted file mode 100644
index 1ae3693c9..000000000
--- a/libpod/image/manifests.go
+++ /dev/null
@@ -1,209 +0,0 @@
-package image
-
-import (
- "context"
- "fmt"
-
- "github.com/containers/buildah/manifests"
- "github.com/containers/image/v5/docker"
- "github.com/containers/image/v5/manifest"
- "github.com/containers/image/v5/transports/alltransports"
- "github.com/containers/image/v5/types"
- "github.com/opencontainers/go-digest"
-)
-
-// Options for adding a manifest
-// swagger:model ManifestAddOpts
-type ManifestAddOpts struct {
- All bool `json:"all"`
- Annotation map[string]string `json:"annotation"`
- Arch string `json:"arch"`
- Features []string `json:"features"`
- Images []string `json:"images"`
- OS string `json:"os"`
- OSVersion string `json:"os_version"`
- Variant string `json:"variant"`
-}
-
-// ManifestAnnotateOptions defines the options for
-// manifest annotate
-type ManifestAnnotateOpts struct {
- Annotation map[string]string `json:"annotation"`
- Arch string `json:"arch"`
- Features []string `json:"features"`
- OS string `json:"os"`
- OSFeatures []string `json:"os_feature"`
- OSVersion string `json:"os_version"`
- Variant string `json:"variant"`
-}
-
-// InspectManifest returns a dockerized version of the manifest list
-func (i *Image) InspectManifest() (*manifest.Schema2List, error) {
- list, err := i.getManifestList()
- if err != nil {
- return nil, err
- }
- return list.Docker(), nil
-}
-
-// ExistsManifest checks if a manifest list exists
-func (i *Image) ExistsManifest() (bool, error) {
- _, err := i.getManifestList()
- if err != nil {
- return false, err
- }
- return true, nil
-}
-
-// RemoveManifest removes the given digest from the manifest list.
-func (i *Image) RemoveManifest(d digest.Digest) (string, error) {
- list, err := i.getManifestList()
- if err != nil {
- return "", err
- }
- if err := list.Remove(d); err != nil {
- return "", err
- }
- return list.SaveToImage(i.imageruntime.store, i.ID(), nil, "")
-}
-
-// getManifestList is a helper to obtain a manifest list
-func (i *Image) getManifestList() (manifests.List, error) {
- _, list, err := manifests.LoadFromImage(i.imageruntime.store, i.ID())
- return list, err
-}
-
-// CreateManifestList creates a new manifest list and can optionally add given images
-// to the list
-func CreateManifestList(rt *Runtime, systemContext types.SystemContext, names []string, imgs []string, all bool) (string, error) {
- list := manifests.Create()
- opts := ManifestAddOpts{Images: names, All: all}
- for _, img := range imgs {
- ref, err := alltransports.ParseImageName(img)
- if err != nil {
- dockerPrefix := fmt.Sprintf("%s://", docker.Transport.Name())
- ref, err = alltransports.ParseImageName(fmt.Sprintf("%s%s", dockerPrefix, img))
- if err != nil {
- return "", err
- }
- }
- list, err = addManifestToList(ref, list, systemContext, opts)
- if err != nil {
- return "", err
- }
- }
- return list.SaveToImage(rt.store, "", names, manifest.DockerV2ListMediaType)
-}
-
-func addManifestToList(ref types.ImageReference, list manifests.List, systemContext types.SystemContext, opts ManifestAddOpts) (manifests.List, error) {
- d, err := list.Add(context.Background(), &systemContext, ref, opts.All)
- if err != nil {
- return nil, err
- }
- if opts.OS != "" {
- if err := list.SetOS(d, opts.OS); err != nil {
- return nil, err
- }
- }
- if len(opts.OSVersion) > 0 {
- if err := list.SetOSVersion(d, opts.OSVersion); err != nil {
- return nil, err
- }
- }
- if len(opts.Features) > 0 {
- if err := list.SetFeatures(d, opts.Features); err != nil {
- return nil, err
- }
- }
- if len(opts.Arch) > 0 {
- if err := list.SetArchitecture(d, opts.Arch); err != nil {
- return nil, err
- }
- }
- if len(opts.Variant) > 0 {
- if err := list.SetVariant(d, opts.Variant); err != nil {
- return nil, err
- }
- }
- if len(opts.Annotation) > 0 {
- if err := list.SetAnnotations(&d, opts.Annotation); err != nil {
- return nil, err
- }
- }
- return list, err
-}
-
-// AddManifest adds a manifest to a given manifest list.
-func (i *Image) AddManifest(systemContext types.SystemContext, opts ManifestAddOpts) (string, error) {
- ref, err := alltransports.ParseImageName(opts.Images[0])
- if err != nil {
- dockerPrefix := fmt.Sprintf("%s://", docker.Transport.Name())
- ref, err = alltransports.ParseImageName(fmt.Sprintf("%s%s", dockerPrefix, opts.Images[0]))
- if err != nil {
- return "", err
- }
- }
- list, err := i.getManifestList()
- if err != nil {
- return "", err
- }
- list, err = addManifestToList(ref, list, systemContext, opts)
- if err != nil {
- return "", err
- }
- return list.SaveToImage(i.imageruntime.store, i.ID(), nil, "")
-}
-
-// PushManifest pushes a manifest to a destination
-func (i *Image) PushManifest(dest types.ImageReference, opts manifests.PushOptions) (digest.Digest, error) {
- list, err := i.getManifestList()
- if err != nil {
- return "", err
- }
- _, d, err := list.Push(context.Background(), dest, opts)
- return d, err
-}
-
-// AnnotateManifest updates an image configuration of a manifest list.
-func (i *Image) AnnotateManifest(systemContext types.SystemContext, d digest.Digest, opts ManifestAnnotateOpts) (string, error) {
- list, err := i.getManifestList()
- if err != nil {
- return "", err
- }
- if len(opts.OS) > 0 {
- if err := list.SetOS(d, opts.OS); err != nil {
- return "", err
- }
- }
- if len(opts.OSVersion) > 0 {
- if err := list.SetOSVersion(d, opts.OSVersion); err != nil {
- return "", err
- }
- }
- if len(opts.Features) > 0 {
- if err := list.SetFeatures(d, opts.Features); err != nil {
- return "", err
- }
- }
- if len(opts.OSFeatures) > 0 {
- if err := list.SetOSFeatures(d, opts.OSFeatures); err != nil {
- return "", err
- }
- }
- if len(opts.Arch) > 0 {
- if err := list.SetArchitecture(d, opts.Arch); err != nil {
- return "", err
- }
- }
- if len(opts.Variant) > 0 {
- if err := list.SetVariant(d, opts.Variant); err != nil {
- return "", err
- }
- }
- if len(opts.Annotation) > 0 {
- if err := list.SetAnnotations(&d, opts.Annotation); err != nil {
- return "", err
- }
- }
- return list.SaveToImage(i.imageruntime.store, i.ID(), nil, "")
-}