mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #3145 from vieux/fix_docker_images
multiple fixed in docker images
This commit is contained in:
commit
5b33ae5971
2 changed files with 60 additions and 51 deletions
107
commands.go
107
commands.go
|
@ -1101,33 +1101,9 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if *flViz {
|
filter := cmd.Arg(0)
|
||||||
body, _, err := cli.call("GET", "/images/json?all=1", nil)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var outs []APIImages
|
if *flViz || *flTree {
|
||||||
err = json.Unmarshal(body, &outs)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(cli.out, "digraph docker {\n")
|
|
||||||
|
|
||||||
for _, image := range outs {
|
|
||||||
if image.ParentId == "" {
|
|
||||||
fmt.Fprintf(cli.out, " base -> \"%s\" [style=invis]\n", utils.TruncateID(image.ID))
|
|
||||||
} else {
|
|
||||||
fmt.Fprintf(cli.out, " \"%s\" -> \"%s\"\n", utils.TruncateID(image.ParentId), utils.TruncateID(image.ID))
|
|
||||||
}
|
|
||||||
if image.RepoTags[0] != "<none>:<none>" {
|
|
||||||
fmt.Fprintf(cli.out, " \"%s\" [label=\"%s\\n%s\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n", utils.TruncateID(image.ID), utils.TruncateID(image.ID), strings.Join(image.RepoTags, "\\n"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
|
|
||||||
} else if *flTree {
|
|
||||||
body, _, err := cli.call("GET", "/images/json?all=1", nil)
|
body, _, err := cli.call("GET", "/images/json?all=1", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1139,8 +1115,8 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
startImageArg = cmd.Arg(0)
|
printNode func(cli *DockerCli, noTrunc bool, image APIImages, prefix string)
|
||||||
startImage APIImages
|
startImage APIImages
|
||||||
|
|
||||||
roots []APIImages
|
roots []APIImages
|
||||||
byParent = make(map[string][]APIImages)
|
byParent = make(map[string][]APIImages)
|
||||||
|
@ -1157,28 +1133,38 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if startImageArg != "" {
|
if filter != "" {
|
||||||
if startImageArg == image.ID || startImageArg == utils.TruncateID(image.ID) {
|
if filter == image.ID || filter == utils.TruncateID(image.ID) {
|
||||||
startImage = image
|
startImage = image
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, repotag := range image.RepoTags {
|
for _, repotag := range image.RepoTags {
|
||||||
if repotag == startImageArg {
|
if repotag == filter {
|
||||||
startImage = image
|
startImage = image
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if startImageArg != "" {
|
if *flViz {
|
||||||
WalkTree(cli, noTrunc, []APIImages{startImage}, byParent, "")
|
fmt.Fprintf(cli.out, "digraph docker {\n")
|
||||||
|
printNode = (*DockerCli).printVizNode
|
||||||
} else {
|
} else {
|
||||||
WalkTree(cli, noTrunc, roots, byParent, "")
|
printNode = (*DockerCli).printTreeNode
|
||||||
|
}
|
||||||
|
|
||||||
|
if startImage.ID != "" {
|
||||||
|
cli.WalkTree(*noTrunc, &[]APIImages{startImage}, byParent, "", printNode)
|
||||||
|
} else if filter == "" {
|
||||||
|
cli.WalkTree(*noTrunc, &roots, byParent, "", printNode)
|
||||||
|
}
|
||||||
|
if *flViz {
|
||||||
|
fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
if cmd.NArg() == 1 {
|
if cmd.NArg() == 1 {
|
||||||
v.Set("filter", cmd.Arg(0))
|
v.Set("filter", filter)
|
||||||
}
|
}
|
||||||
if *all {
|
if *all {
|
||||||
v.Set("all", "1")
|
v.Set("all", "1")
|
||||||
|
@ -1224,41 +1210,64 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WalkTree(cli *DockerCli, noTrunc *bool, images []APIImages, byParent map[string][]APIImages, prefix string) {
|
func (cli *DockerCli) WalkTree(noTrunc bool, images *[]APIImages, byParent map[string][]APIImages, prefix string, printNode func(cli *DockerCli, noTrunc bool, image APIImages, prefix string)) {
|
||||||
if len(images) > 1 {
|
length := len(*images)
|
||||||
length := len(images)
|
if length > 1 {
|
||||||
for index, image := range images {
|
for index, image := range *images {
|
||||||
if index+1 == length {
|
if index+1 == length {
|
||||||
PrintTreeNode(cli, noTrunc, image, prefix+"└─")
|
printNode(cli, noTrunc, image, prefix+"└─")
|
||||||
if subimages, exists := byParent[image.ID]; exists {
|
if subimages, exists := byParent[image.ID]; exists {
|
||||||
WalkTree(cli, noTrunc, subimages, byParent, prefix+" ")
|
cli.WalkTree(noTrunc, &subimages, byParent, prefix+" ", printNode)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
PrintTreeNode(cli, noTrunc, image, prefix+"|─")
|
printNode(cli, noTrunc, image, prefix+"|─")
|
||||||
if subimages, exists := byParent[image.ID]; exists {
|
if subimages, exists := byParent[image.ID]; exists {
|
||||||
WalkTree(cli, noTrunc, subimages, byParent, prefix+"| ")
|
cli.WalkTree(noTrunc, &subimages, byParent, prefix+"| ", printNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, image := range images {
|
for _, image := range *images {
|
||||||
PrintTreeNode(cli, noTrunc, image, prefix+"└─")
|
printNode(cli, noTrunc, image, prefix+"└─")
|
||||||
if subimages, exists := byParent[image.ID]; exists {
|
if subimages, exists := byParent[image.ID]; exists {
|
||||||
WalkTree(cli, noTrunc, subimages, byParent, prefix+" ")
|
cli.WalkTree(noTrunc, &subimages, byParent, prefix+" ", printNode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintTreeNode(cli *DockerCli, noTrunc *bool, image APIImages, prefix string) {
|
func (cli *DockerCli) printVizNode(noTrunc bool, image APIImages, prefix string) {
|
||||||
|
var (
|
||||||
|
imageID string
|
||||||
|
parentID string
|
||||||
|
)
|
||||||
|
if noTrunc {
|
||||||
|
imageID = image.ID
|
||||||
|
parentID = image.ParentId
|
||||||
|
} else {
|
||||||
|
imageID = utils.TruncateID(image.ID)
|
||||||
|
parentID = utils.TruncateID(image.ParentId)
|
||||||
|
}
|
||||||
|
if image.ParentId == "" {
|
||||||
|
fmt.Fprintf(cli.out, " base -> \"%s\" [style=invis]\n", imageID)
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(cli.out, " \"%s\" -> \"%s\"\n", parentID, imageID)
|
||||||
|
}
|
||||||
|
if image.RepoTags[0] != "<none>:<none>" {
|
||||||
|
fmt.Fprintf(cli.out, " \"%s\" [label=\"%s\\n%s\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n",
|
||||||
|
imageID, imageID, strings.Join(image.RepoTags, "\\n"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cli *DockerCli) printTreeNode(noTrunc bool, image APIImages, prefix string) {
|
||||||
var imageID string
|
var imageID string
|
||||||
if *noTrunc {
|
if noTrunc {
|
||||||
imageID = image.ID
|
imageID = image.ID
|
||||||
} else {
|
} else {
|
||||||
imageID = utils.TruncateID(image.ID)
|
imageID = utils.TruncateID(image.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(cli.out, "%s%s Size: %s (virtual %s)", prefix, imageID, utils.HumanSize(image.Size), utils.HumanSize(image.VirtualSize))
|
fmt.Fprintf(cli.out, "%s%s Virtual Size: %s", prefix, imageID, utils.HumanSize(image.VirtualSize))
|
||||||
if image.RepoTags[0] != "<none>:<none>" {
|
if image.RepoTags[0] != "<none>:<none>" {
|
||||||
fmt.Fprintf(cli.out, " Tags: %s\n", strings.Join(image.RepoTags, ", "))
|
fmt.Fprintf(cli.out, " Tags: %s\n", strings.Join(image.RepoTags, ", "))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -867,11 +867,11 @@ func TestImagesTree(t *testing.T) {
|
||||||
}
|
}
|
||||||
cmdOutput := string(cmdOutputBytes)
|
cmdOutput := string(cmdOutputBytes)
|
||||||
regexpStrings := []string{
|
regexpStrings := []string{
|
||||||
fmt.Sprintf("└─%s Size: (\\d+.\\d+ MB) \\(virtual \\d+.\\d+ MB\\) Tags: %s:latest", unitTestImageIDShort, unitTestImageName),
|
fmt.Sprintf("└─%s Virtual Size: \\d+.\\d+ MB Tags: %s:latest", unitTestImageIDShort, unitTestImageName),
|
||||||
"(?m) └─[0-9a-f]+.*",
|
"(?m) └─[0-9a-f]+.*",
|
||||||
"(?m) └─[0-9a-f]+.*",
|
"(?m) └─[0-9a-f]+.*",
|
||||||
"(?m) └─[0-9a-f]+.*",
|
"(?m) └─[0-9a-f]+.*",
|
||||||
fmt.Sprintf("(?m)^ └─%s Size: \\d+ B \\(virtual \\d+.\\d+ MB\\) Tags: test:latest", utils.TruncateID(image.ID)),
|
fmt.Sprintf("(?m)^ └─%s Virtual Size: \\d+.\\d+ MB Tags: test:latest", utils.TruncateID(image.ID)),
|
||||||
}
|
}
|
||||||
|
|
||||||
compiledRegexps := []*regexp.Regexp{}
|
compiledRegexps := []*regexp.Regexp{}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue