From 88d3e14ecea60d3747c49404a2ee2620d611f0af Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Thu, 28 Aug 2014 17:58:42 -0700 Subject: [PATCH] v2 image push: it works, but no signature yet --- graph/push.go | 9 +++++++-- registry/endpoint.go | 4 ++++ registry/session_prov.go | 5 ++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/graph/push.go b/graph/push.go index f2a366ae02c0f..39c77e4a81bfa 100644 --- a/graph/push.go +++ b/graph/push.go @@ -228,6 +228,9 @@ func (s *TagStore) CmdPush(job *engine.Job) engine.Status { return job.Error(err2) } + if len(tag) == 0 { + tag = DEFAULTTAG + } // XXX TESTING // 1) Check if TarSum of each layer exists /v2/ // 1.a) if 200, continue @@ -240,7 +243,7 @@ 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) - var manifestData map[string][]byte + var manifestData = make(map[string][]byte) // XXX unfortunately this goes from child to parent, // but the list of blobs in the manifest is expected to go parent to child @@ -267,6 +270,8 @@ func (s *TagStore) CmdPush(job *engine.Job) engine.Status { localChecksum := tsRdr.Sum(nil) if serverChecksum != localChecksum { return job.Error(fmt.Errorf("%q: failed checksum comparison. serverChecksum: %q, localChecksum: %q", remoteName, serverChecksum, localChecksum)) + } else { + log.Debugf("imgID: %q, serverChecksum: %q, localChecksum: %q", img.ID, serverChecksum, localChecksum) } // So dumb. This should be a call to the image.Image RawJson() @@ -302,7 +307,7 @@ func (s *TagStore) CmdPush(job *engine.Job) engine.Status { // Next, push the manifest log.Debugf("SUCH MANIFEST %s:%s -- %s", localName, tag, manifestBuf) - err = r.PutV2ImageManifest(localName, tag, bytes.NewReader(manifestBuf), nil) + err = r.PutV2ImageManifest(remoteName, tag, bytes.NewReader(manifestBuf), nil) if err != nil { return job.Error(err) } diff --git a/registry/endpoint.go b/registry/endpoint.go index 5444546eb32c2..d8071c532786e 100644 --- a/registry/endpoint.go +++ b/registry/endpoint.go @@ -41,11 +41,15 @@ func NewEndpoint(hostname string) (*Endpoint, error) { trimmedHostname string err error ) + if !strings.HasPrefix(hostname, "http") { + hostname = "https://" + hostname + } trimmedHostname, endpoint.Version = scanForApiVersion(hostname) endpoint.URL, err = url.Parse(trimmedHostname) if err != nil { return nil, err } + fmt.Printf("%#v\n", endpoint.URL) // XXX TESTING ONLY if drv := os.Getenv("DOCKER_REGISTRY_VERSION"); len(drv) > 0 { if v, err := strconv.Atoi(drv); err == nil { diff --git a/registry/session_prov.go b/registry/session_prov.go index ef6b3a7afc706..05625a6c8e94a 100644 --- a/registry/session_prov.go +++ b/registry/session_prov.go @@ -31,6 +31,9 @@ func getV2URL(e *Endpoint, routeName string, vars map[string]string) (*url.URL, return nil, fmt.Errorf("unable to make registry route %q with vars %v: %s", routeName, vars, err) } + fmt.Println(e.URL.Scheme) + fmt.Println(e.URL.Host) + return &url.URL{ Scheme: e.URL.Scheme, Host: e.URL.Host, @@ -251,7 +254,7 @@ func (r *Session) PutV2ImageManifest(imageName, tagName string, manifestRdr io.R return err } res.Body.Close() - if res.StatusCode != 200 { + if res.StatusCode != 201 { if res.StatusCode == 401 { return errLoginRequired }