From ea8aafcd9e695b9e692bfea47ea568b78daed761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 14 Aug 2024 13:46:45 +0200 Subject: [PATCH] cli/tree: Add `Content size` column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- cli/command/image/tree.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index a4f0761e92..64d32cd0e3 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -39,25 +39,30 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error Used: img.Containers > 0, } + var totalContent int64 children := make([]subImage, 0, len(img.Manifests)) for _, im := range img.Manifests { if im.Kind != imagetypes.ManifestKindImage { continue } + im := im sub := subImage{ Platform: platforms.Format(im.ImageData.Platform), Available: im.Available, Details: imageDetails{ - ID: im.ID, - DiskUsage: units.HumanSizeWithPrecision(float64(im.Size.Total), 3), - Used: len(im.ImageData.Containers) > 0, + ID: im.ID, + DiskUsage: units.HumanSizeWithPrecision(float64(im.Size.Total), 3), + Used: len(im.ImageData.Containers) > 0, + ContentSize: units.HumanSizeWithPrecision(float64(im.Size.Content), 3), }, } + totalContent += im.Size.Content children = append(children, sub) } + details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3) view = append(view, topImage{ Names: img.RepoTags, Details: details, @@ -69,9 +74,10 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error } type imageDetails struct { - ID string - DiskUsage string - Used bool + ID string + DiskUsage string + Used bool + ContentSize string } type topImage struct { @@ -125,6 +131,13 @@ func printImageTree(dockerCLI command.Cli, images []topImage) error { return d.DiskUsage }, }, + { + Title: "Content size", + Width: 12, + DetailsValue: func(d *imageDetails) string { + return d.ContentSize + }, + }, { Title: "Used", Width: 4,