From e46484545db76296d4ae166dda9293338de2d2cd Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 7 Sep 2024 12:31:55 +0200 Subject: [PATCH] fix: do not try to pull images tagged `cibw_local` --- cibuildwheel/oci_container.py | 11 +++++++---- unit_test/oci_container_test.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cibuildwheel/oci_container.py b/cibuildwheel/oci_container.py index 526db0d39..d8e5ef600 100644 --- a/cibuildwheel/oci_container.py +++ b/cibuildwheel/oci_container.py @@ -33,9 +33,10 @@ ContainerEngineName = Literal["docker", "podman"] +# Order of the enum matters for tests. 386 shall appear before amd64. class OCIPlatform(Enum): - AMD64 = "linux/amd64" i386 = "linux/386" + AMD64 = "linux/amd64" ARM64 = "linux/arm64" PPC64LE = "linux/ppc64le" S390X = "linux/s390x" @@ -182,9 +183,11 @@ def __enter__(self) -> Self: if detect_ci_provider() == CIProvider.travis_ci and platform.machine() == "ppc64le": network_args = ["--network=host"] - # we need '--pull=always' otherwise some images with the wrong platform get re-used (e.g. 386 image for amd64) - # c.f. https://github.com/moby/moby/issues/48197#issuecomment-2282802313 - platform_args = [f"--platform={self.oci_platform.value}", "--pull=always"] + platform_args = [f"--platform={self.oci_platform.value}"] + if not self.image.endswith(":cibw_local"): + # we need '--pull=always' otherwise some images with the wrong platform get re-used (e.g. 386 image for amd64) + # c.f. https://github.com/moby/moby/issues/48197#issuecomment-2282802313 + platform_args.append("--pull=always") simulate_32_bit = False if self.oci_platform == OCIPlatform.i386: diff --git a/unit_test/oci_container_test.py b/unit_test/oci_container_test.py index 2169eefc5..850fe2e97 100644 --- a/unit_test/oci_container_test.py +++ b/unit_test/oci_container_test.py @@ -513,6 +513,15 @@ 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:cibw_local" + 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 + ): + pass + + @pytest.mark.parametrize("platform", list(OCIPlatform)) def test_multiarch_image(container_engine, platform): if ( @@ -533,3 +542,12 @@ def test_multiarch_image(container_engine, platform): OCIPlatform.S390X: "s390x", } assert output_map[platform] == output.strip() + output = container.call(["dpkg", "--print-architecture"], capture_output=True) + output_map = { + OCIPlatform.i386: "i386", + OCIPlatform.AMD64: "amd64", + OCIPlatform.ARM64: "arm64", + OCIPlatform.PPC64LE: "ppc64el", + OCIPlatform.S390X: "s390x", + } + assert output_map[platform] == output.strip()