2015-11-18 17:18:44 -05:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package distribution
|
|
|
|
|
|
|
|
import (
|
2016-05-25 22:11:51 -04:00
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-11-18 17:18:44 -05:00
|
|
|
|
2016-09-26 11:47:38 -04:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-05-25 22:11:51 -04:00
|
|
|
"github.com/docker/distribution"
|
|
|
|
"github.com/docker/distribution/context"
|
2016-06-06 20:49:34 -04:00
|
|
|
"github.com/docker/distribution/manifest/schema2"
|
2016-05-25 22:11:51 -04:00
|
|
|
"github.com/docker/distribution/registry/client/transport"
|
2015-11-18 17:18:44 -05:00
|
|
|
)
|
|
|
|
|
2016-06-06 20:49:34 -04:00
|
|
|
var _ distribution.Describable = &v2LayerDescriptor{}
|
2016-05-25 22:11:51 -04:00
|
|
|
|
2016-06-06 20:49:34 -04:00
|
|
|
func (ld *v2LayerDescriptor) Descriptor() distribution.Descriptor {
|
|
|
|
if ld.src.MediaType == schema2.MediaTypeForeignLayer && len(ld.src.URLs) > 0 {
|
|
|
|
return ld.src
|
|
|
|
}
|
|
|
|
return distribution.Descriptor{}
|
2016-05-25 22:11:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
|
2017-05-09 17:00:31 -04:00
|
|
|
blobs := ld.repo.Blobs(ctx)
|
|
|
|
rsc, err := blobs.Open(ctx, ld.digest)
|
|
|
|
|
2016-06-06 20:49:34 -04:00
|
|
|
if len(ld.src.URLs) == 0 {
|
2017-05-09 17:00:31 -04:00
|
|
|
return rsc, err
|
2016-05-25 22:11:51 -04:00
|
|
|
}
|
|
|
|
|
2017-05-09 17:00:31 -04:00
|
|
|
// We're done if the registry has this blob.
|
|
|
|
if err == nil {
|
|
|
|
// Seek does an HTTP GET. If it succeeds, the blob really is accessible.
|
|
|
|
if _, err = rsc.Seek(0, os.SEEK_SET); err == nil {
|
|
|
|
return rsc, nil
|
|
|
|
}
|
|
|
|
rsc.Close()
|
|
|
|
}
|
2016-05-25 22:11:51 -04:00
|
|
|
|
|
|
|
// Find the first URL that results in a 200 result code.
|
2016-06-06 20:49:34 -04:00
|
|
|
for _, url := range ld.src.URLs {
|
2016-09-26 11:47:38 -04:00
|
|
|
logrus.Debugf("Pulling %v from foreign URL %v", ld.digest, url)
|
2016-05-25 22:11:51 -04:00
|
|
|
rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
|
2017-05-09 17:00:31 -04:00
|
|
|
|
|
|
|
// Seek does an HTTP GET. If it succeeds, the blob really is accessible.
|
2016-05-25 22:11:51 -04:00
|
|
|
_, err = rsc.Seek(0, os.SEEK_SET)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
2016-09-26 11:47:38 -04:00
|
|
|
logrus.Debugf("Download for %v failed: %v", ld.digest, err)
|
2016-05-25 22:11:51 -04:00
|
|
|
rsc.Close()
|
|
|
|
rsc = nil
|
|
|
|
}
|
|
|
|
return rsc, err
|
|
|
|
}
|