platforms.go 764 B

1234567891011121314151617181920212223242526
  1. package platforms
  2. import (
  3. cplatforms "github.com/containerd/containerd/platforms"
  4. ocispec "github.com/opencontainers/image-spec/specs-go/v1"
  5. )
  6. type allPlatformsWithPreferenceMatcher struct {
  7. preferred cplatforms.MatchComparer
  8. }
  9. // AllPlatformsWithPreference will return a platform matcher that matches all
  10. // platforms but will order platforms matching the preferred matcher first.
  11. func AllPlatformsWithPreference(preferred cplatforms.MatchComparer) cplatforms.MatchComparer {
  12. return allPlatformsWithPreferenceMatcher{
  13. preferred: preferred,
  14. }
  15. }
  16. func (c allPlatformsWithPreferenceMatcher) Match(_ ocispec.Platform) bool {
  17. return true
  18. }
  19. func (c allPlatformsWithPreferenceMatcher) Less(p1, p2 ocispec.Platform) bool {
  20. return c.preferred.Less(p1, p2)
  21. }