Start image for --dot
This commit is contained in:
parent
4da0559824
commit
b95175dae8
1 changed files with 10 additions and 9 deletions
19
images.go
19
images.go
|
@ -124,6 +124,7 @@ func (x *ImagesCommand) Execute(args []string) error {
|
||||||
if startImage == nil {
|
if startImage == nil {
|
||||||
roots = collectRoots(images)
|
roots = collectRoots(images)
|
||||||
} else {
|
} else {
|
||||||
|
startImage.ParentId = ""
|
||||||
roots = []Image{*startImage}
|
roots = []Image{*startImage}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +146,10 @@ func (x *ImagesCommand) Execute(args []string) error {
|
||||||
jsonToText(&buffer, imagesCommand.NoTruncate, roots, imagesByParent, "")
|
jsonToText(&buffer, imagesCommand.NoTruncate, roots, imagesByParent, "")
|
||||||
}
|
}
|
||||||
if imagesCommand.Dot {
|
if imagesCommand.Dot {
|
||||||
imagesToDot(&buffer, images)
|
buffer.WriteString("digraph docker {\n")
|
||||||
|
imagesToDot(&buffer, roots, imagesByParent)
|
||||||
|
buffer.WriteString(" base [style=invisible]\n}\n")
|
||||||
|
buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print(buffer.String())
|
fmt.Print(buffer.String())
|
||||||
|
@ -295,10 +299,8 @@ func parseImagesJSON(rawJSON []byte) (*[]Image, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func imagesToDot(buffer *bytes.Buffer, images *[]Image) string {
|
func imagesToDot(buffer *bytes.Buffer, images []Image, byParent map[string][]Image) {
|
||||||
buffer.WriteString("digraph docker {\n")
|
for _, image := range images {
|
||||||
|
|
||||||
for _, image := range *images {
|
|
||||||
if image.ParentId == "" {
|
if image.ParentId == "" {
|
||||||
buffer.WriteString(fmt.Sprintf(" base -> \"%s\" [style=invis]\n", truncate(image.Id)))
|
buffer.WriteString(fmt.Sprintf(" base -> \"%s\" [style=invis]\n", truncate(image.Id)))
|
||||||
} else {
|
} else {
|
||||||
|
@ -307,11 +309,10 @@ func imagesToDot(buffer *bytes.Buffer, images *[]Image) string {
|
||||||
if image.RepoTags[0] != "<none>:<none>" {
|
if image.RepoTags[0] != "<none>:<none>" {
|
||||||
buffer.WriteString(fmt.Sprintf(" \"%s\" [label=\"%s\\n%s\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n", truncate(image.Id), truncate(image.Id), strings.Join(image.RepoTags, "\\n")))
|
buffer.WriteString(fmt.Sprintf(" \"%s\" [label=\"%s\\n%s\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n", truncate(image.Id), truncate(image.Id), strings.Join(image.RepoTags, "\\n")))
|
||||||
}
|
}
|
||||||
|
if subimages, exists := byParent[image.Id]; exists {
|
||||||
|
imagesToDot(buffer, subimages, byParent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.WriteString(" base [style=invisible]\n}\n")
|
|
||||||
|
|
||||||
return buffer.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue