38
38
class OCIPlatform (Enum ):
39
39
i386 = "linux/386"
40
40
AMD64 = "linux/amd64"
41
+ ARMV7 = "linux/arm/v7"
41
42
ARM64 = "linux/arm64"
42
43
PPC64LE = "linux/ppc64le"
43
44
S390X = "linux/s390x"
@@ -208,7 +209,11 @@ def _get_platform_args(self, *, oci_platform: OCIPlatform | None = None) -> tupl
208
209
"inspect" ,
209
210
self .image ,
210
211
"--format" ,
211
- "{{.Os}}/{{.Architecture}}" ,
212
+ (
213
+ "{{.Os}}/{{.Architecture}}/{{.Variant}}"
214
+ if len (oci_platform .value .split ("/" )) == 3
215
+ else "{{.Os}}/{{.Architecture}}"
216
+ ),
212
217
capture_stdout = True ,
213
218
).strip ()
214
219
if image_platform == oci_platform .value :
@@ -235,7 +240,7 @@ def __enter__(self) -> Self:
235
240
platform_args = self ._get_platform_args ()
236
241
237
242
simulate_32_bit = False
238
- if self .oci_platform == OCIPlatform .i386 :
243
+ if self .oci_platform in { OCIPlatform .i386 , OCIPlatform . ARMV7 } :
239
244
# If the architecture running the image is already the right one
240
245
# or the image entrypoint takes care of enforcing this, then we don't need to
241
246
# simulate this
@@ -246,13 +251,14 @@ def __enter__(self) -> Self:
246
251
* run_cmd , * platform_args , self .image , * ctr_cmd , capture_stdout = True
247
252
).strip ()
248
253
except subprocess .CalledProcessError :
249
- # The image might have been built with amd64 architecture
250
- # Let's try that
251
- platform_args = self ._get_platform_args (oci_platform = OCIPlatform .AMD64 )
252
- container_machine = call (
253
- * run_cmd , * platform_args , self .image , * ctr_cmd , capture_stdout = True
254
- ).strip ()
255
- simulate_32_bit = container_machine != "i686"
254
+ if self .oci_platform == OCIPlatform .i386 :
255
+ # The image might have been built with amd64 architecture
256
+ # Let's try that
257
+ platform_args = self ._get_platform_args (oci_platform = OCIPlatform .AMD64 )
258
+ container_machine = call (
259
+ * run_cmd , * platform_args , self .image , * ctr_cmd , capture_stdout = True
260
+ ).strip ()
261
+ simulate_32_bit = container_machine not in {"i686" , "armv7l" , "armv8l" }
256
262
257
263
shell_args = ["linux32" , "/bin/bash" ] if simulate_32_bit else ["/bin/bash" ]
258
264
0 commit comments