diff options
author | Qi Wang <qiwan@redhat.com> | 2020-04-16 00:41:09 -0400 |
---|---|---|
committer | Qi Wang <qiwan@redhat.com> | 2020-04-22 20:05:21 -0400 |
commit | 17783dda6880c786a6eb3f47b3b6100e43bcdc77 (patch) | |
tree | 1d551e1a3901fe07c3540c8e9a58d93c8da5c772 /pkg/domain/infra/tunnel/manifest.go | |
parent | 576fe98bbcee7361251b437835125f93b4c10b15 (diff) | |
download | podman-17783dda6880c786a6eb3f47b3b6100e43bcdc77.tar.gz podman-17783dda6880c786a6eb3f47b3b6100e43bcdc77.tar.bz2 podman-17783dda6880c786a6eb3f47b3b6100e43bcdc77.zip |
manifest create,add,inspect
Implememts manifest subcommands create, add, inspect.
Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'pkg/domain/infra/tunnel/manifest.go')
-rw-r--r-- | pkg/domain/infra/tunnel/manifest.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/pkg/domain/infra/tunnel/manifest.go b/pkg/domain/infra/tunnel/manifest.go new file mode 100644 index 000000000..338256530 --- /dev/null +++ b/pkg/domain/infra/tunnel/manifest.go @@ -0,0 +1,63 @@ +package tunnel + +import ( + "context" + "encoding/json" + "strings" + + "github.com/containers/libpod/libpod/image" + "github.com/containers/libpod/pkg/bindings/manifests" + "github.com/containers/libpod/pkg/domain/entities" + "github.com/pkg/errors" +) + +// ManifestCreate implements manifest create via ImageEngine +func (ir *ImageEngine) ManifestCreate(ctx context.Context, names, images []string, opts entities.ManifestCreateOptions) (string, error) { + imageID, err := manifests.Create(ir.ClientCxt, names, images, &opts.All) + if err != nil { + return imageID, errors.Wrapf(err, "error creating manifest") + } + return imageID, err +} + +// ManifestInspect returns contents of manifest list with given name +func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte, error) { + list, err := manifests.Inspect(ir.ClientCxt, name) + if err != nil { + return nil, errors.Wrapf(err, "error getting content of manifest list or image %s", name) + } + + buf, err := json.MarshalIndent(list, "", " ") + if err != nil { + return buf, errors.Wrapf(err, "error rendering manifest for display") + } + return buf, err +} + +// ManifestAdd adds images to the manifest list +func (ir *ImageEngine) ManifestAdd(ctx context.Context, opts entities.ManifestAddOptions) (string, error) { + manifestAddOpts := image.ManifestAddOpts{ + All: opts.All, + Arch: opts.Arch, + Features: opts.Features, + Images: opts.Images, + OSVersion: opts.OSVersion, + Variant: opts.Variant, + } + if len(opts.Annotation) != 0 { + annotations := make(map[string]string) + for _, annotationSpec := range opts.Annotation { + spec := strings.SplitN(annotationSpec, "=", 2) + if len(spec) != 2 { + return "", errors.Errorf("no value given for annotation %q", spec[0]) + } + annotations[spec[0]] = spec[1] + } + manifestAddOpts.Annotation = annotations + } + listID, err := manifests.Add(ctx, opts.Images[1], manifestAddOpts) + if err != nil { + return listID, errors.Wrapf(err, "error adding to manifest list %s", opts.Images[1]) + } + return listID, nil +} |