summaryrefslogtreecommitdiff
path: root/pkg/adapter/images_remote.go
blob: 1d4997d9a82afad88ec1b44844449ddc6201a787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// +build remoteclient

package adapter

import (
	"context"
	"encoding/json"

	iopodman "github.com/containers/libpod/cmd/podman/varlink"
	"github.com/containers/libpod/libpod/image"
	"github.com/containers/libpod/pkg/inspect"
	"github.com/pkg/errors"
)

// Inspect returns returns an ImageData struct from over a varlink connection
func (i *ContainerImage) Inspect(ctx context.Context) (*inspect.ImageData, error) {
	reply, err := iopodman.InspectImage().Call(i.Runtime.Conn, i.ID())
	if err != nil {
		return nil, err
	}
	data := inspect.ImageData{}
	if err := json.Unmarshal([]byte(reply), &data); err != nil {
		return nil, err
	}
	return &data, nil
}

// Tree ...
func (r *LocalRuntime) Tree(imageOrID string) (*image.InfoImage, map[string]*image.LayerInfo, *ContainerImage, error) {
	layerInfoMap := make(map[string]*image.LayerInfo)
	imageInfo := &image.InfoImage{}

	img, err := r.NewImageFromLocal(imageOrID)
	if err != nil {
		return nil, nil, nil, err
	}

	reply, err := iopodman.GetLayersMapWithImageInfo().Call(r.Conn)
	if err != nil {
		return nil, nil, nil, errors.Wrap(err, "failed to obtain image layers")
	}
	if err := json.Unmarshal([]byte(reply), &layerInfoMap); err != nil {
		return nil, nil, nil, errors.Wrap(err, "failed to unmarshal image layers")
	}

	reply, err = iopodman.BuildImageHierarchyMap().Call(r.Conn, imageOrID)
	if err != nil {
		return nil, nil, nil, errors.Wrap(err, "failed to get build image map")
	}
	if err := json.Unmarshal([]byte(reply), imageInfo); err != nil {
		return nil, nil, nil, errors.Wrap(err, "failed to unmarshal build image map")
	}

	return imageInfo, layerInfoMap, img, nil
}