Skip to content

Describe available platforms when no match #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion internal/manifest/oci_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"runtime"
"slices"
"strings"

platform "github.com/containers/image/v5/internal/pkg/platform"
compression "github.com/containers/image/v5/pkg/compression/types"
Expand Down Expand Up @@ -229,6 +230,26 @@ func (ic instanceCandidate) isPreferredOver(other *instanceCandidate, preferGzip
panic("internal error: invalid comparison between two candidates") // This should not be reachable because in all calls we make, the two candidates differ at least in manifestPosition.
}

func (index *OCI1IndexPublic) descOciPlatforms() string {
if len(index.Manifests) == 0 {
return "no platforms"
}

var b strings.Builder
for i, d := range index.Manifests {
if i > 0 {
b.WriteString(", ")
}
if d.Platform != nil {
imagePlatform := ociPlatformClone(*d.Platform)
b.WriteString(fmt.Sprintf("arch=%q os=%q variant=%q", imagePlatform.Architecture, imagePlatform.OS, imagePlatform.Variant))
} else {
b.WriteString("any")
}
}
return b.String()
}

// chooseInstance is a private equivalent to ChooseInstanceByCompression,
// shared by ChooseInstance and ChooseInstanceByCompression.
func (index *OCI1IndexPublic) chooseInstance(ctx *types.SystemContext, preferGzip types.OptionalBool) (digest.Digest, error) {
Expand All @@ -254,7 +275,8 @@ func (index *OCI1IndexPublic) chooseInstance(ctx *types.SystemContext, preferGzi
if bestMatch != nil {
return bestMatch.digest, nil
}
return "", fmt.Errorf("no image found in image index for architecture %q, variant %q, OS %q", wantedPlatforms[0].Architecture, wantedPlatforms[0].Variant, wantedPlatforms[0].OS)
return "", fmt.Errorf("no image found in image index for architecture %q, variant %q, OS %q; available platforms: %s", wantedPlatforms[0].Architecture, wantedPlatforms[0].Variant, wantedPlatforms[0].OS,
index.descOciPlatforms())
}

func (index *OCI1Index) ChooseInstanceByCompression(ctx *types.SystemContext, preferGzip types.OptionalBool) (digest.Digest, error) {
Expand Down