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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package abi
import (
"context"
"fmt"
"github.com/containers/common/libimage"
"github.com/containers/podman/v4/pkg/domain/entities"
)
func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) {
listImagesOptions := &libimage.ListImagesOptions{
Filters: opts.Filter,
}
if !opts.All {
// Filter intermediate images unless we want to list *all*.
// NOTE: it's a positive filter, so `intermediate=false` means
// to display non-intermediate images.
listImagesOptions.Filters = append(listImagesOptions.Filters, "intermediate=false")
}
images, err := ir.Libpod.LibimageRuntime().ListImages(ctx, nil, listImagesOptions)
if err != nil {
return nil, err
}
summaries := []*entities.ImageSummary{}
for _, img := range images {
repoDigests, err := img.RepoDigests()
if err != nil {
return nil, fmt.Errorf("getting repoDigests from image %q: %w", img.ID(), err)
}
isDangling, err := img.IsDangling(ctx)
if err != nil {
return nil, fmt.Errorf("error checking if image %q is dangling: %w", img.ID(), err)
}
e := entities.ImageSummary{
ID: img.ID(),
Created: img.Created().Unix(),
Dangling: isDangling,
Digest: string(img.Digest()),
RepoDigests: repoDigests,
History: img.NamesHistory(),
Names: img.Names(),
ReadOnly: img.IsReadOnly(),
SharedSize: 0,
RepoTags: img.Names(), // may include tags and digests
}
e.Labels, err = img.Labels(ctx)
if err != nil {
return nil, fmt.Errorf("error retrieving label for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
ctnrs, err := img.Containers()
if err != nil {
return nil, fmt.Errorf("error retrieving containers for image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
e.Containers = len(ctnrs)
sz, err := img.Size()
if err != nil {
return nil, fmt.Errorf("error retrieving size of image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
e.Size = sz
// This is good enough for now, but has to be
// replaced later with correct calculation logic
e.VirtualSize = sz
parent, err := img.Parent(ctx)
if err != nil {
return nil, fmt.Errorf("error retrieving parent of image %q: you may need to remove the image to resolve the error: %w", img.ID(), err)
}
if parent != nil {
e.ParentId = parent.ID()
}
summaries = append(summaries, &e)
}
return summaries, nil
}
|