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"
|
2015-04-23 15:05:21 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2014-04-28 02:59:46 -04:00
|
|
|
)
|
|
|
|
|
2015-04-23 15:05:21 -04:00
|
|
|
func (s *TagStore) LookupRaw(name string) ([]byte, error) {
|
|
|
|
image, err := s.LookupImage(name)
|
|
|
|
if err != nil || image == nil {
|
|
|
|
return nil, fmt.Errorf("No such image %s", name)
|
|
|
|
}
|
|
|
|
|
2015-06-05 18:31:10 -04:00
|
|
|
imageInspectRaw, err := s.graph.RawJSON(image.ID)
|
2015-04-23 15:05:21 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-08-06 16:09:29 -04:00
|
|
|
}
|
2015-04-23 15:05:21 -04:00
|
|
|
|
|
|
|
return imageInspectRaw, nil
|
2014-04-28 02:59:46 -04:00
|
|
|
}
|
|
|
|
|
2015-04-23 15:05:21 -04:00
|
|
|
// Lookup return an image encoded in JSON
|
|
|
|
func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) {
|
|
|
|
image, err := s.LookupImage(name)
|
|
|
|
if err != nil || image == nil {
|
|
|
|
return nil, fmt.Errorf("No such image: %s", name)
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2014-05-30 21:13:37 -04:00
|
|
|
|
2015-04-23 15:05:21 -04:00
|
|
|
imageInspect := &types.ImageInspect{
|
|
|
|
Id: image.ID,
|
|
|
|
Parent: image.Parent,
|
|
|
|
Comment: image.Comment,
|
|
|
|
Created: image.Created,
|
|
|
|
Container: image.Container,
|
|
|
|
ContainerConfig: &image.ContainerConfig,
|
|
|
|
DockerVersion: image.DockerVersion,
|
|
|
|
Author: image.Author,
|
|
|
|
Config: image.Config,
|
|
|
|
Architecture: image.Architecture,
|
|
|
|
Os: image.OS,
|
|
|
|
Size: image.Size,
|
2015-06-05 18:31:10 -04:00
|
|
|
VirtualSize: s.graph.GetParentsSize(image, 0) + image.Size,
|
2014-05-20 15:36:15 -04:00
|
|
|
}
|
2015-04-23 15:05:21 -04:00
|
|
|
|
2015-06-15 14:05:10 -04:00
|
|
|
imageInspect.GraphDriver.Name = s.graph.driver.String()
|
|
|
|
|
|
|
|
graphDriverData, err := s.graph.driver.GetMetadata(image.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
imageInspect.GraphDriver.Data = graphDriverData
|
2015-04-23 15:05:21 -04:00
|
|
|
return imageInspect, nil
|
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 {
|
2015-06-05 18:31:10 -04:00
|
|
|
fs, err := s.graph.TarLayer(image)
|
2014-05-20 15:36:15 -04:00
|
|
|
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
|
|
|
}
|