9 "github.com/Sirupsen/logrus"
10 "github.com/docker/distribution"
11 "github.com/docker/distribution/context"
12 "github.com/docker/distribution/manifest/schema2"
13 "github.com/docker/distribution/registry/client/transport"
16 var _ distribution.Describable = &v2LayerDescriptor{}
18 func (ld *v2LayerDescriptor) Descriptor() distribution.Descriptor {
19 if ld.src.MediaType == schema2.MediaTypeForeignLayer && len(ld.src.URLs) > 0 {
22 return distribution.Descriptor{}
25 func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
26 blobs := ld.repo.Blobs(ctx)
27 rsc, err := blobs.Open(ctx, ld.digest)
29 if len(ld.src.URLs) == 0 {
33 // We're done if the registry has this blob.
35 // Seek does an HTTP GET. If it succeeds, the blob really is accessible.
36 if _, err = rsc.Seek(0, os.SEEK_SET); err == nil {
42 // Find the first URL that results in a 200 result code.
43 for _, url := range ld.src.URLs {
44 logrus.Debugf("Pulling %v from foreign URL %v", ld.digest, url)
45 rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
47 // Seek does an HTTP GET. If it succeeds, the blob really is accessible.
48 _, err = rsc.Seek(0, os.SEEK_SET)
52 logrus.Debugf("Download for %v failed: %v", ld.digest, err)