2021-08-23 09:14:53 -04:00
|
|
|
//go:build !windows
|
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"
|
2022-03-27 22:46:45 -04:00
|
|
|
"sort"
|
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
|
|
|
)
|
|
|
|
|
2022-02-27 14:57:07 -05:00
|
|
|
func (ld *layerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
|
2016-05-25 22:11:51 -04:00
|
|
|
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))
|
2022-03-27 22:46:45 -04:00
|
|
|
m := platforms.Only(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 {
|
2022-06-01 21:26:35 -04:00
|
|
|
descP := toOCIPlatform(desc.Platform)
|
|
|
|
if descP == nil || m.Match(*descP) {
|
2018-06-26 17:49:33 -04:00
|
|
|
matches = append(matches, desc)
|
2022-06-01 21:26:35 -04:00
|
|
|
if descP != nil {
|
|
|
|
logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
|
|
|
|
}
|
2018-06-26 17:49:33 -04:00
|
|
|
}
|
|
|
|
}
|
2017-10-03 19:58:07 -04:00
|
|
|
|
2022-03-27 22:46:45 -04:00
|
|
|
sort.SliceStable(matches, func(i, j int) bool {
|
2022-06-01 21:26:35 -04:00
|
|
|
p1 := toOCIPlatform(matches[i].Platform)
|
|
|
|
if p1 == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
p2 := toOCIPlatform(matches[j].Platform)
|
|
|
|
if p2 == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return m.Less(*p1, *p2)
|
2022-03-27 22:46:45 -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 {
|
2022-03-27 23:21:22 -04:00
|
|
|
def := maximumSpec()
|
2018-06-26 17:49:33 -04:00
|
|
|
if p.OS == "" {
|
|
|
|
p.OS = def.OS
|
|
|
|
}
|
|
|
|
if p.Architecture == "" {
|
|
|
|
p.Architecture = def.Architecture
|
|
|
|
p.Variant = def.Variant
|
|
|
|
}
|
|
|
|
return p
|
|
|
|
}
|
2019-01-15 12:24:15 -05:00
|
|
|
|
|
|
|
func formatPlatform(platform specs.Platform) string {
|
|
|
|
if platform.OS == "" {
|
|
|
|
platform = platforms.DefaultSpec()
|
|
|
|
}
|
|
|
|
return platforms.Format(platform)
|
|
|
|
}
|