|
@@ -82,22 +82,6 @@ type Graph struct {
|
|
|
retained *retainedLayers
|
|
|
}
|
|
|
|
|
|
-type Image struct {
|
|
|
- ID string `json:"id"`
|
|
|
- Parent string `json:"parent,omitempty"`
|
|
|
- Comment string `json:"comment,omitempty"`
|
|
|
- Created time.Time `json:"created"`
|
|
|
- Container string `json:"container,omitempty"`
|
|
|
- ContainerConfig runconfig.Config `json:"container_config,omitempty"`
|
|
|
- DockerVersion string `json:"docker_version,omitempty"`
|
|
|
- Author string `json:"author,omitempty"`
|
|
|
- Config *runconfig.Config `json:"config,omitempty"`
|
|
|
- Architecture string `json:"architecture,omitempty"`
|
|
|
- OS string `json:"os,omitempty"`
|
|
|
- Size int64
|
|
|
- graph Graph
|
|
|
-}
|
|
|
-
|
|
|
var (
|
|
|
// ErrDigestNotSet is used when request the digest for a layer
|
|
|
// but the layer has no digest value or content to compute the
|
|
@@ -174,7 +158,7 @@ func (graph *Graph) Exists(id string) bool {
|
|
|
}
|
|
|
|
|
|
// Get returns the image with the given id, or an error if the image doesn't exist.
|
|
|
-func (graph *Graph) Get(name string) (*Image, error) {
|
|
|
+func (graph *Graph) Get(name string) (*image.Image, error) {
|
|
|
id, err := graph.idIndex.Get(name)
|
|
|
if err != nil {
|
|
|
return nil, fmt.Errorf("could not find image: %v", err)
|
|
@@ -202,8 +186,8 @@ func (graph *Graph) Get(name string) (*Image, error) {
|
|
|
}
|
|
|
|
|
|
// Create creates a new image and registers it in the graph.
|
|
|
-func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*Image, error) {
|
|
|
- img := &Image{
|
|
|
+func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, containerImage, comment, author string, containerConfig, config *runconfig.Config) (*image.Image, error) {
|
|
|
+ img := &image.Image{
|
|
|
ID: stringid.GenerateRandomID(),
|
|
|
Comment: comment,
|
|
|
Created: time.Now().UTC(),
|
|
@@ -227,7 +211,7 @@ func (graph *Graph) Create(layerData archive.ArchiveReader, containerID, contain
|
|
|
}
|
|
|
|
|
|
// Register imports a pre-existing image into the graph.
|
|
|
-func (graph *Graph) Register(img *Image, layerData archive.ArchiveReader) (err error) {
|
|
|
+func (graph *Graph) Register(img *image.Image, layerData archive.ArchiveReader) (err error) {
|
|
|
|
|
|
if err := image.ValidateID(img.ID); err != nil {
|
|
|
return err
|
|
@@ -380,9 +364,9 @@ func (graph *Graph) Delete(name string) error {
|
|
|
}
|
|
|
|
|
|
// Map returns a list of all images in the graph, addressable by ID.
|
|
|
-func (graph *Graph) Map() map[string]*Image {
|
|
|
- images := make(map[string]*Image)
|
|
|
- graph.walkAll(func(image *Image) {
|
|
|
+func (graph *Graph) Map() map[string]*image.Image {
|
|
|
+ images := make(map[string]*image.Image)
|
|
|
+ graph.walkAll(func(image *image.Image) {
|
|
|
images[image.ID] = image
|
|
|
})
|
|
|
return images
|
|
@@ -390,7 +374,7 @@ func (graph *Graph) Map() map[string]*Image {
|
|
|
|
|
|
// walkAll iterates over each image in the graph, and passes it to a handler.
|
|
|
// The walking order is undetermined.
|
|
|
-func (graph *Graph) walkAll(handler func(*Image)) {
|
|
|
+func (graph *Graph) walkAll(handler func(*image.Image)) {
|
|
|
graph.idIndex.Iterate(func(id string) {
|
|
|
if img, err := graph.Get(id); err != nil {
|
|
|
return
|
|
@@ -404,9 +388,9 @@ func (graph *Graph) walkAll(handler func(*Image)) {
|
|
|
// If an image of id ID has 3 children images, then the value for key ID
|
|
|
// will be a list of 3 images.
|
|
|
// If an image has no children, it will not have an entry in the table.
|
|
|
-func (graph *Graph) ByParent() map[string][]*Image {
|
|
|
- byParent := make(map[string][]*Image)
|
|
|
- graph.walkAll(func(img *Image) {
|
|
|
+func (graph *Graph) ByParent() map[string][]*image.Image {
|
|
|
+ byParent := make(map[string][]*image.Image)
|
|
|
+ graph.walkAll(func(img *image.Image) {
|
|
|
parent, err := graph.Get(img.Parent)
|
|
|
if err != nil {
|
|
|
return
|
|
@@ -414,7 +398,7 @@ func (graph *Graph) ByParent() map[string][]*Image {
|
|
|
if children, exists := byParent[parent.ID]; exists {
|
|
|
byParent[parent.ID] = append(children, img)
|
|
|
} else {
|
|
|
- byParent[parent.ID] = []*Image{img}
|
|
|
+ byParent[parent.ID] = []*image.Image{img}
|
|
|
}
|
|
|
})
|
|
|
return byParent
|
|
@@ -433,10 +417,10 @@ func (graph *Graph) Release(sessionID string, layerIDs ...string) {
|
|
|
|
|
|
// Heads returns all heads in the graph, keyed by id.
|
|
|
// A head is an image which is not the parent of another image in the graph.
|
|
|
-func (graph *Graph) Heads() map[string]*Image {
|
|
|
- heads := make(map[string]*Image)
|
|
|
+func (graph *Graph) Heads() map[string]*image.Image {
|
|
|
+ heads := make(map[string]*image.Image)
|
|
|
byParent := graph.ByParent()
|
|
|
- graph.walkAll(func(image *Image) {
|
|
|
+ graph.walkAll(func(image *image.Image) {
|
|
|
// If it's not in the byParent lookup table, then
|
|
|
// it's not a parent -> so it's a head!
|
|
|
if _, exists := byParent[image.ID]; !exists {
|
|
@@ -451,7 +435,7 @@ func (graph *Graph) imageRoot(id string) string {
|
|
|
}
|
|
|
|
|
|
// loadImage fetches the image with the given id from the graph.
|
|
|
-func (graph *Graph) loadImage(id string) (*Image, error) {
|
|
|
+func (graph *Graph) loadImage(id string) (*image.Image, error) {
|
|
|
root := graph.imageRoot(id)
|
|
|
|
|
|
// Open the JSON file to decode by streaming
|
|
@@ -461,7 +445,7 @@ func (graph *Graph) loadImage(id string) (*Image, error) {
|
|
|
}
|
|
|
defer jsonSource.Close()
|
|
|
|
|
|
- img := &Image{}
|
|
|
+ img := &image.Image{}
|
|
|
dec := json.NewDecoder(jsonSource)
|
|
|
|
|
|
// Decode the JSON data
|
|
@@ -538,14 +522,3 @@ func (graph *Graph) RawJSON(id string) ([]byte, error) {
|
|
|
func jsonPath(root string) string {
|
|
|
return filepath.Join(root, "json")
|
|
|
}
|
|
|
-
|
|
|
-// Build an Image object from raw json data
|
|
|
-func NewImgJSON(src []byte) (*Image, error) {
|
|
|
- ret := &Image{}
|
|
|
-
|
|
|
- // FIXME: Is there a cleaner way to "purify" the input json?
|
|
|
- if err := json.Unmarshal(src, ret); err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
- return ret, nil
|
|
|
-}
|