2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2015-11-18 22:18:44 +00:00
|
|
|
|
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"
|
2022-03-28 02:46:45 +00:00
|
|
|
"sort"
|
2017-10-03 23:58:07 +00:00
|
|
|
|
2018-06-26 21:49:33 +00:00
|
|
|
"github.com/containerd/containerd/platforms"
|
2023-09-13 15:41:45 +00:00
|
|
|
"github.com/containerd/log"
|
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"
|
2023-05-08 09:57:52 +00:00
|
|
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
2015-11-18 22:18:44 +00:00
|
|
|
)
|
|
|
|
|
2022-02-27 19:57:07 +00:00
|
|
|
func (ld *layerDescriptor) open(ctx context.Context) (distribution.ReadSeekCloser, error) {
|
2016-05-26 02:11:51 +00:00
|
|
|
blobs := ld.repo.Blobs(ctx)
|
|
|
|
return blobs.Open(ctx, ld.digest)
|
|
|
|
}
|
2017-10-03 23:58:07 +00:00
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func filterManifests(manifests []manifestlist.ManifestDescriptor, p ocispec.Platform) []manifestlist.ManifestDescriptor {
|
2018-06-27 22:21:16 +00:00
|
|
|
p = platforms.Normalize(withDefault(p))
|
2022-03-28 02:46:45 +00:00
|
|
|
m := platforms.Only(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 {
|
2022-06-02 01:26:35 +00:00
|
|
|
descP := toOCIPlatform(desc.Platform)
|
|
|
|
if descP == nil || m.Match(*descP) {
|
2018-06-26 21:49:33 +00:00
|
|
|
matches = append(matches, desc)
|
2022-06-02 01:26:35 +00:00
|
|
|
if descP != nil {
|
2023-06-23 00:33:17 +00:00
|
|
|
log.G(context.TODO()).Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
|
2022-06-02 01:26:35 +00:00
|
|
|
}
|
2018-06-26 21:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-03 23:58:07 +00:00
|
|
|
|
2022-03-28 02:46:45 +00:00
|
|
|
sort.SliceStable(matches, func(i, j int) bool {
|
2022-06-02 01:26:35 +00: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-28 02:46:45 +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
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func withDefault(p ocispec.Platform) ocispec.Platform {
|
2022-03-28 03:21:22 +00:00
|
|
|
def := maximumSpec()
|
2018-06-26 21:49:33 +00:00
|
|
|
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
|
|
|
|
2023-05-08 09:57:52 +00:00
|
|
|
func formatPlatform(platform ocispec.Platform) string {
|
2019-01-15 17:24:15 +00:00
|
|
|
if platform.OS == "" {
|
|
|
|
platform = platforms.DefaultSpec()
|
|
|
|
}
|
|
|
|
return platforms.Format(platform)
|
|
|
|
}
|