aboutsummaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi/images_list.go
blob: 281b0429411532f3c79598caaf20b38536e3e9f5 (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
56
57
58
59
60
61
62
63
64
65
66
67
package abi

import (
	"context"

	libpodImage "github.com/containers/podman/v2/libpod/image"
	"github.com/containers/podman/v2/pkg/domain/entities"
	"github.com/pkg/errors"
)

func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) {
	images, err := ir.Libpod.ImageRuntime().GetImagesWithFilters(opts.Filter)
	if err != nil {
		return nil, err
	}

	if !opts.All {
		filter, err := ir.Libpod.ImageRuntime().IntermediateFilter(ctx, images)
		if err != nil {
			return nil, err
		}
		images = libpodImage.FilterImages(images, []libpodImage.ResultFilter{filter})
	}

	summaries := []*entities.ImageSummary{}
	for _, img := range images {
		digests := make([]string, len(img.Digests()))
		for j, d := range img.Digests() {
			digests[j] = string(d)
		}

		e := entities.ImageSummary{
			ID:           img.ID(),
			ConfigDigest: string(img.ConfigDigest),
			Created:      img.Created().Unix(),
			Dangling:     img.Dangling(),
			Digest:       string(img.Digest()),
			Digests:      digests,
			History:      img.NamesHistory(),
			Names:        img.Names(),
			ParentId:     img.Parent,
			ReadOnly:     img.IsReadOnly(),
			SharedSize:   0,
			VirtualSize:  img.VirtualSize,
			RepoTags:     img.Names(), // may include tags and digests
		}
		e.Labels, err = img.Labels(ctx)
		if err != nil {
			return nil, errors.Wrapf(err, "error retrieving label for image %q: you may need to remove the image to resolve the error", img.ID())
		}

		ctnrs, err := img.Containers()
		if err != nil {
			return nil, errors.Wrapf(err, "error retrieving containers for image %q: you may need to remove the image to resolve the error", img.ID())
		}
		e.Containers = len(ctnrs)

		sz, err := img.Size(ctx)
		if err != nil {
			return nil, errors.Wrapf(err, "error retrieving size of image %q: you may need to remove the image to resolve the error", img.ID())
		}
		e.Size = int64(*sz)

		summaries = append(summaries, &e)
	}
	return summaries, nil
}