Skip to content

Commit

Permalink
Merge pull request #90 from manics/test-docker-nerdctl
Browse files Browse the repository at this point in the history
Test docker and nerdctl, upgrade to pytest 8
  • Loading branch information
manics authored Mar 3, 2024
2 parents abad9ca + 808f88e commit 127a569
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
38 changes: 33 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion repo2podman/podman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
33 changes: 19 additions & 14 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
from repo2docker.__main__ import make_r2d


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)
CONTAINER_ENGINE = os.getenv("CONTAINER_ENGINE")


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):
Expand Down Expand Up @@ -79,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
Expand All @@ -99,20 +102,22 @@ 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")
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)
# 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)
yield Repo2DockerTest.from_parent(
self, name=self.fspath.basename, args=args + ["./verify"]
self, name=self.path.name, args=args + ["./verify"]
)

0 comments on commit 127a569

Please sign in to comment.