2015-11-18 17:18:44 -05:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package distribution // import "github.com/docker/docker/distribution"
|
2015-11-18 17:18:44 -05:00
|
|
|
|
|
|
|
import (
|
2018-04-19 20:00:56 -04:00
|
|
|
"context"
|
2017-10-03 19:58:07 -04:00
|
|
|
|
2018-06-26 17:49:33 -04:00
|
|
|
"github.com/containerd/containerd/platforms"
|
2016-05-25 22:11:51 -04:00
|
|
|
"github.com/docker/distribution"
|
2017-10-03 19:58:07 -04:00
|
|
|
"github.com/docker/distribution/manifest/manifestlist"
|
2018-06-26 17:49:33 -04:00
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
2017-10-03 19:58:07 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2015-11-18 17:18:44 -05:00
|
|
|
)
|
|
|
|
|
2016-05-25 22:11:51 -04:00
|
|
|
func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
|
|
|
|
blobs := ld.repo.Blobs(ctx)
|
|
|
|
return blobs.Open(ctx, ld.digest)
|
|
|
|
}
|
2017-10-03 19:58:07 -04:00
|
|
|
|
2018-06-26 17:49:33 -04:00
|
|
|
func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
|
2018-06-27 18:21:16 -04:00
|
|
|
p = platforms.Normalize(withDefault(p))
|
|
|
|
m := platforms.NewMatcher(p)
|
2017-10-03 19:58:07 -04:00
|
|
|
var matches []manifestlist.ManifestDescriptor
|
2018-06-26 17:49:33 -04:00
|
|
|
for _, desc := range manifests {
|
2018-06-27 18:21:16 -04:00
|
|
|
if m.Match(toOCIPlatform(desc.Platform)) {
|
2018-06-26 17:49:33 -04:00
|
|
|
matches = append(matches, desc)
|
|
|
|
logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 19:58:07 -04:00
|
|
|
|
2018-06-26 17:49:33 -04:00
|
|
|
// deprecated: backwards compatibility with older versions that didn't compare variant
|
|
|
|
if len(matches) == 0 && p.Architecture == "arm" {
|
2018-06-27 18:21:16 -04:00
|
|
|
p = platforms.Normalize(p)
|
2018-06-26 17:49:33 -04:00
|
|
|
for _, desc := range manifests {
|
|
|
|
if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
|
|
|
|
matches = append(matches, desc)
|
|
|
|
logrus.Debugf("found deprecated partial match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
|
|
|
|
}
|
2017-10-03 19:58:07 -04:00
|
|
|
}
|
|
|
|
}
|
2018-06-26 17:49:33 -04:00
|
|
|
|
2017-10-03 19:58:07 -04:00
|
|
|
return matches
|
|
|
|
}
|
2018-02-15 16:17:27 -05:00
|
|
|
|
|
|
|
// checkImageCompatibility is a Windows-specific function. No-op on Linux
|
|
|
|
func checkImageCompatibility(imageOS, imageOSVersion string) error {
|
|
|
|
return nil
|
|
|
|
}
|
2018-06-26 17:49:33 -04:00
|
|
|
|
|
|
|
func withDefault(p specs.Platform) specs.Platform {
|
|
|
|
def := platforms.DefaultSpec()
|
|
|
|
if p.OS == "" {
|
|
|
|
p.OS = def.OS
|
|
|
|
}
|
|
|
|
if p.Architecture == "" {
|
|
|
|
p.Architecture = def.Architecture
|
|
|
|
p.Variant = def.Variant
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|