From c1081a9a54d44776b6e49661dfcc24c6734fcd32 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sat, 2 Mar 2024 23:31:48 +0000 Subject: [PATCH 1/4] Replace `stop` `--timeout` with `--time` --- repo2podman/podman.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repo2podman/podman.py b/repo2podman/podman.py index d45dccb..c8d2a95 100644 --- a/repo2podman/podman.py +++ b/repo2podman/podman.py @@ -327,7 +327,7 @@ def remove(self): def stop(self, *, timeout=10): lines = exec_podman( - ["stop", "--timeout", str(timeout), self.id], + ["stop", "--time", str(timeout), self.id], capture="stdout", exe=self._podman_executable, ) From 0b77ddff9003f1950f1331e4f73676564d44ca5e Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 3 Mar 2024 18:01:22 +0000 Subject: [PATCH 2/4] Test docker and rootless nerdctl --- .github/workflows/build.yml | 38 ++++++++++++++++++++++++++++++++----- tests/conftest.py | 8 ++++++-- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9305446..9299bec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,19 +6,21 @@ on: jobs: lint: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.1 test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: # Do not cancel all jobs if one fails 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,15 @@ jobs: cache: pip cache-dependency-path: dev-requirements.txt + - name: Install nerdctl + if: matrix.container_engine == 'nerdctl' + run: | + NERDCTL_VERSION=1.7.4 + sudo systemctl disable --now docker + 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 + containerd-rootless-setuptool.sh install + containerd-rootless-setuptool.sh install-buildkit + - name: Install run: | pip install -r dev-requirements.txt @@ -67,7 +91,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: @@ -76,7 +104,7 @@ jobs: # Only publish if other jobs passed - lint - test - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -147,7 +175,7 @@ jobs: status_all: name: Status matrix Test if: always() - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 needs: - lint - test 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") From 77c6dfcc8e26709c7872edad3dc4f090e9fdb680 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 3 Mar 2024 19:25:38 +0000 Subject: [PATCH 3/4] pytest==8.0.2 --- dev-requirements.txt | 2 +- tests/conftest.py | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index af97237..7dccbf2 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,4 +1,4 @@ build==1.0.3 jupyter-repo2docker==2023.6.0 -pytest==7.4.4 +pytest==8.0.2 pre-commit==3.6.2 diff --git a/tests/conftest.py b/tests/conftest.py index 0bd665d..9046f7c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,11 +22,11 @@ CONTAINER_ENGINE = os.getenv("CONTAINER_ENGINE") -def pytest_collect_file(parent, path): - if path.basename == "verify": - return LocalRepo.from_parent(parent, fspath=path) - # elif path.basename.endswith(".repos.yaml"): - # return RemoteRepoList(path, parent) +def pytest_collect_file(parent, file_path): + if file_path.name == "verify": + return LocalRepo.from_parent(parent, path=file_path) + # elif file_path.name.endswith(".repos.yaml"): + # return RemoteRepoList.from_parent(parent, path=file_path) def make_test_func(args): @@ -82,7 +82,7 @@ def __init__(self, name, parent, args): super().__init__(name, parent, callobj=f) def reportinfo(self): - return self.parent.fspath, None, "" + return self.parent.path, None, "" def repr_failure(self, excinfo): err = excinfo.value @@ -108,15 +108,14 @@ def collect(self): 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") - if os.path.exists(extra_args_path): - with open(extra_args_path) as f: - extra_args = yaml.safe_load(f) + extra_args_path = self.path.parent / "test-extra-args.yaml" + if extra_args_path.exists(): + extra_args = yaml.safe_load(extra_args_path.read_text()) args += extra_args - args.append(self.fspath.dirname) + args.append(str(self.path.parent)) yield Repo2DockerTest.from_parent(self, name="build", args=args) yield Repo2DockerTest.from_parent( - self, name=self.fspath.basename, args=args + ["./verify"] + self, name=self.path.name, args=args + ["./verify"] ) From 808f88eb0cfb8f813fdef301425fe6a4ec83efc8 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Sun, 3 Mar 2024 19:33:27 +0000 Subject: [PATCH 4/4] Avoid overly long image names --- tests/conftest.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 9046f7c..68e5dcd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -113,6 +113,8 @@ def collect(self): extra_args = yaml.safe_load(extra_args_path.read_text()) args += extra_args + # Avoid overly long image names + args.append("--image-name=" + "-".join(self.path.parent.parts[-3:])) args.append(str(self.path.parent)) yield Repo2DockerTest.from_parent(self, name="build", args=args)