Skip to content

Commit

Permalink
Enable proxying registries to downgrade fetched manifests to Schema 1.
Browse files Browse the repository at this point in the history
Ensure Accept headers are sent with TagService.Get (which hits manifest
endpoints).  Add support for remote Get and Put for the proxied blobstore.

Signed-off-by: Richard Scothern <richard.scothern@gmail.com>
  • Loading branch information
RichardScothern committed Feb 23, 2016
1 parent 16445b6 commit 3693621
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
24 changes: 21 additions & 3 deletions registry/client/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,18 @@ func (t *tags) Get(ctx context.Context, tag string) (distribution.Descriptor, er
if err != nil {
return distribution.Descriptor{}, err
}
var attempts int
resp, err := t.client.Head(u)

req, err := http.NewRequest("HEAD", u, nil)
if err != nil {
return distribution.Descriptor{}, err
}

for _, t := range distribution.ManifestMediaTypes() {
req.Header.Add("Accept", t)
}

var attempts int
resp, err := t.client.Do(req)
check:
if err != nil {
return distribution.Descriptor{}, err
Expand All @@ -269,7 +278,16 @@ check:
case resp.StatusCode >= 200 && resp.StatusCode < 400:
return descriptorFromResponse(resp)
case resp.StatusCode == http.StatusMethodNotAllowed:
resp, err = t.client.Get(u)
req, err = http.NewRequest("GET", u, nil)
if err != nil {
return distribution.Descriptor{}, err
}

for _, t := range distribution.ManifestMediaTypes() {
req.Header.Add("Accept", t)
}

resp, err = t.client.Do(req)
attempts++
if attempts > 1 {
return distribution.Descriptor{}, err
Expand Down
26 changes: 22 additions & 4 deletions registry/proxy/proxyblobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ func (pbs *proxyBlobStore) Stat(ctx context.Context, dgst digest.Digest) (distri
return pbs.remoteStore.Stat(ctx, dgst)
}

func (pbs *proxyBlobStore) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) {
blob, err := pbs.localStore.Get(ctx, dgst)
if err == nil {
return blob, nil
}

if err := pbs.authChallenger.tryEstablishChallenges(ctx); err != nil {
return []byte{}, err
}

blob, err = pbs.remoteStore.Get(ctx, dgst)
if err != nil {
return []byte{}, err
}

_, err = pbs.localStore.Put(ctx, "", blob)
if err != nil {
return []byte{}, err
}
return blob, nil
}

// Unsupported functions
func (pbs *proxyBlobStore) Put(ctx context.Context, mediaType string, p []byte) (distribution.Descriptor, error) {
return distribution.Descriptor{}, distribution.ErrUnsupported
Expand All @@ -195,10 +217,6 @@ func (pbs *proxyBlobStore) Open(ctx context.Context, dgst digest.Digest) (distri
return nil, distribution.ErrUnsupported
}

func (pbs *proxyBlobStore) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) {
return nil, distribution.ErrUnsupported
}

func (pbs *proxyBlobStore) Delete(ctx context.Context, dgst digest.Digest) error {
return distribution.ErrUnsupported
}
34 changes: 34 additions & 0 deletions registry/proxy/proxyblobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,40 @@ func populate(t *testing.T, te *testEnv, blobCount, size, numUnique int) {
te.inRemote = inRemote
te.numUnique = numUnique
}
func TestProxyStoreGet(t *testing.T) {
te := makeTestEnv(t, "foo/bar")

localStats := te.LocalStats()
remoteStats := te.RemoteStats()

populate(t, te, 1, 10, 1)
_, err := te.store.Get(te.ctx, te.inRemote[0].Digest)
if err != nil {
t.Fatal(err)
}

if (*localStats)["get"] != 1 && (*localStats)["put"] != 1 {
t.Errorf("Unexpected local counts")
}

if (*remoteStats)["get"] != 1 {
t.Errorf("Unexpected remote get count")
}

_, err = te.store.Get(te.ctx, te.inRemote[0].Digest)
if err != nil {
t.Fatal(err)
}

if (*localStats)["get"] != 2 && (*localStats)["put"] != 1 {
t.Errorf("Unexpected local counts")
}

if (*remoteStats)["get"] != 1 {
t.Errorf("Unexpected remote get count")
}

}

func TestProxyStoreStat(t *testing.T) {
te := makeTestEnv(t, "foo/bar")
Expand Down

0 comments on commit 3693621

Please sign in to comment.