2014-04-28 06:59:46 +00:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
2014-08-06 20:09:29 +00:00
|
|
|
"fmt"
|
2014-05-20 19:36:15 +00:00
|
|
|
"io"
|
2015-06-11 18:29:29 +00:00
|
|
|
"runtime"
|
2015-07-26 13:00:53 +00:00
|
|
|
"time"
|
2014-05-20 19:36:15 +00:00
|
|
|
|
2015-03-26 22:22:04 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-04-23 19:05:21 +00:00
|
|
|
"github.com/docker/docker/api/types"
|
2015-05-13 13:23:36 +00:00
|
|
|
"github.com/docker/docker/utils"
|
2014-04-28 06:59:46 +00:00
|
|
|
)
|
|
|
|
|
2015-07-29 23:45:47 +00:00
|
|
|
// lookupRaw looks up an image by name in a TagStore and returns the raw JSON
|
|
|
|
// describing the image.
|
2015-07-21 16:21:45 +00:00
|
|
|
func (s *TagStore) lookupRaw(name string) ([]byte, error) {
|
2015-04-23 19:05:21 +00:00
|
|
|
image, err := s.LookupImage(name)
|
|
|
|
if err != nil || image == nil {
|
|
|
|
return nil, fmt.Errorf("No such image %s", name)
|
|
|
|
}
|
|
|
|
|
2015-06-05 22:31:10 +00:00
|
|
|
imageInspectRaw, err := s.graph.RawJSON(image.ID)
|
2015-04-23 19:05:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2014-08-06 20:09:29 +00:00
|
|
|
}
|
2015-04-23 19:05:21 +00:00
|
|
|
|
|
|
|
return imageInspectRaw, nil
|
2014-04-28 06:59:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 23:45:47 +00:00
|
|
|
// Lookup looks up an image by name in a TagStore and returns it as an
|
|
|
|
// ImageInspect structure.
|
2015-04-23 19:05:21 +00:00
|
|
|
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 19:36:15 +00:00
|
|
|
}
|
2014-05-31 01:13:37 +00:00
|
|
|
|
2015-05-13 13:23:36 +00:00
|
|
|
var tags = make([]string, 0)
|
|
|
|
|
|
|
|
s.Lock()
|
|
|
|
for repoName, repository := range s.Repositories {
|
|
|
|
for ref, id := range repository {
|
|
|
|
if id == image.ID {
|
|
|
|
imgRef := utils.ImageReference(repoName, ref)
|
|
|
|
tags = append(tags, imgRef)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.Unlock()
|
|
|
|
|
2015-04-23 19:05:21 +00:00
|
|
|
imageInspect := &types.ImageInspect{
|
2015-07-23 09:40:54 +00:00
|
|
|
ID: image.ID,
|
2015-05-13 13:23:36 +00:00
|
|
|
Tags: tags,
|
2015-04-23 19:05:21 +00:00
|
|
|
Parent: image.Parent,
|
|
|
|
Comment: image.Comment,
|
2015-07-26 13:00:53 +00:00
|
|
|
Created: image.Created.Format(time.RFC3339Nano),
|
2015-04-23 19:05:21 +00:00
|
|
|
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-07-29 23:45:47 +00:00
|
|
|
VirtualSize: s.graph.GetParentsSize(image) + image.Size,
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
2015-04-23 19:05:21 +00:00
|
|
|
|
2015-06-15 18:05:10 +00: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 19:05:21 +00:00
|
|
|
return imageInspect, nil
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 17:59:45 +00:00
|
|
|
// ImageTarLayer return the tarLayer of the image
|
|
|
|
func (s *TagStore) ImageTarLayer(name string, dest io.Writer) error {
|
2014-05-20 19:36:15 +00:00
|
|
|
if image, err := s.LookupImage(name); err == nil && image != nil {
|
2015-06-11 18:29:29 +00: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 19:36:15 +00:00
|
|
|
|
2015-06-11 18:29:29 +00: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 19:36:15 +00:00
|
|
|
}
|
2015-03-25 07:44:12 +00:00
|
|
|
return nil
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|
2015-03-25 07:44:12 +00:00
|
|
|
return fmt.Errorf("No such image: %s", name)
|
2014-05-20 19:36:15 +00:00
|
|
|
}
|