@@ -125,19 +125,26 @@ var compatibility = map[string][]string{
125125// If some option (arch, os, variant) is not present, a value from current platform is detected.
126126func WantedPlatforms (ctx * types.SystemContext ) ([]imgspecv1.Platform , error ) {
127127 wantedArch := runtime .GOARCH
128+ wantedVariant := ""
128129 if ctx != nil && ctx .ArchitectureChoice != "" {
129130 wantedArch = ctx .ArchitectureChoice
131+ } else {
132+ // Only auto-detect the variant if we are using the default architecture.
133+ // If the user has specified the ArchitectureChoice, don't autodetect, even if
134+ // ctx.ArchitectureChoice == runtime.GOARCH, because we have no idea whether the runtime.GOARCH
135+ // value is relevant to the use case, and if we do autodetect a variant,
136+ // ctx.VariantChoice can't be used to override it back to "".
137+ wantedVariant = getCPUVariant (runtime .GOOS , runtime .GOARCH )
130138 }
139+ if ctx != nil && ctx .VariantChoice != "" {
140+ wantedVariant = ctx .VariantChoice
141+ }
142+
131143 wantedOS := runtime .GOOS
132144 if ctx != nil && ctx .OSChoice != "" {
133145 wantedOS = ctx .OSChoice
134146 }
135147
136- wantedVariant := getCPUVariant (runtime .GOOS , runtime .GOARCH )
137- if ctx != nil && ctx .VariantChoice != "" {
138- wantedVariant = ctx .VariantChoice
139- }
140-
141148 var wantedPlatforms []imgspecv1.Platform
142149 if wantedVariant != "" && compatibility [wantedArch ] != nil {
143150 wantedPlatforms = make ([]imgspecv1.Platform , 0 , len (compatibility [wantedArch ]))
0 commit comments