MCPcopy Index your code
hub / github.com/docker/cli / runTree

Function runTree

cli/command/image/tree.go:38–151  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts treeOptions)

Source from the content-addressed store, hash-verified

36}
37
38func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) (int, error) {
39 images := opts.images
40
41 view := treeView{
42 images: make([]topImage, 0, len(images)),
43 }
44 attested := make(map[digest.Digest]bool)
45
46 for _, img := range images {
47 if ctx.Err() != nil {
48 return 0, ctx.Err()
49 }
50 topDetails := imageDetails{
51 ID: img.ID,
52 DiskUsage: units.HumanSizeWithPrecision(float64(img.Size), 3),
53 InUse: img.Containers > 0,
54 }
55
56 var totalContent int64
57 children := make([]subImage, 0, len(img.Manifests))
58 for _, im := range img.Manifests {
59 totalContent += im.Size.Content
60
61 if im.Kind == imagetypes.ManifestKindAttestation {
62 attested[im.AttestationData.For] = true
63 continue
64 }
65 if im.Kind != imagetypes.ManifestKindImage {
66 continue
67 }
68
69 inUse := len(im.ImageData.Containers) > 0
70 if inUse {
71 // Mark top-level parent image as used if any of its subimages are used.
72 topDetails.InUse = true
73 }
74
75 if !opts.expanded {
76 continue
77 }
78
79 sub := subImage{
80 Platform: platforms.Format(im.ImageData.Platform),
81 Available: im.Available,
82 Details: imageDetails{
83 ID: im.ID,
84 DiskUsage: units.HumanSizeWithPrecision(float64(im.Size.Total), 3),
85 InUse: inUse,
86 ContentSize: units.HumanSizeWithPrecision(float64(im.Size.Content), 3),
87 },
88 }
89
90 children = append(children, sub)
91
92 // Add extra spacing between images if there's at least one entry with children.
93 view.imageSpacing = true
94 }
95

Callers 1

runImagesFunction · 0.85

Calls 2

printImageTreeFunction · 0.85
ErrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…