Skip to content

Commit 0787a44

Browse files
authored
fix: enforce minimum version of docker/podman (#1961)
* fix: enforce minimum version of docker/podman This allows to always pass `--platform` to the OCI engine thus fixing issues with multiarch images. * Allow older versions with warnings * Upgrade docker on Travis CI * fix: use `docker cp` instead of `tar` * Enforce docker>=24.0 * move log to include container.copy_into * fix: travis-ci, only update docker on aarch64 * skip test_multiarch_image on s390x / ppc64le * skip flaky test * chore: only install test deps on Travis CI * fix: do not try to pull images tagged `cibw_local` * use "--pull=never" for local images * Use docker image inspect to check if an image needs to be pulled
1 parent fd11286 commit 0787a44

15 files changed

+299
-119
lines changed

.circleci/prepare.sh

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set -o xtrace
44

55
if [ "$(uname -s)" == "Darwin" ]; then
66
sudo softwareupdate --install-rosetta --agree-to-license
7+
else
8+
docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
79
fi
810

911
$PYTHON --version

.cirrus.yml

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ linux_x86_task:
1717
memory: 8G
1818

1919
install_pre_requirements_script:
20+
- docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
2021
- apt install -y python3-venv python-is-python3
2122
<<: *RUN_TESTS
2223

@@ -30,6 +31,7 @@ linux_aarch64_task:
3031
memory: 4G
3132

3233
install_pre_requirements_script:
34+
- docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
3335
- apt install -y python3-venv python-is-python3
3436
<<: *RUN_TESTS
3537

.github/workflows/test.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ jobs:
5959
docker system prune -a -f
6060
df -h
6161
62+
# for oci_container unit tests
63+
- name: Set up QEMU
64+
if: runner.os == 'Linux'
65+
uses: docker/setup-qemu-action@v3
66+
6267
- name: Install dependencies
6368
run: |
6469
uv pip install --system ".[test]"
@@ -157,10 +162,7 @@ jobs:
157162
run: python -m pip install ".[test,uv]"
158163

159164
- name: Set up QEMU
160-
id: qemu
161165
uses: docker/setup-qemu-action@v3
162-
with:
163-
platforms: all
164166

165167
- name: Run the emulation tests
166168
run: pytest --run-emulation ${{ matrix.arch }} test/test_emulation.py

.gitlab-ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ linux:
1515
PYTEST_ADDOPTS: -k "unit_test or test_0_basic" --suppress-no-test-exit-code
1616
script:
1717
- curl -sSL https://get.docker.com/ | sh
18+
- docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
1819
- python -m pip install -e ".[dev]" pytest-custom-exit-code
1920
- python ./bin/run_tests.py
2021

.travis.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ jobs:
2020
group: edge
2121
virt: vm
2222
env: PYTHON=python
23+
# docker is outdated in the arm64-graviton2 vm focal image (19.x)
24+
# we need to upgrade to get >= 24.0
25+
addons:
26+
apt:
27+
sources:
28+
- sourceline: 'deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable'
29+
packages:
30+
- docker-ce docker-ce-cli containerd.io
2331

2432
- name: Linux | ppc64le | Python 3.9
2533
python: 3.9
@@ -48,8 +56,9 @@ jobs:
4856
env: PYTHON=python
4957

5058
install:
59+
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all; fi
5160
- $PYTHON -m pip install -U pip
52-
- $PYTHON -m pip install -e ".[dev]" pytest-custom-exit-code
61+
- $PYTHON -m pip install -e ".[test]" pytest-custom-exit-code
5362

5463
script: |
5564
# travis_wait disable the output while waiting

appveyor.yml

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ init:
1717
if (-not ($BRANCH -eq 'main' -or $BRANCH.ToLower().StartsWith('appveyor-'))) {
1818
$env:PYTEST_ADDOPTS = '-k "unit_test or test_0_basic" --suppress-no-test-exit-code'
1919
}
20+
if ($IsLinux) {
21+
docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
22+
}
2023
2124
install:
2225
- python -m pip install -U pip

azure-pipelines.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
inputs:
1414
versionSpec: '3.8'
1515
- bash: |
16+
docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
1617
python -m pip install -e ".[dev]"
1718
python ./bin/run_tests.py
1819

bin/run_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# unit tests
2929
unit_test_args = [sys.executable, "-m", "pytest", "unit_test"]
3030

31-
if sys.platform.startswith("linux"):
31+
if sys.platform.startswith("linux") and os.environ.get("CIBW_PLATFORM", "linux") == "linux":
3232
# run the docker unit tests only on Linux
3333
unit_test_args += ["--run-docker"]
3434

cibuildwheel/architecture.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
6464
if arch_str == "auto":
6565
result |= Architecture.auto_archs(platform=platform)
6666
elif arch_str == "native":
67-
result.add(Architecture(platform_module.machine()))
67+
native_arch = Architecture.native_arch(platform=platform)
68+
if native_arch:
69+
result.add(native_arch)
6870
elif arch_str == "all":
6971
result |= Architecture.all_archs(platform=platform)
7072
elif arch_str == "auto64":

cibuildwheel/errors.py

+4
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ def __init__(self, wheel_name: str) -> None:
5858
)
5959
super().__init__(message)
6060
self.return_code = 6
61+
62+
63+
class OCIEngineTooOldError(FatalError):
64+
return_code = 7

cibuildwheel/linux.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ._compat.typing import assert_never
1515
from .architecture import Architecture
1616
from .logger import log
17-
from .oci_container import OCIContainer, OCIContainerEngineConfig
17+
from .oci_container import OCIContainer, OCIContainerEngineConfig, OCIPlatform
1818
from .options import BuildOptions, Options
1919
from .typing import PathOrStr
2020
from .util import (
@@ -29,6 +29,14 @@
2929
unwrap,
3030
)
3131

32+
ARCHITECTURE_OCI_PLATFORM_MAP = {
33+
Architecture.x86_64: OCIPlatform.AMD64,
34+
Architecture.i686: OCIPlatform.i386,
35+
Architecture.aarch64: OCIPlatform.ARM64,
36+
Architecture.ppc64le: OCIPlatform.PPC64LE,
37+
Architecture.s390x: OCIPlatform.S390X,
38+
}
39+
3240

3341
@dataclass(frozen=True)
3442
class PythonConfiguration:
@@ -196,6 +204,8 @@ def build_in_container(
196204

197205
dependency_constraint_flags: list[PathOrStr] = []
198206

207+
log.step("Setting up build environment...")
208+
199209
if build_options.dependency_constraints:
200210
constraints_file = build_options.dependency_constraints.get_for_python_version(
201211
config.version
@@ -205,8 +215,6 @@ def build_in_container(
205215
container.copy_into(constraints_file, container_constraints_file)
206216
dependency_constraint_flags = ["-c", container_constraints_file]
207217

208-
log.step("Setting up build environment...")
209-
210218
env = container.get_environment()
211219
env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"
212220
env["PIP_ROOT_USER_ACTION"] = "ignore"
@@ -446,10 +454,11 @@ def build(options: Options, tmp_path: Path) -> None: # noqa: ARG001
446454
log.step(f"Starting container image {build_step.container_image}...")
447455

448456
print(f"info: This container will host the build for {', '.join(ids_to_build)}...")
457+
architecture = Architecture(build_step.platform_tag.split("_", 1)[1])
449458

450459
with OCIContainer(
451460
image=build_step.container_image,
452-
enforce_32_bit=build_step.platform_tag.endswith("i686"),
461+
oci_platform=ARCHITECTURE_OCI_PLATFORM_MAP[architecture],
453462
cwd=container_project_path,
454463
engine=build_step.container_engine,
455464
) as container:

0 commit comments

Comments
 (0)