mirror of https://github.com/docker/docs.git
Implemented checksum computation on image creation (necessary for new push primitive)
This commit is contained in:
parent
7c1a27e2ad
commit
048fd671ef
13
container.go
13
container.go
|
@ -1,6 +1,7 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/rcli"
|
"github.com/dotcloud/docker/rcli"
|
||||||
|
@ -695,6 +696,18 @@ func (container *Container) ExportRw() (Archive, error) {
|
||||||
return Tar(container.rwPath(), Uncompressed)
|
return Tar(container.rwPath(), Uncompressed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) RwChecksum() (string, error) {
|
||||||
|
h := sha256.New()
|
||||||
|
rwData, err := container.ExportRw()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if _, err := io.Copy(h, rwData); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(h.Sum(nil)), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) Export() (Archive, error) {
|
func (container *Container) Export() (Archive, error) {
|
||||||
if err := container.EnsureMounted(); err != nil {
|
if err := container.EnsureMounted(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
10
graph.go
10
graph.go
|
@ -98,11 +98,13 @@ func (graph *Graph) Create(layerData Archive, container *Container, comment, aut
|
||||||
img.Parent = container.Image
|
img.Parent = container.Image
|
||||||
img.Container = container.Id
|
img.Container = container.Id
|
||||||
img.ContainerConfig = *container.Config
|
img.ContainerConfig = *container.Config
|
||||||
if config == nil {
|
// FIXME: If an image is pulled from a raw URL (not created from a container),
|
||||||
if parentImage, err := graph.Get(container.Image); err == nil && parentImage != nil {
|
// its checksum will not be computed, which will cause a push to fail
|
||||||
img.Config = parentImage.Config
|
checksum, err := container.RwChecksum()
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
img.Checksum = checksum
|
||||||
}
|
}
|
||||||
if err := graph.Register(layerData, img); err != nil {
|
if err := graph.Register(layerData, img); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
1
image.go
1
image.go
|
@ -18,6 +18,7 @@ import (
|
||||||
type Image struct {
|
type Image struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
Parent string `json:"parent,omitempty"`
|
Parent string `json:"parent,omitempty"`
|
||||||
|
Checksum string `json:"checksum,omitempty"`
|
||||||
Comment string `json:"comment,omitempty"`
|
Comment string `json:"comment,omitempty"`
|
||||||
Created time.Time `json:"created"`
|
Created time.Time `json:"created"`
|
||||||
Container string `json:"container,omitempty"`
|
Container string `json:"container,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue