2014-04-28 10:59:46 +04:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
2014-08-07 00:09:29 +04:00
|
|
|
"fmt"
|
2014-05-20 23:36:15 +04:00
|
|
|
"io"
|
2015-06-11 21:29:29 +03:00
|
|
|
"runtime"
|
2014-05-20 23:36:15 +04:00
|
|
|
|
2015-03-27 01:22:04 +03:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-04-23 22:05:21 +03:00
|
|
|
"github.com/docker/docker/api/types"
|
2014-04-28 10:59:46 +04:00
|
|
|
)
|
|
|
|
|
2015-04-23 22:05:21 +03: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-06 01:31:10 +03:00
|
|
|
imageInspectRaw, err := s.graph.RawJSON(image.ID)
|
2015-04-23 22:05:21 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-08-07 00:09:29 +04:00
|
|
|
}
|
2015-04-23 22:05:21 +03:00
|
|
|
|
|
|
|
return imageInspectRaw, nil
|
2014-04-28 10:59:46 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 22:05:21 +03: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 23:36:15 +04:00
|
|
|
}
|
2014-05-31 05:13:37 +04:00
|
|
|
|
2015-04-23 22:05:21 +03: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-06 01:31:10 +03:00
|
|
|
VirtualSize: s.graph.GetParentsSize(image, 0) + image.Size,
|
2014-05-20 23:36:15 +04:00
|
|
|
}
|
2015-04-23 22:05:21 +03:00
|
|
|
|
2015-06-15 21:05:10 +03: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 22:05:21 +03:00
|
|
|
return imageInspect, nil
|
2014-05-20 23:36:15 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 20:59:45 +03:00
|
|
|
// ImageTarLayer return the tarLayer of the image
|
|
|
|
func (s *TagStore) ImageTarLayer(name string, dest io.Writer) error {
|
2014-05-20 23:36:15 +04:00
|
|
|
if image, err := s.LookupImage(name); err == nil && image != nil {
|
2015-06-11 21:29:29 +03:00
|
|
|
// On Windows, the base layer cannot be exported
|
|
|
|
if runtime.GOOS != "windows" || image.Parent != "" {
|
|
|
|
|
|
|
|
fs, err := s.graph.TarLayer(image)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fs.Close()
|
2014-05-20 23:36:15 +04:00
|
|
|
|
2015-06-11 21:29:29 +03:00
|
|
|
written, err := io.Copy(dest, fs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.Debugf("rendered layer for %s of [%d] size", image.ID, written)
|
2014-05-20 23:36:15 +04:00
|
|
|
}
|
2015-03-25 10:44:12 +03:00
|
|
|
return nil
|
2014-05-20 23:36:15 +04:00
|
|
|
}
|
2015-03-25 10:44:12 +03:00
|
|
|
return fmt.Errorf("No such image: %s", name)
|
2014-05-20 23:36:15 +04:00
|
|
|
}
|