2015-11-18 22:18:44 +00:00
|
|
|
// +build !windows
|
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package distribution // import "github.com/docker/docker/distribution"
|
2015-11-18 22:18:44 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-20 00:00:56 +00:00
|
|
|
"context"
|
2017-10-03 23:58:07 +00:00
|
|
|
|
2018-06-26 21:49:33 +00:00
|
|
|
"github.com/containerd/containerd/platforms"
|
2016-05-26 02:11:51 +00:00
|
|
|
"github.com/docker/distribution"
|
2017-10-03 23:58:07 +00:00
|
|
|
"github.com/docker/distribution/manifest/manifestlist"
|
2018-06-26 21:49:33 +00:00
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
2017-10-03 23:58:07 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2015-11-18 22:18:44 +00:00
|
|
|
)
|
|
|
|
|
2016-05-26 02:11:51 +00: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 23:58:07 +00:00
|
|
|
|
2018-06-26 21:49:33 +00:00
|
|
|
func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
|
2018-06-27 22:21:16 +00:00
|
|
|
p = platforms.Normalize(withDefault(p))
|
|
|
|
m := platforms.NewMatcher(p)
|
2017-10-03 23:58:07 +00:00
|
|
|
var matches []manifestlist.ManifestDescriptor
|
2018-06-26 21:49:33 +00:00
|
|
|
for _, desc := range manifests {
|
2018-06-27 22:21:16 +00:00
|
|
|
if m.Match(toOCIPlatform(desc.Platform)) {
|
2018-06-26 21:49:33 +00: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 23:58:07 +00:00
|
|
|
|
2018-06-26 21:49:33 +00:00
|
|
|
// deprecated: backwards compatibility with older versions that didn't compare variant
|
|
|
|
if len(matches) == 0 && p.Architecture == "arm" {
|
2018-06-27 22:21:16 +00:00
|
|
|
p = platforms.Normalize(p)
|
2018-06-26 21:49:33 +00: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 23:58:07 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-26 21:49:33 +00:00
|
|
|
|
2017-10-03 23:58:07 +00:00
|
|
|
return matches
|
|
|
|
}
|
2018-02-15 21:17:27 +00:00
|
|
|
|
|
|
|
// checkImageCompatibility is a Windows-specific function. No-op on Linux
|
|
|
|
func checkImageCompatibility(imageOS, imageOSVersion string) error {
|
|
|
|
return nil
|
|
|
|
}
|
2018-06-26 21:49:33 +00: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
|
|
|
|
}
|
2019-01-15 17:24:15 +00:00
|
|
|
|
|
|
|
func formatPlatform(platform specs.Platform) string {
|
|
|
|
if platform.OS == "" {
|
|
|
|
platform = platforms.DefaultSpec()
|
|
|
|
}
|
|
|
|
return platforms.Format(platform)
|
|
|
|
}
|