Skip to content

Commit

Permalink
fix: local armv7l images
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Sep 29, 2024
1 parent d902841 commit 500f015
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
5 changes: 4 additions & 1 deletion cibuildwheel/oci_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 23 additions & 7 deletions unit_test/oci_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 500f015

Please sign in to comment.