From 7a664e6a5f0b8b8a11167789b817b2dd5185940d Mon Sep 17 00:00:00 2001 From: shin- Date: Fri, 24 May 2013 10:37:34 -0700 Subject: [PATCH 1/5] Tentative support for independent registries --- docs/registry.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/registry.go b/docs/registry.go index c565c299..5d642b39 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -56,20 +56,19 @@ func (r *Registry) GetRemoteHistory(imgId, registry string, token []string) ([]s } // Check if an image exists in the Registry -func (r *Registry) LookupRemoteImage(imgId, registry string, authConfig *auth.AuthConfig) bool { +func (r *Registry) LookupRemoteImage(imgId, registry string, token []string) bool { rt := &http.Transport{Proxy: http.ProxyFromEnvironment} req, err := http.NewRequest("GET", registry+"/images/"+imgId+"/json", nil) if err != nil { return false } - req.SetBasicAuth(authConfig.Username, authConfig.Password) res, err := rt.RoundTrip(req) if err != nil { return false } res.Body.Close() - return res.StatusCode == 307 + return res.StatusCode == 200 } func (r *Registry) getImagesInRepository(repository string, authConfig *auth.AuthConfig) ([]map[string]string, error) { From dc97156c832f7262196d141844d9752299086b20 Mon Sep 17 00:00:00 2001 From: shin- Date: Wed, 29 May 2013 11:24:50 -0700 Subject: [PATCH 2/5] Skip certificate check (don't error out on self-signed certs) --- docs/registry.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/registry.go b/docs/registry.go index 5d642b39..864f3e8b 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -2,6 +2,7 @@ package registry import ( "bytes" + "crypto/tls" "encoding/json" "errors" "fmt" @@ -164,6 +165,7 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [ if err != nil { return nil, err } + utils.Debugf("Got status code %d from %s", res.StatusCode, endpoint) defer res.Body.Close() From e1d8d0245fbb8b48546431cc938262c1a28bb8e2 Mon Sep 17 00:00:00 2001 From: shin- Date: Wed, 29 May 2013 11:39:31 -0700 Subject: [PATCH 3/5] Rolled back of previous commit (skip cert verification) --- docs/registry.go | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/registry.go b/docs/registry.go index 864f3e8b..30b91cef 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -2,7 +2,6 @@ package registry import ( "bytes" - "crypto/tls" "encoding/json" "errors" "fmt" From 259eeb382c03fd672e83a67a95a7384d3b370019 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 5 Jun 2013 15:12:50 -0700 Subject: [PATCH 4/5] Remove https prefix from registry --- docs/registry.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/registry.go b/docs/registry.go index 30b91cef..29a1f29e 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -154,7 +154,7 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [ repository = "library/" + repository } for _, host := range registries { - endpoint := fmt.Sprintf("https://%s/v1/repositories/%s/tags", host, repository) + endpoint := fmt.Sprintf("%s/v1/repositories/%s/tags", host, repository) req, err := r.opaqueRequest("GET", endpoint, nil) if err != nil { return nil, err @@ -249,7 +249,7 @@ func (r *Registry) GetRepositoryData(remote string) (*RepositoryData, error) { // Push a local image to the registry func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, registry string, token []string) error { - registry = "https://" + registry + "/v1" + registry = registry + "/v1" // FIXME: try json with UTF8 req, err := http.NewRequest("PUT", registry+"/images/"+imgData.ID+"/json", strings.NewReader(string(jsonRaw))) if err != nil { @@ -285,7 +285,7 @@ func (r *Registry) PushImageJSONRegistry(imgData *ImgData, jsonRaw []byte, regis } func (r *Registry) PushImageLayerRegistry(imgId string, layer io.Reader, registry string, token []string) error { - registry = "https://" + registry + "/v1" + registry = registry + "/v1" req, err := http.NewRequest("PUT", registry+"/images/"+imgId+"/layer", layer) if err != nil { return err @@ -323,7 +323,7 @@ func (r *Registry) opaqueRequest(method, urlStr string, body io.Reader) (*http.R func (r *Registry) PushRegistryTag(remote, revision, tag, registry string, token []string) error { // "jsonify" the string revision = "\"" + revision + "\"" - registry = "https://" + registry + "/v1" + registry = registry + "/v1" req, err := r.opaqueRequest("PUT", registry+"/repositories/"+remote+"/tags/"+tag, strings.NewReader(revision)) if err != nil { From 03a77bd8511bf59481524bd70c5d313ae863cfeb Mon Sep 17 00:00:00 2001 From: shin- Date: Fri, 28 Jun 2013 18:42:37 +0200 Subject: [PATCH 5/5] Fixed issue in registry.GetRemoteTags --- docs/registry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/registry.go b/docs/registry.go index 29a1f29e..456e4321 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -155,6 +155,9 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [ } for _, host := range registries { endpoint := fmt.Sprintf("%s/v1/repositories/%s/tags", host, repository) + if !(strings.HasPrefix(endpoint, "http://") || strings.HasPrefix(endpoint, "https://")) { + endpoint = "https://" + endpoint + } req, err := r.opaqueRequest("GET", endpoint, nil) if err != nil { return nil, err