2014-08-05 01:11:02 -04:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
2015-03-25 03:44:12 -04:00
|
|
|
"fmt"
|
2014-08-05 01:11:02 -04:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/image"
|
|
|
|
)
|
|
|
|
|
2015-03-25 03:44:12 -04:00
|
|
|
func (s *TagStore) CmdViz(job *engine.Job) error {
|
2014-08-05 01:11:02 -04:00
|
|
|
images, _ := s.graph.Map()
|
|
|
|
if images == nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-08-05 01:11:02 -04:00
|
|
|
}
|
|
|
|
job.Stdout.Write([]byte("digraph docker {\n"))
|
|
|
|
|
|
|
|
var (
|
|
|
|
parentImage *image.Image
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
for _, image := range images {
|
|
|
|
parentImage, err = image.GetParent()
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Error while getting parent image: %v", err)
|
2014-08-05 01:11:02 -04:00
|
|
|
}
|
|
|
|
if parentImage != nil {
|
|
|
|
job.Stdout.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
|
|
|
|
} else {
|
|
|
|
job.Stdout.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for id, repos := range s.GetRepoRefs() {
|
|
|
|
job.Stdout.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
|
|
|
|
}
|
|
|
|
job.Stdout.Write([]byte(" base [style=invisible]\n}\n"))
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-08-05 01:11:02 -04:00
|
|
|
}
|