Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ient

# Conflicts:
#	registry/manifest.go
  • Loading branch information
yj committed Dec 9, 2016
2 parents f049c0a + 10ddce7 commit c686f5c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ manifest, err := hub.ManifestV2("heroku/cedar", "14")
The returned manifest will be a `manifest.SignedManifest` pointer. For details,
see the `github.com/docker/distribution/manifest` library.

## Retrieving Manifest Digest

A manifest is identified by a digest.

```go
digest, err := hub.ManifestDigest("heroku/cedar", "14")
```

The returned digest will be a `digest.Digest`. See `github.com/docker/distribution/digest`.

## Deleting Manifest

To delete a manifest

```go
digest, err := hub.ManifestDigest("heroku/cedar", "14")
err = hub.DeleteManifest("heroku/cedar", digest)
```

Please notice that, as specified by the Registry v2 API, this call doesn't actually remove the fs layers used by the image.

## Downloading Layers

Each manifest contains a list of layers, filesystem images that Docker will
Expand Down
33 changes: 33 additions & 0 deletions registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"net/http"

"github.com/docker/distribution/digest"
manifestV1 "github.com/docker/distribution/manifest/schema1"
manifestV2 "github.com/docker/distribution/manifest/schema2"
)
Expand Down Expand Up @@ -68,6 +69,38 @@ func (registry *Registry) ManifestV2(repository, reference string) (*manifestV2.
return deserialized, nil
}

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)

resp, err := registry.Client.Head(url)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return "", err
}
return digest.ParseDigest(resp.Header.Get("Docker-Content-Digest"))
}

func (registry *Registry) DeleteManifest(repository string, digest digest.Digest) error {
url := registry.url("/v2/%s/manifests/%s", repository, digest)
registry.Logf("registry.manifest.delete url=%s repository=%s reference=%s", url, repository, digest)

req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
resp, err := registry.Client.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
return err
}
return nil
}

func (registry *Registry) PutManifest(repository, reference string, signedManifest *manifestV1.SignedManifest) error {
url := registry.url("/v2/%s/manifests/%s", repository, reference)
registry.Logf("registry.manifest.put url=%s repository=%s reference=%s", url, repository, reference)
Expand Down

0 comments on commit c686f5c

Please sign in to comment.