From 5054a2ca390c1e9d4a18d19a9da545f6827831b3 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 2 Mar 2024 23:30:57 +0000 Subject: [PATCH] Test docker and nerdctl --- .github/workflows/build.yml | 29 ++++++++++++++++++++++++++++- tests/conftest.py | 8 ++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9305446..87e09a5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,8 @@ jobs: fail-fast: false matrix: python_version: ["3.9"] + container_engine: + - podman repo_type: # Only test a subset of the repo2docker tests since we're testing podman, # not the full repo2docker functionality @@ -33,6 +35,19 @@ jobs: # - r - unit - venv/default + include: + - python_version: "3.11" + container_engine: docker + repo_type: base + - python_version: "3.11" + container_engine: docker + repo_type: venv/default + - python_version: "3.11" + container_engine: nerdctl + repo_type: base + - python_version: "3.11" + container_engine: nerdctl + repo_type: venv/default steps: - name: Checkout repo @@ -45,6 +60,14 @@ jobs: cache: pip cache-dependency-path: dev-requirements.txt + - name: Install nerdctl + if: matrix.container_engine == 'nerdctl' + run: | + NERDCTL_VERSION=1.7.4 + curl -sfL https://github.com/containerd/nerdctl/releases/download/v$NERDCTL_VERSION/nerdctl-full-$NERDCTL_VERSION-linux-amd64.tar.gz | sudo tar -zxvf - -C /usr/local + # https://github.com/containerd/nerdctl/blob/v1.7.4/docs/faq.md#does-nerdctl-have-an-equivalent-of-sudo-usermod--ag-docker-user- + sudo chmod +s /usr/local/bin/nerdctl + - name: Install run: | pip install -r dev-requirements.txt @@ -67,7 +90,11 @@ jobs: done - name: Run tests - run: pytest -v tests/${{ matrix.repo_type }} + run: | + export CONTAINER_ENGINE=${{ matrix.container_engine }} + which $CONTAINER_ENGINE + $CONTAINER_ENGINE version + pytest -v tests/${{ matrix.repo_type }} # https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ publish-pypi: diff --git a/tests/conftest.py b/tests/conftest.py index bc128bb..0bd665d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,6 +19,9 @@ from repo2docker.__main__ import make_r2d +CONTAINER_ENGINE = os.getenv("CONTAINER_ENGINE") + + def pytest_collect_file(parent, path): if path.basename == "verify": return LocalRepo.from_parent(parent, fspath=path) @@ -99,9 +102,10 @@ def collect(self): args = [ "--appendix", 'RUN echo "appendix" > /tmp/appendix', - "--engine", - "podman", + "--engine=podman", ] + if CONTAINER_ENGINE: + args.append(f"--PodmanEngine.podman_executable={CONTAINER_ENGINE}") # If there's an extra-args.yaml file in a test dir, assume it contains # a yaml list with extra arguments to be passed to repo2docker extra_args_path = os.path.join(self.fspath.dirname, "extra-args.yaml")