Merge pull request #4489 from crosbymichael/bump_v0.9.0

Bump to version 0.9.0
This commit is contained in:
Michael Crosby 2014-03-10 10:04:33 -07:00
commit e7d288d8d7
2 changed files with 23 additions and 19 deletions

View file

@ -2,6 +2,7 @@ package registry
import ( import (
"bytes" "bytes"
"crypto/sha256"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -91,7 +92,7 @@ func validateRepositoryName(repositoryName string) error {
return nil return nil
} }
// Resolves a repository name to a endpoint + name // Resolves a repository name to a hostname + name
func ResolveRepositoryName(reposName string) (string, string, error) { func ResolveRepositoryName(reposName string) (string, string, error) {
if strings.Contains(reposName, "://") { if strings.Contains(reposName, "://") {
// It cannot contain a scheme! // It cannot contain a scheme!
@ -117,11 +118,8 @@ func ResolveRepositoryName(reposName string) (string, string, error) {
if err := validateRepositoryName(reposName); err != nil { if err := validateRepositoryName(reposName); err != nil {
return "", "", err return "", "", err
} }
endpoint, err := ExpandAndVerifyRegistryUrl(hostname)
if err != nil { return hostname, reposName, nil
return "", "", err
}
return endpoint, reposName, err
} }
// this method expands the registry name as used in the prefix of a repo // this method expands the registry name as used in the prefix of a repo
@ -388,6 +386,7 @@ func (r *Registry) PushImageChecksumRegistry(imgData *ImgData, registry string,
} }
setTokenAuth(req, token) setTokenAuth(req, token)
req.Header.Set("X-Docker-Checksum", imgData.Checksum) req.Header.Set("X-Docker-Checksum", imgData.Checksum)
req.Header.Set("X-Docker-Checksum-Payload", imgData.ChecksumPayload)
res, err := doWithCookies(r.client, req) res, err := doWithCookies(r.client, req)
if err != nil { if err != nil {
@ -446,26 +445,28 @@ func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, regis
return nil return nil
} }
func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registry string, token []string, jsonRaw []byte) (checksum string, err error) { func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registry string, token []string, jsonRaw []byte) (checksum string, checksumPayload string, err error) {
utils.Debugf("[registry] Calling PUT %s", registry+"images/"+imgID+"/layer") utils.Debugf("[registry] Calling PUT %s", registry+"images/"+imgID+"/layer")
tarsumLayer := &utils.TarSum{Reader: layer} h := sha256.New()
checksumLayer := &utils.CheckSum{Reader: layer, Hash: h}
tarsumLayer := &utils.TarSum{Reader: checksumLayer}
req, err := r.reqFactory.NewRequest("PUT", registry+"images/"+imgID+"/layer", tarsumLayer) req, err := r.reqFactory.NewRequest("PUT", registry+"images/"+imgID+"/layer", tarsumLayer)
if err != nil { if err != nil {
return "", err return "", "", err
} }
req.ContentLength = -1 req.ContentLength = -1
req.TransferEncoding = []string{"chunked"} req.TransferEncoding = []string{"chunked"}
setTokenAuth(req, token) setTokenAuth(req, token)
res, err := doWithCookies(r.client, req) res, err := doWithCookies(r.client, req)
if err != nil { if err != nil {
return "", fmt.Errorf("Failed to upload layer: %s", err) return "", "", fmt.Errorf("Failed to upload layer: %s", err)
} }
if rc, ok := layer.(io.Closer); ok { if rc, ok := layer.(io.Closer); ok {
if err := rc.Close(); err != nil { if err := rc.Close(); err != nil {
return "", err return "", "", err
} }
} }
defer res.Body.Close() defer res.Body.Close()
@ -473,11 +474,13 @@ func (r *Registry) PushImageLayerRegistry(imgID string, layer io.Reader, registr
if res.StatusCode != 200 { if res.StatusCode != 200 {
errBody, err := ioutil.ReadAll(res.Body) errBody, err := ioutil.ReadAll(res.Body)
if err != nil { if err != nil {
return "", utils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res) return "", "", utils.NewHTTPRequestError(fmt.Sprintf("HTTP code %d while uploading metadata and error when trying to parse response body: %s", res.StatusCode, err), res)
} }
return "", utils.NewHTTPRequestError(fmt.Sprintf("Received HTTP code %d while uploading layer: %s", res.StatusCode, errBody), res) return "", "", utils.NewHTTPRequestError(fmt.Sprintf("Received HTTP code %d while uploading layer: %s", res.StatusCode, errBody), res)
} }
return tarsumLayer.Sum(jsonRaw), nil
checksumPayload = "sha256:" + checksumLayer.Sum()
return tarsumLayer.Sum(jsonRaw), checksumPayload, nil
} }
// push a tag on the registry. // push a tag on the registry.
@ -673,6 +676,7 @@ type RepositoryData struct {
type ImgData struct { type ImgData struct {
ID string `json:"id"` ID string `json:"id"`
Checksum string `json:"checksum,omitempty"` Checksum string `json:"checksum,omitempty"`
ChecksumPayload string `json:"-"`
Tag string `json:",omitempty"` Tag string `json:",omitempty"`
} }

View file

@ -124,7 +124,7 @@ func TestPushImageJSONRegistry(t *testing.T) {
func TestPushImageLayerRegistry(t *testing.T) { func TestPushImageLayerRegistry(t *testing.T) {
r := spawnTestRegistry(t) r := spawnTestRegistry(t)
layer := strings.NewReader("") layer := strings.NewReader("")
_, err := r.PushImageLayerRegistry(IMAGE_ID, layer, makeURL("/v1/"), TOKEN, []byte{}) _, _, err := r.PushImageLayerRegistry(IMAGE_ID, layer, makeURL("/v1/"), TOKEN, []byte{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -145,7 +145,7 @@ func TestResolveRepositoryName(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
assertEqual(t, ep, "http://"+u+"/v1/", "Expected endpoint to be "+u) assertEqual(t, ep, u, "Expected endpoint to be "+u)
assertEqual(t, repo, "private/moonbase", "Expected endpoint to be private/moonbase") assertEqual(t, repo, "private/moonbase", "Expected endpoint to be private/moonbase")
} }