github.com/guilhermebr/docker@v1.4.2-0.20150428121140-67da055cebca/graph/service.go (about)

     1  package graph
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  
     7  	"github.com/Sirupsen/logrus"
     8  	"github.com/docker/docker/api/types"
     9  )
    10  
    11  func (s *TagStore) LookupRaw(name string) ([]byte, error) {
    12  	image, err := s.LookupImage(name)
    13  	if err != nil || image == nil {
    14  		return nil, fmt.Errorf("No such image %s", name)
    15  	}
    16  
    17  	imageInspectRaw, err := image.RawJson()
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  
    22  	return imageInspectRaw, nil
    23  }
    24  
    25  // Lookup return an image encoded in JSON
    26  func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) {
    27  	image, err := s.LookupImage(name)
    28  	if err != nil || image == nil {
    29  		return nil, fmt.Errorf("No such image: %s", name)
    30  	}
    31  
    32  	imageInspect := &types.ImageInspect{
    33  		Id:              image.ID,
    34  		Parent:          image.Parent,
    35  		Comment:         image.Comment,
    36  		Created:         image.Created,
    37  		Container:       image.Container,
    38  		ContainerConfig: &image.ContainerConfig,
    39  		DockerVersion:   image.DockerVersion,
    40  		Author:          image.Author,
    41  		Config:          image.Config,
    42  		Architecture:    image.Architecture,
    43  		Os:              image.OS,
    44  		Size:            image.Size,
    45  		VirtualSize:     image.GetParentsSize(0) + image.Size,
    46  	}
    47  
    48  	return imageInspect, nil
    49  }
    50  
    51  // ImageTarLayer return the tarLayer of the image
    52  func (s *TagStore) ImageTarLayer(name string, dest io.Writer) error {
    53  	if image, err := s.LookupImage(name); err == nil && image != nil {
    54  		fs, err := image.TarLayer()
    55  		if err != nil {
    56  			return err
    57  		}
    58  		defer fs.Close()
    59  
    60  		written, err := io.Copy(dest, fs)
    61  		if err != nil {
    62  			return err
    63  		}
    64  		logrus.Debugf("rendered layer for %s of [%d] size", image.ID, written)
    65  		return nil
    66  	}
    67  	return fmt.Errorf("No such image: %s", name)
    68  }