mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implemented checksum computation on image creation (necessary for new push primitive)
This commit is contained in:
parent
7c1a27e2ad
commit
048fd671ef
3 changed files with 20 additions and 4 deletions
13
container.go
13
container.go
|
@ -1,6 +1,7 @@
|
|||
package docker
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/rcli"
|
||||
|
@ -695,6 +696,18 @@ func (container *Container) ExportRw() (Archive, error) {
|
|||
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) {
|
||||
if err := container.EnsureMounted(); err != nil {
|
||||
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.Container = container.Id
|
||||
img.ContainerConfig = *container.Config
|
||||
if config == nil {
|
||||
if parentImage, err := graph.Get(container.Image); err == nil && parentImage != nil {
|
||||
img.Config = parentImage.Config
|
||||
}
|
||||
// FIXME: If an image is pulled from a raw URL (not created from a container),
|
||||
// its checksum will not be computed, which will cause a push to fail
|
||||
checksum, err := container.RwChecksum()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
img.Checksum = checksum
|
||||
}
|
||||
if err := graph.Register(layerData, img); err != nil {
|
||||
return nil, err
|
||||
|
|
1
image.go
1
image.go
|
@ -18,6 +18,7 @@ import (
|
|||
type Image struct {
|
||||
Id string `json:"id"`
|
||||
Parent string `json:"parent,omitempty"`
|
||||
Checksum string `json:"checksum,omitempty"`
|
||||
Comment string `json:"comment,omitempty"`
|
||||
Created time.Time `json:"created"`
|
||||
Container string `json:"container,omitempty"`
|
||||
|
|
Loading…
Add table
Reference in a new issue