Skip to content

Commit

Permalink
graph.CmdPush: plumbing a /v2/ POC
Browse files Browse the repository at this point in the history
  • Loading branch information
vbatts committed Aug 28, 2014
1 parent 13f1dbe commit 7c9996c
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion graph/push.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package graph

import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
Expand All @@ -10,6 +12,8 @@ import (
"github.com/docker/docker/archive"
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/tarsum"
"github.com/docker/docker/registry"
"github.com/docker/docker/utils"
)
Expand Down Expand Up @@ -237,7 +241,68 @@ func (s *TagStore) CmdPush(job *engine.Job) engine.Status {
// XXX wait this requires having the TarSum of the layer.tar first
// skip this step for now. Just push the layer every time for this naive implementation
//shouldPush, err := r.PostV2ImageMountBlob(imageName, sumType, sum string, token []string)
_ = img
var (
manifestData map[string][]byte
imageName, tagName = parsers.ParseRepositoryTag(remoteName)
)
// XXX unfortunately this goes from child to parent,
// but the list of blobs in the manifest is expected to go parent to child
for currentImg := img; currentImg != nil; currentImg, err = currentImg.GetParent() {
arch, err := currentImg.TarLayer()
if err != nil {
return job.Error(err)
}
tsRdr := &tarsum.TarSum{Reader: arch, DisableCompression: false}
log.Debugf("SUCH PUSH ID %s", currentImg.ID)
serverChecksum, err := r.PostV2ImageBlob(imageName, "tarsum+sha256", tsRdr, nil)
if err != nil {
return job.Error(err)
}
localChecksum := tsRdr.Sum(nil)
if serverChecksum != localChecksum {
return job.Error(fmt.Errorf("%q: failed checksum comparison. serverChecksum: %q, localChecksum: %q", imageName, serverChecksum, localChecksum))
}
manifestData[localChecksum], err = currentImg.RawJson()
if err != nil {
return job.Error(err)
}

currentImg, err = currentImg.GetParent()
if err != nil {
return job.Error(err)
}
}

// Next, produce the merged/flattened "image json"
// ...

// Next, produce the manifest
blobSums := []string{}
for k := range manifestData {
blobSums = append(blobSums, k)
}
manifest := struct {
Name string
BlobSums []string
History []map[string][]byte
}{
Name: remoteName,
BlobSums: blobSums,
History: []map[string][]byte{
manifestData,
},
}
manifestBuf, err := json.Marshal(manifest)
if err != nil {
return job.Error(err)
}

// Next, push the manifest
log.Debugf("SUCH MANIFEST %s:%s -- %s", localName, tagName, manifestBuf)
err = r.PutV2ImageManifest(localName, tagName, bytes.NewReader(manifestBuf), nil)
if err != nil {
return job.Error(err)
}

// we should wrap up this CmdPush here
return engine.StatusOK
Expand Down

0 comments on commit 7c9996c

Please sign in to comment.