From 500f015e7259f1524ed93187fa44115d2c79ce03 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 29 Sep 2024 11:35:24 +0200 Subject: [PATCH] fix: local armv7l images --- cibuildwheel/oci_container.py | 5 ++++- unit_test/oci_container_test.py | 30 +++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index 53da2ad19..a036cf34f 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -183,13 +183,16 @@ def _get_platform_args(self, *, oci_platform: OCIPlatform | None = None) -> tupl # c.f. https://github.com/moby/moby/issues/48197#issuecomment-2282802313 pull = "always" try: + components = len(oci_platform.value.split("/")) + assert components in {2, 3} + variant = "/{{.Variant}}" if components == 3 else "" image_platform = call( self.engine.name, "image", "inspect", self.image, "--format", - "{{.Os}}/{{.Architecture}}", + "{{.Os}}/{{.Architecture}}" + variant, capture_stdout=True, ).strip() if image_platform == oci_platform.value: diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index db91f7b00..80146c8fe 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -527,16 +527,32 @@ def test_disable_host_mount(tmp_path: Path, container_engine, config, should_hav container.call(["cat", host_mount_path], capture_output=True) -def test_local_image(container_engine): - local_image = f"cibw_test_{container_engine.name}_local:latest" +@pytest.mark.parametrize("platform", list(OCIPlatform)) +def test_local_image(container_engine, platform, tmp_path: Path): + if ( + detect_ci_provider() in {CIProvider.travis_ci} + and pm in {"s390x", "ppc64le"} + and platform != DEFAULT_OCI_PLATFORM + ): + pytest.skip("Skipping test because docker on this platform does not support QEMU") + if container_engine.name == "podman" and platform == OCIPlatform.ARMV7: + # both GHA & local macOS arm64 podman desktop are failing + pytest.xfail("podman fails with armv7l images") + + remote_image = "debian:12-slim" + local_image = f"cibw_{container_engine.name}_{platform.value.replace("/", "_")}_local:latest" + dockerfile = tmp_path / "Dockerfile" + dockerfile.write_text(f"FROM {remote_image}") subprocess.run( - [container_engine.name, "pull", f"--platform={DEFAULT_OCI_PLATFORM.value}", DEFAULT_IMAGE], + [container_engine.name, "pull", f"--platform={platform.value}", remote_image], check=True, ) - subprocess.run([container_engine.name, "image", "tag", DEFAULT_IMAGE, local_image], check=True) - with OCIContainer( - engine=container_engine, image=local_image, oci_platform=DEFAULT_OCI_PLATFORM - ): + subprocess.run( + [container_engine.name, "build", f"--platform={platform.value}", "-t", local_image, "."], + check=True, + cwd=tmp_path, + ) + with OCIContainer(engine=container_engine, image=local_image, oci_platform=platform): pass