diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3cabb68..a21f70b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,80 +26,6 @@ jobs: pip install --upgrade poetry nox nox-poetry nox -s format -- --check - generate_requirements: - name: Generate requirements.txt for Python 3.6 CI - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - uses: actions/cache@v4 - with: - path: ~/.cache/pypoetry/virtualenvs - key: poetry-${{ hashFiles('poetry.lock') }} - - - run: | - pipx install poetry - poetry export --with=dev --without-hashes > requirements.txt - - - uses: actions/upload-artifact@v4 - with: - name: requirements - path: requirements.txt - if-no-files-found: error - - ci_36: - name: Run the integration tests for Python 3.6 - runs-on: ubuntu-20.04 - needs: generate_requirements - - strategy: - fail-fast: false - matrix: - container_runtime: ["podman", "docker"] - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: 3.6 - - - uses: actions/download-artifact@v4 - with: - name: requirements - path: . - - - run: pip install -r test-requirements.txt - - - run: | - export CUR_USER="$(whoami)" - sudo loginctl enable-linger ${CUR_USER} - - - run: | - mkdir ./tmp/ - chmod 1777 ./tmp - export TMPDIR="$(pwd)/tmp" - # duplication of noxfile.py because we can't use that one with python 3.6 :-/ - coverage run -m pytest -vv tests -p pytest_container -x -n auto --reruns 3 --pytest-container-log-level DEBUG - coverage run -m pytest -vv tests -p pytest_container -x --reruns 3 --pytest-container-log-level DEBUG - coverage combine - coverage report -m - coverage xml - - - name: verify that no stray containers are left - run: | - [[ $(${{ matrix.container_runtime }} ps -aq|wc -l) = "0" ]] - - - name: verify that no stray volumes are left - run: | - [[ $(${{ matrix.container_runtime }} volume ls -q|wc -l) = "0" ]] - - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - fail_ci_if_error: true ci: name: Run the integration tests @@ -107,17 +33,11 @@ jobs: strategy: fail-fast: false matrix: - python_version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] + python_version: ["3.9", "3.10", "3.11", "3.12"] container_runtime: ["podman", "docker"] update_runtime: [ true, false ] exclude: - - container_runtime: "docker" - python_version: "3.7" - update_runtime: true - - container_runtime: "docker" - python_version: "3.8" - update_runtime: true - container_runtime: "docker" python_version: "3.9" update_runtime: true @@ -217,10 +137,7 @@ jobs: fail-fast: false matrix: os_version: ["ubuntu-latest"] - python_version: ["3.7", "3.8", "3.9", "3.10", "3.11"] - include: - - os_version: "ubuntu-20.04" - python_version: "3.6" + python_version: ["3.9", "3.10", "3.11"] steps: - uses: actions/setup-python@v5 diff --git a/pytest_container/container.py b/pytest_container/container.py index b838cc3..fce735a 100644 --- a/pytest_container/container.py +++ b/pytest_container/container.py @@ -490,6 +490,9 @@ class ContainerBase: default_factory=list ) + #: optional target platform for the container image + platform: Optional[str] = None + _is_local: bool = False def __post_init__(self) -> None: @@ -654,7 +657,14 @@ def pull_container(self) -> None: container runtime""" runtime = get_selected_runtime() _logger.debug("Pulling %s via %s", self.url, runtime.runner_binary) - check_output([runtime.runner_binary, "pull", self.url]) + + # Construct the args passed to the Docker CLI + cmd_args = [runtime.runner_binary, "pull"] + if self.platform is not None: + cmd_args += ["--platform", self.platform] + cmd_args.append(self.url) + + check_output(cmd_args) def prepare_container( self, rootdir: Path, extra_build_args: Optional[List[str]] = None @@ -1067,6 +1077,9 @@ def release_lock() -> None: if self.container_name: extra_run_args.extend(("--name", self.container_name)) + if self.container.platform: + extra_run_args.extend(("--platform", self.container.platform)) + extra_run_args.append(f"--cidfile={self._cidfile}") # We must perform the launches in separate branches, as containers with diff --git a/pytest_container/runtime.py b/pytest_container/runtime.py index 3b7fb7f..24c2062 100644 --- a/pytest_container/runtime.py +++ b/pytest_container/runtime.py @@ -621,15 +621,21 @@ def get_selected_runtime() -> OciRuntimeBase: podman_exists = LOCALHOST.exists("podman") and LOCALHOST.exists("buildah") docker_exists = LOCALHOST.exists("docker") - runtime_choice = getenv("CONTAINER_RUNTIME", "podman").lower() - if runtime_choice not in ("podman", "docker"): + runtime_choice = getenv("CONTAINER_RUNTIME", None) + if runtime_choice is not None and runtime_choice.lower() not in ( + "podman", + "docker", + ): raise ValueError(f"Invalid CONTAINER_RUNTIME {runtime_choice}") - if runtime_choice == "podman" and podman_exists: + runtime_choice = runtime_choice and runtime_choice.lower() or None + if runtime_choice in ("podman", None) and podman_exists: return PodmanRuntime() - if runtime_choice == "docker" and docker_exists: + + if runtime_choice in ("docker", None) and docker_exists: return DockerRuntime() + runtime_choice = runtime_choice or "(podman or docker)" raise ValueError( "Selected runtime " + runtime_choice + " does not exist on the system" ) diff --git a/tests/test_container_build.py b/tests/test_container_build.py index b3997cd..ab6d77b 100644 --- a/tests/test_container_build.py +++ b/tests/test_container_build.py @@ -268,7 +268,7 @@ def test_multistage_build_target( == "foobar" ) - for (distro, target) in ( + for distro, target in ( ("Leap", first_target), ("Alpine", second_target), ): diff --git a/tests/test_launcher.py b/tests/test_launcher.py index cccde0a..afe93ee 100644 --- a/tests/test_launcher.py +++ b/tests/test_launcher.py @@ -94,7 +94,6 @@ def test_launcher_creates_and_cleanes_up_volumes( assert container.volume_mounts for vol in container.volume_mounts: - if isinstance(vol, BindMount): assert vol.host_path and os.path.exists(vol.host_path) elif isinstance(vol, ContainerVolume):