3838class OCIPlatform (Enum ):
3939 i386 = "linux/386"
4040 AMD64 = "linux/amd64"
41+ ARMV7 = "linux/arm/v7"
4142 ARM64 = "linux/arm64"
4243 PPC64LE = "linux/ppc64le"
4344 S390X = "linux/s390x"
@@ -208,7 +209,11 @@ def _get_platform_args(self, *, oci_platform: OCIPlatform | None = None) -> tupl
208209 "inspect" ,
209210 self .image ,
210211 "--format" ,
211- "{{.Os}}/{{.Architecture}}" ,
212+ (
213+ "{{.Os}}/{{.Architecture}}/{{.Variant}}"
214+ if len (oci_platform .value .split ("/" )) == 3
215+ else "{{.Os}}/{{.Architecture}}"
216+ ),
212217 capture_stdout = True ,
213218 ).strip ()
214219 if image_platform == oci_platform .value :
@@ -235,7 +240,7 @@ def __enter__(self) -> Self:
235240 platform_args = self ._get_platform_args ()
236241
237242 simulate_32_bit = False
238- if self .oci_platform == OCIPlatform .i386 :
243+ if self .oci_platform in { OCIPlatform .i386 , OCIPlatform . ARMV7 } :
239244 # If the architecture running the image is already the right one
240245 # or the image entrypoint takes care of enforcing this, then we don't need to
241246 # simulate this
@@ -246,13 +251,14 @@ def __enter__(self) -> Self:
246251 * run_cmd , * platform_args , self .image , * ctr_cmd , capture_stdout = True
247252 ).strip ()
248253 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" }
256262
257263 shell_args = ["linux32" , "/bin/bash" ] if simulate_32_bit else ["/bin/bash" ]
258264
0 commit comments