diff --git a/glide.yaml b/glide.yaml deleted file mode 100644 index 9c0dffd9..00000000 --- a/glide.yaml +++ /dev/null @@ -1,9 +0,0 @@ -package: github.com/rusenask/docker-registry-client -import: -- package: github.com/docker/distribution - version: 5db89f0ca68677abc5eefce8f2a0a772c98ba52d - subpackages: - - manifest/schema1 - - manifest/schema2 -- package: github.com/opencontainers/go-digest - version: ^1.0.0-rc0 diff --git a/registry/layer.go b/registry/layer.go deleted file mode 100644 index 094c894c..00000000 --- a/registry/layer.go +++ /dev/null @@ -1,108 +0,0 @@ -package registry - -import ( - "io" - "net/http" - "net/url" - - "github.com/docker/distribution" - "github.com/docker/distribution/digest" -) - -func (registry *Registry) DownloadLayer(repository string, digest digest.Digest) (io.ReadCloser, error) { - url := registry.url("/v2/%s/blobs/%s", repository, digest) - registry.Logf("registry.layer.download url=%s repository=%s digest=%s", url, repository, digest) - - resp, err := registry.Client.Get(url) - if err != nil { - return nil, err - } - - return resp.Body, nil -} - -func (registry *Registry) UploadLayer(repository string, digest digest.Digest, content io.Reader) error { - uploadUrl, err := registry.initiateUpload(repository) - if err != nil { - return err - } - q := uploadUrl.Query() - q.Set("digest", digest.String()) - uploadUrl.RawQuery = q.Encode() - - registry.Logf("registry.layer.upload url=%s repository=%s digest=%s", uploadUrl, repository, digest) - - upload, err := http.NewRequest("PUT", uploadUrl.String(), content) - if err != nil { - return err - } - upload.Header.Set("Content-Type", "application/octet-stream") - - _, err = registry.Client.Do(upload) - return err -} - -func (registry *Registry) HasLayer(repository string, digest digest.Digest) (bool, error) { - checkUrl := registry.url("/v2/%s/blobs/%s", repository, digest) - registry.Logf("registry.layer.check url=%s repository=%s digest=%s", checkUrl, repository, digest) - - resp, err := registry.Client.Head(checkUrl) - if resp != nil { - defer resp.Body.Close() - } - if err == nil { - return resp.StatusCode == http.StatusOK, nil - } - - urlErr, ok := err.(*url.Error) - if !ok { - return false, err - } - httpErr, ok := urlErr.Err.(*HttpStatusError) - if !ok { - return false, err - } - if httpErr.Response.StatusCode == http.StatusNotFound { - return false, nil - } - - return false, err -} - -func (registry *Registry) LayerMetadata(repository string, digest digest.Digest) (distribution.Descriptor, error) { - checkUrl := registry.url("/v2/%s/blobs/%s", repository, digest) - registry.Logf("registry.layer.check url=%s repository=%s digest=%s", checkUrl, repository, digest) - - resp, err := registry.Client.Head(checkUrl) - if resp != nil { - defer resp.Body.Close() - } - if err != nil { - return distribution.Descriptor{}, err - } - - return distribution.Descriptor{ - Digest: digest, - Size: resp.ContentLength, - }, nil -} - -func (registry *Registry) initiateUpload(repository string) (*url.URL, error) { - initiateUrl := registry.url("/v2/%s/blobs/uploads/", repository) - registry.Logf("registry.layer.initiate-upload url=%s repository=%s", initiateUrl, repository) - - resp, err := registry.Client.Post(initiateUrl, "application/octet-stream", nil) - if resp != nil { - defer resp.Body.Close() - } - if err != nil { - return nil, err - } - - location := resp.Header.Get("Location") - locationUrl, err := url.Parse(location) - if err != nil { - return nil, err - } - return locationUrl, nil -} diff --git a/registry/manifest.go b/registry/manifest.go index 7b11cf81..5bfabe43 100644 --- a/registry/manifest.go +++ b/registry/manifest.go @@ -8,7 +8,7 @@ import ( manifestV1 "github.com/docker/distribution/manifest/schema1" manifestV2 "github.com/docker/distribution/manifest/schema2" - "github.com/opencontainers/go-digest" + digest "github.com/opencontainers/go-digest" ) func (registry *Registry) Manifest(repository, reference string) (*manifestV1.SignedManifest, error) { @@ -70,11 +70,12 @@ func (registry *Registry) ManifestV2(repository, reference string) (*manifestV2. return deserialized, nil } +// ManifestDigest - get manifest digest func (registry *Registry) ManifestDigest(repository, reference string) (digest.Digest, error) { url := registry.url("/v2/%s/manifests/%s", repository, reference) registry.Logf("registry.manifest.head url=%s repository=%s reference=%s", url, repository, reference) - req, err := http.NewRequest("HEAD", url, nil) + req, err := http.NewRequest("GET", url, nil) if err != nil { return "", err } diff --git a/registry/tags.go b/registry/tags.go index 973219e3..aab4ed5c 100644 --- a/registry/tags.go +++ b/registry/tags.go @@ -4,6 +4,7 @@ type tagsResponse struct { Tags []string `json:"tags"` } +// Tags returns repository tags, ie: latest, 1.0.0, 2.0.0, etc.. func (registry *Registry) Tags(repository string) (tags []string, err error) { url := registry.url("/v2/%s/tags/list", repository)