2015-11-18 17:18:44 -05:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package distribution
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2016-05-25 22:11:51 -04:00
|
|
|
"net/http"
|
|
|
|
"os"
|
2015-11-18 17:18:44 -05:00
|
|
|
|
2016-05-25 22:11:51 -04:00
|
|
|
"github.com/docker/distribution"
|
|
|
|
"github.com/docker/distribution/context"
|
2015-11-18 17:18:44 -05:00
|
|
|
"github.com/docker/distribution/manifest/schema1"
|
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
|
|
|
"github.com/docker/docker/image"
|
|
|
|
)
|
|
|
|
|
|
|
|
func detectBaseLayer(is image.Store, m *schema1.Manifest, rootFS *image.RootFS) error {
|
|
|
|
v1img := &image.V1Image{}
|
|
|
|
if err := json.Unmarshal([]byte(m.History[len(m.History)-1].V1Compatibility), v1img); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if v1img.Parent == "" {
|
|
|
|
return fmt.Errorf("Last layer %q does not have a base layer reference", v1img.ID)
|
|
|
|
}
|
|
|
|
// There must be an image that already references the baselayer.
|
|
|
|
for _, img := range is.Map() {
|
2016-03-28 21:14:05 -04:00
|
|
|
if img.RootFS.Type == image.TypeLayersWithBase && img.RootFS.BaseLayerID() == v1img.Parent {
|
2015-11-18 17:18:44 -05:00
|
|
|
rootFS.BaseLayer = img.RootFS.BaseLayer
|
2016-03-28 21:14:05 -04:00
|
|
|
rootFS.Type = image.TypeLayersWithBase
|
2015-11-18 17:18:44 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Errorf("Invalid base layer %q", v1img.Parent)
|
|
|
|
}
|
2016-05-25 22:11:51 -04: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) {
|
2016-06-06 20:49:34 -04:00
|
|
|
if len(ld.src.URLs) == 0 {
|
2016-05-25 22:11:51 -04:00
|
|
|
blobs := ld.repo.Blobs(ctx)
|
|
|
|
return blobs.Open(ctx, ld.digest)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
rsc distribution.ReadSeekCloser
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-05-25 22:11:51 -04:00
|
|
|
rsc = transport.NewHTTPReadSeeker(http.DefaultClient, url, nil)
|
|
|
|
_, err = rsc.Seek(0, os.SEEK_SET)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
rsc.Close()
|
|
|
|
rsc = nil
|
|
|
|
}
|
|
|
|
return rsc, err
|
|
|
|
}
|