2014-04-28 02:59:46 -04:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
2014-08-06 16:09:29 -04:00
|
|
|
"fmt"
|
2014-05-20 15:36:15 -04:00
|
|
|
"io"
|
|
|
|
|
2015-03-26 18:22:04 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/engine"
|
2014-04-28 02:59:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *TagStore) Install(eng *engine.Engine) error {
|
2014-08-06 16:09:29 -04:00
|
|
|
for name, handler := range map[string]engine.Handler{
|
2015-04-21 13:59:45 -04:00
|
|
|
"image_inspect": s.CmdLookup,
|
|
|
|
"viz": s.CmdViz,
|
2014-08-06 16:09:29 -04:00
|
|
|
} {
|
|
|
|
if err := eng.Register(name, handler); err != nil {
|
|
|
|
return fmt.Errorf("Could not register %q: %v", name, err)
|
|
|
|
}
|
|
|
|
}
|
2014-04-28 02:59:46 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2014-05-20 15:36:15 -04:00
|
|
|
// CmdLookup return an image encoded in JSON
|
2015-03-25 03:44:12 -04:00
|
|
|
func (s *TagStore) CmdLookup(job *engine.Job) error {
|
2014-05-20 15:36:15 -04:00
|
|
|
if len(job.Args) != 1 {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("usage: %s NAME", job.Name)
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
|
|
|
name := job.Args[0]
|
|
|
|
if image, err := s.LookupImage(name); err == nil && image != nil {
|
2014-06-16 20:06:21 -04:00
|
|
|
if job.GetenvBool("raw") {
|
2014-06-17 09:05:29 -04:00
|
|
|
b, err := image.RawJson()
|
2014-05-30 21:13:37 -04:00
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-05-30 21:13:37 -04:00
|
|
|
}
|
|
|
|
job.Stdout.Write(b)
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-05-30 21:13:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
out := &engine.Env{}
|
2014-12-11 07:56:21 -05:00
|
|
|
out.SetJson("Id", image.ID)
|
|
|
|
out.SetJson("Parent", image.Parent)
|
|
|
|
out.SetJson("Comment", image.Comment)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetAuto("Created", image.Created)
|
2014-12-11 07:56:21 -05:00
|
|
|
out.SetJson("Container", image.Container)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetJson("ContainerConfig", image.ContainerConfig)
|
|
|
|
out.Set("DockerVersion", image.DockerVersion)
|
2014-12-11 07:56:21 -05:00
|
|
|
out.SetJson("Author", image.Author)
|
2014-05-30 21:13:37 -04:00
|
|
|
out.SetJson("Config", image.Config)
|
|
|
|
out.Set("Architecture", image.Architecture)
|
|
|
|
out.Set("Os", image.OS)
|
|
|
|
out.SetInt64("Size", image.Size)
|
2014-09-22 20:42:32 -04:00
|
|
|
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
2014-05-30 21:13:37 -04:00
|
|
|
if _, err = out.WriteTo(job.Stdout); err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("No such image: %s", name)
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
|
|
|
|
2015-04-21 13:59:45 -04:00
|
|
|
// ImageTarLayer return the tarLayer of the image
|
|
|
|
func (s *TagStore) ImageTarLayer(name string, dest io.Writer) error {
|
2014-05-20 15:36:15 -04:00
|
|
|
if image, err := s.LookupImage(name); err == nil && image != nil {
|
|
|
|
fs, err := image.TarLayer()
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
|
|
|
defer fs.Close()
|
|
|
|
|
2015-04-21 13:59:45 -04:00
|
|
|
written, err := io.Copy(dest, fs)
|
2014-08-29 07:21:28 -04:00
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-03-26 18:22:04 -04:00
|
|
|
logrus.Debugf("rendered layer for %s of [%d] size", image.ID, written)
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("No such image: %s", name)
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|