From 9dbecd8d49321f1957d59628ee988dc95b46d773 Mon Sep 17 00:00:00 2001 From: Thorben Thuermer Date: Thu, 12 Mar 2020 16:35:45 +0100 Subject: [PATCH] fix size info missing on tagged images, refactor imagesToDot() --- images.go | 53 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/images.go b/images.go index dd310f3..c8e86fe 100644 --- a/images.go +++ b/images.go @@ -471,34 +471,41 @@ func imagesToDot(buffer *bytes.Buffer, images []Image, byParent map[string][]Ima buffer.WriteString(fmt.Sprintf(" \"%s\" -> \"%s\"\n", truncate(image.ParentId, 12), truncate(image.Id, 12))) } - if image.RepoTags[0] != ":" { - buffer.WriteString(fmt.Sprintf(" \"%s\" [label=\"%s\\n%s\",area=%f,shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n", truncate(image.Id, 12), truncate(stripPrefix(image.OrigId), 12), strings.Join(image.RepoTags, "\\n"), megabytes(image.Size))) + var style string + + var size int64 + var sizeLabel string + if dispOpts.Incremental { + sizeLabel = "Size" + size = image.Size } else { - labelParts := []string{truncate(stripPrefix(image.OrigId), 12)} - if dispOpts.ShowCreatedBy { - labelParts = append(labelParts, SanitizeCommand(image.CreatedBy, 30)) - } + sizeLabel = "Virtual Size" + size = image.VirtualSize + } - var size int64 - var sizeLabel string - if dispOpts.Incremental { - sizeLabel = "Size" - size = image.Size - } else { - sizeLabel = "Virtual Size" - size = image.VirtualSize - } + var sizeStr string + if dispOpts.NoHuman { + sizeStr = strconv.FormatInt(size, 10) + } else { + sizeStr = humanSize(size) + } - var sizeStr string - if dispOpts.NoHuman { - sizeStr = strconv.FormatInt(size, 10) - } else { - sizeStr = humanSize(size) - } - labelParts = append(labelParts, fmt.Sprintf("%s: %s", sizeLabel, sizeStr)) + labelParts := []string{truncate(stripPrefix(image.OrigId), 12)} + + if dispOpts.ShowCreatedBy { + labelParts = append(labelParts, SanitizeCommand(image.CreatedBy, 30)) + } - buffer.WriteString(fmt.Sprintf(" \"%s\" [label=\"%s\",area=%f]\n", truncate(image.Id, 12), strings.Join(labelParts, "\n"), megabytes(image.Size))) + if image.RepoTags[0] != ":" { + labelParts = append(labelParts, strings.Join(image.RepoTags, "\\n")) + style = ",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\""; } + + labelParts = append(labelParts, fmt.Sprintf("%s: %s", sizeLabel, sizeStr)) + + buffer.WriteString(fmt.Sprintf(" \"%s\" [label=\"%s\",area=%f%s]\n", truncate(image.Id, 12), strings.Join(labelParts, "\n"), megabytes(image.Size),style)) + + if subimages, exists := byParent[image.Id]; exists { imagesToDot(buffer, subimages, byParent, dispOpts) }