Skip to content

Commit

Permalink
fix: do not try to pull images tagged cibw_local
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Sep 7, 2024
1 parent ac8a290 commit e464845
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cibuildwheel/oci_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions unit_test/oci_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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()

0 comments on commit e464845

Please sign in to comment.