github.com/iaintshine/docker@v1.8.2/graph/service.go (about) 1 package graph 2 3 import ( 4 "fmt" 5 "io" 6 "runtime" 7 "time" 8 9 "github.com/Sirupsen/logrus" 10 "github.com/docker/docker/api/types" 11 ) 12 13 func (s *TagStore) LookupRaw(name string) ([]byte, error) { 14 image, err := s.LookupImage(name) 15 if err != nil || image == nil { 16 return nil, fmt.Errorf("No such image %s", name) 17 } 18 19 imageInspectRaw, err := s.graph.RawJSON(image.ID) 20 if err != nil { 21 return nil, err 22 } 23 24 return imageInspectRaw, nil 25 } 26 27 // Lookup return an image encoded in JSON 28 func (s *TagStore) Lookup(name string) (*types.ImageInspect, error) { 29 image, err := s.LookupImage(name) 30 if err != nil || image == nil { 31 return nil, fmt.Errorf("No such image: %s", name) 32 } 33 34 imageInspect := &types.ImageInspect{ 35 Id: image.ID, 36 Parent: image.Parent, 37 Comment: image.Comment, 38 Created: image.Created.Format(time.RFC3339Nano), 39 Container: image.Container, 40 ContainerConfig: &image.ContainerConfig, 41 DockerVersion: image.DockerVersion, 42 Author: image.Author, 43 Config: image.Config, 44 Architecture: image.Architecture, 45 Os: image.OS, 46 Size: image.Size, 47 VirtualSize: s.graph.GetParentsSize(image, 0) + image.Size, 48 } 49 50 imageInspect.GraphDriver.Name = s.graph.driver.String() 51 52 graphDriverData, err := s.graph.driver.GetMetadata(image.ID) 53 if err != nil { 54 return nil, err 55 } 56 imageInspect.GraphDriver.Data = graphDriverData 57 return imageInspect, nil 58 } 59 60 // ImageTarLayer return the tarLayer of the image 61 func (s *TagStore) ImageTarLayer(name string, dest io.Writer) error { 62 if image, err := s.LookupImage(name); err == nil && image != nil { 63 // On Windows, the base layer cannot be exported 64 if runtime.GOOS != "windows" || image.Parent != "" { 65 66 fs, err := s.graph.TarLayer(image) 67 if err != nil { 68 return err 69 } 70 defer fs.Close() 71 72 written, err := io.Copy(dest, fs) 73 if err != nil { 74 return err 75 } 76 logrus.Debugf("rendered layer for %s of [%d] size", image.ID, written) 77 } 78 return nil 79 } 80 return fmt.Errorf("No such image: %s", name) 81 }