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-06-11 14:29:29 -04:00
|
|
|
"runtime"
|
2015-07-26 09:00:53 -04:00
|
|
|
"time"
|
2014-05-20 15:36:15 -04:00
|
|
|
|
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"
|
2015-05-13 09:23:36 -04:00
|
|
|
"github.com/docker/docker/utils"
|
2014-04-28 02:59:46 -04:00
|
|
|
)
|
|
|
|
|
2015-07-29 19:45:47 -04:00
|
|
|
// Lookup looks up an image by name in a TagStore and returns it as an
|
|
|
|
// ImageInspect structure.
|
2015-04-23 15:05:21 -04: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 15:36:15 -04:00
|
|
|
}
|
2014-05-30 21:13:37 -04:00
|
|
|
|
2015-05-13 09:23:36 -04: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 15:05:21 -04:00
|
|
|
imageInspect := &types.ImageInspect{
|
2015-07-23 05:40:54 -04:00
|
|
|
ID: image.ID,
|
2015-05-13 09:23:36 -04:00
|
|
|
Tags: tags,
|
2015-04-23 15:05:21 -04:00
|
|
|
Parent: image.Parent,
|
|
|
|
Comment: image.Comment,
|
2015-07-26 09:00:53 -04:00
|
|
|
Created: image.Created.Format(time.RFC3339Nano),
|
2015-04-23 15:05:21 -04: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 19:45:47 -04:00
|
|
|
VirtualSize: s.graph.GetParentsSize(image) + 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-11 14:29:29 -04: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 15:36:15 -04:00
|
|
|
|
2015-06-11 14:29:29 -04: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 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
|
|
|
}
|