github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/domain/infra/tunnel/manifest.go (about)

     1  package tunnel
     2  
     3  import (
     4  	"context"
     5  	"encoding/json"
     6  	"fmt"
     7  	"strings"
     8  
     9  	"github.com/containers/podman/v2/libpod/image"
    10  	"github.com/containers/podman/v2/pkg/bindings/manifests"
    11  	"github.com/containers/podman/v2/pkg/domain/entities"
    12  	"github.com/pkg/errors"
    13  )
    14  
    15  // ManifestCreate implements manifest create via ImageEngine
    16  func (ir *ImageEngine) ManifestCreate(ctx context.Context, names, images []string, opts entities.ManifestCreateOptions) (string, error) {
    17  	imageID, err := manifests.Create(ir.ClientCxt, names, images, &opts.All)
    18  	if err != nil {
    19  		return imageID, errors.Wrapf(err, "error creating manifest")
    20  	}
    21  	return imageID, err
    22  }
    23  
    24  // ManifestInspect returns contents of manifest list with given name
    25  func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte, error) {
    26  	list, err := manifests.Inspect(ir.ClientCxt, name)
    27  	if err != nil {
    28  		return nil, errors.Wrapf(err, "error getting content of manifest list or image %s", name)
    29  	}
    30  
    31  	buf, err := json.MarshalIndent(list, "", "    ")
    32  	if err != nil {
    33  		return buf, errors.Wrapf(err, "error rendering manifest for display")
    34  	}
    35  	return buf, err
    36  }
    37  
    38  // ManifestAdd adds images to the manifest list
    39  func (ir *ImageEngine) ManifestAdd(ctx context.Context, opts entities.ManifestAddOptions) (string, error) {
    40  	manifestAddOpts := image.ManifestAddOpts{
    41  		All:       opts.All,
    42  		Arch:      opts.Arch,
    43  		Features:  opts.Features,
    44  		Images:    opts.Images,
    45  		OS:        opts.OS,
    46  		OSVersion: opts.OSVersion,
    47  		Variant:   opts.Variant,
    48  	}
    49  	if len(opts.Annotation) != 0 {
    50  		annotations := make(map[string]string)
    51  		for _, annotationSpec := range opts.Annotation {
    52  			spec := strings.SplitN(annotationSpec, "=", 2)
    53  			if len(spec) != 2 {
    54  				return "", errors.Errorf("no value given for annotation %q", spec[0])
    55  			}
    56  			annotations[spec[0]] = spec[1]
    57  		}
    58  		manifestAddOpts.Annotation = annotations
    59  	}
    60  	listID, err := manifests.Add(ir.ClientCxt, opts.Images[1], manifestAddOpts)
    61  	if err != nil {
    62  		return listID, errors.Wrapf(err, "error adding to manifest list %s", opts.Images[1])
    63  	}
    64  	return listID, nil
    65  }
    66  
    67  // ManifestAnnotate updates an entry of the manifest list
    68  func (ir *ImageEngine) ManifestAnnotate(ctx context.Context, names []string, opts entities.ManifestAnnotateOptions) (string, error) {
    69  	return "", errors.New("not implemented")
    70  }
    71  
    72  // ManifestRemove removes the digest from manifest list
    73  func (ir *ImageEngine) ManifestRemove(ctx context.Context, names []string) (string, error) {
    74  	updatedListID, err := manifests.Remove(ir.ClientCxt, names[0], names[1])
    75  	if err != nil {
    76  		return updatedListID, errors.Wrapf(err, "error removing from manifest %s", names[0])
    77  	}
    78  	return fmt.Sprintf("%s :%s\n", updatedListID, names[1]), nil
    79  }
    80  
    81  // ManifestPush pushes a manifest list or image index to the destination
    82  func (ir *ImageEngine) ManifestPush(ctx context.Context, names []string, opts entities.ManifestPushOptions) error {
    83  	_, err := manifests.Push(ir.ClientCxt, names[0], &names[1], &opts.All)
    84  	return err
    85  }