diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73b4f247..5332c6e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,6 +72,10 @@ jobs: rustup component add rustfmt make format-check + unit-tests: + uses: ./.github/workflows/unit-tests.yml + secrets: inherit + vars: runs-on: ubuntu-24.04 outputs: @@ -180,8 +184,8 @@ jobs: podman manifest inspect ${{ needs.vars.outputs.rhacs-eng-image }} podman manifest push ${{ needs.vars.outputs.rhacs-eng-image }} - unit-tests: - uses: ./.github/workflows/unit-tests.yml + test-containers-build: + uses: ./.github/workflows/test-containers-build.yml secrets: inherit integration-tests: @@ -189,9 +193,11 @@ jobs: - vars - manifest-stackrox-io - manifest-rhacs-eng + - test-containers-build uses: ./.github/workflows/integration-tests.yml with: tag: ${{ needs.vars.outputs.tag }} + qa-tag: ${{ needs.test-containers-build.outputs.qa-tag }} secrets: inherit performance-tests: diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index f32e77f8..49c4c483 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -13,6 +13,9 @@ on: tag: description: The container image tag to test type: string + qa-tag: + description: The test containers tag to use + type: string job-tag: description: Additional tag to prevent collision on GCP VM naming type: string @@ -68,6 +71,7 @@ jobs: env: FACT_VERSION: ${{ inputs.version }} FACT_REGISTRY: ${{ inputs.registry }} + FACT_QA_TAG: ${{ inputs.qa-tag }} FACT_TAG: ${{ inputs.tag }} run: | FACT_IMAGE_NAME="$(make -sC "${GITHUB_WORKSPACE}/fact" image-name)" @@ -77,6 +81,7 @@ jobs: fact: image: ${FACT_IMAGE_NAME} version: ${FACT_VERSION} + qa_tag: ${FACT_QA_TAG} quay: username: ${{ secrets.QUAY_RHACS_ENG_RO_USERNAME }} password: ${{ secrets.QUAY_RHACS_ENG_RO_PASSWORD }} diff --git a/.github/workflows/konflux-tests.yml b/.github/workflows/konflux-tests.yml index f3415578..a42a9784 100644 --- a/.github/workflows/konflux-tests.yml +++ b/.github/workflows/konflux-tests.yml @@ -40,14 +40,20 @@ jobs: image: rhacs-eng/release-fact:${{ needs.init.outputs.fact-tag }} limit: 2400 # 40m + test-containers-build: + uses: ./.github/workflows/test-containers-build.yml + secrets: inherit + run-konflux-tests: uses: ./.github/workflows/integration-tests.yml needs: - init - wait-for-images + - test-containers-build with: version: ${{ github.head_ref || github.ref_name }} registry: quay.io/rhacs-eng/release-fact tag: ${{ needs.init.outputs.fact-tag }} + qa-tag: ${{ needs.test-containers-build.outputs.qa-tag }} job-tag: konf secrets: inherit diff --git a/.github/workflows/test-containers-build.yml b/.github/workflows/test-containers-build.yml new file mode 100644 index 00000000..e5ebb128 --- /dev/null +++ b/.github/workflows/test-containers-build.yml @@ -0,0 +1,126 @@ +name: Build integration test containers + +on: + workflow_call: + outputs: + qa-tag: + value: ${{ jobs.determine-qa-tag.outputs.qa-tag }} + +jobs: + should-build-test-containers: + name: Determine if tests image needs to be built + runs-on: ubuntu-24.04 + outputs: + build-image: ${{ (github.event_name != 'schedule' && + (steps.changed.outputs.qa-tag == 'true' || + contains(github.event.pull_request.labels.*.name, 'rebuild-test-container'))) }} + + steps: + - uses: actions/checkout@v7 + + - uses: dorny/paths-filter@v4 + id: changed + with: + list-files: shell + base: ${{ github.ref }} + + # Only trigger a rebuild when the QA tag has changed + filters: | + qa-tag: + - tests/containers/QA_TAG + + determine-qa-tag: + name: Determine QA tag + runs-on: ubuntu-24.04 + needs: + - should-build-test-containers + outputs: + qa-tag: ${{ steps.qa-tag.outputs.qa-tag }} + steps: + - uses: actions/checkout@v7 + with: + submodules: true + fetch-depth: 0 + persist-credentials: false + - name: Determine QA tag + id: qa-tag + run: | + QA_TAG="$(cat "${GITHUB_WORKSPACE}/tests/containers/QA_TAG")" + if [[ "${GITHUB_EVENT_NAME}" == "pull_request" && "${{ needs.should-build-test-containers.outputs.build-image }}" == "true" ]]; then + QA_TAG="${QA_TAG}-$(make tag)" + fi + echo "::notice::Using QA tag: ${QA_TAG}" + echo "qa-tag=${QA_TAG}" >> "$GITHUB_OUTPUT" + + build-test-containers: + name: Build and push test containers + runs-on: ubuntu-24.04 + needs: + - determine-qa-tag + - should-build-test-containers + if: needs.should-build-test-containers.outputs.build-image == 'true' || + contains(github.event.pull_request.labels.*.name, 'rebuild-test-container') + env: + FACT_QA_TAG: ${{ needs.determine-qa-tag.outputs.qa-tag }} + + steps: + - uses: actions/checkout@v7 + + - name: Setup QEMU + uses: docker/setup-qemu-action@v4 + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v4 + + - name: Login to quay.io/rhacs-eng + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }} + password: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }} + + - name: Check images already exist + id: images-exist + run: | + manifest_exists() { + local image=$1 output + if output=$(docker manifest inspect "${image}" 2>&1); then + return 0 + elif echo "${output}" | grep -Eiq 'no such manifest:|manifest unknown'; then + return 1 + else + printf '%s: %s\n' "${image}" "${output}" >&2 + return 2 + fi + } + + image_names=$(make --no-print-directory -s \ + -C "${GITHUB_WORKSPACE}/tests/containers" image-names) || exit $? + + EXIST=true + while IFS= read -r image_name; do + [[ -z "${image_name}" ]] && continue + if manifest_exists "${image_name}"; then + continue + else + status=$? + fi + + if [[ "${status}" -eq 1 ]]; then + EXIST=false + else + exit "${status}" + fi + done <<< "${image_names}" + + if [[ "${EXIST}" == false ]]; then + echo "::notice::At least one test container manifest is absent" + fi + echo "exist=${EXIST}" >> "${GITHUB_OUTPUT}" + + - name: Build and Push containers + if: steps.images-exist.outputs.exist == 'false' || contains(github.event.pull_request.labels.*.name, 'rebuild-test-container') + env: + PLATFORM: linux/amd64,linux/arm64 + run: | + make -C "${GITHUB_WORKSPACE}/tests/containers" build-and-push diff --git a/ansible/run-tests.yml b/ansible/run-tests.yml index 20578442..c2e3a02f 100644 --- a/ansible/run-tests.yml +++ b/ansible/run-tests.yml @@ -37,6 +37,8 @@ - block: - name: Run tests + environment: + FACT_QA_TAG: "{{ qa_tag | default(None) }}" ansible.builtin.shell: cmd: | cd "${HOME}/fact" diff --git a/tests/conftest.py b/tests/conftest.py index cce6a03f..7e4f1ab8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -228,3 +228,8 @@ def fact(request, docker_client, fact_config, server, logs_dir, test_file): def pytest_addoption(parser): parser.addoption('--image', action='store', default='quay.io/stackrox-io/fact:latest', help='The image to be used for testing') + parser.addoption( + '--no-local-builds', + action='store_true', + help='Do not build test containers locally', + ) diff --git a/tests/containers.py b/tests/containers.py new file mode 100644 index 00000000..af515dc2 --- /dev/null +++ b/tests/containers.py @@ -0,0 +1,54 @@ +from __future__ import annotations + +import os + +import docker +import docker.errors +from docker.models.images import Image + + +def read_qa_tag() -> str: + tag = os.environ.get('FACT_QA_TAG') + if tag is not None: + return tag + + with open('containers/QA_TAG') as f: + return f.read().strip() + + +QA_TAG = read_qa_tag() +QA_REPOSITORY = os.environ.get( + 'FACT_QA_REPOSITORY', 'quay.io/rhacs-eng/qa-multi-arch' +) + + +def pull_or_build( + docker_client: docker.DockerClient, + tag: str, + path: str | None, + no_local_builds: bool, + containerfile: str = 'Containerfile', +) -> Image: + tag = f'{tag}-{QA_TAG}' + image = f'{QA_REPOSITORY}:{tag}' + + try: + return docker_client.images.get(image) + except docker.errors.ImageNotFound: + print(f'{image} not found locally, attempting to pull') + + try: + return docker_client.images.pull(QA_REPOSITORY, tag=tag) + except docker.errors.APIError as e: + if no_local_builds: + raise e + + if e.status_code != 401 and e.status_code != 404: + raise e + print(f'Failed to pull image: {e}') + print('Attempting to build image from source') + + image, _ = docker_client.images.build( + path=path, tag=image, dockerfile=containerfile + ) + return image diff --git a/tests/containers/Makefile b/tests/containers/Makefile new file mode 100644 index 00000000..3998bc20 --- /dev/null +++ b/tests/containers/Makefile @@ -0,0 +1,10 @@ +include constants.mk + +TARGETS := build build-and-push image-names +DIRS := $(wildcard ./*/) + +$(TARGETS): $(DIRS) +$(DIRS): + $(MAKE) -C $@ $(MAKECMDGOALS) + +.PHONY: $(TARGETS) $(DIRS) diff --git a/tests/containers/QA_TAG b/tests/containers/QA_TAG new file mode 100644 index 00000000..0ea3a944 --- /dev/null +++ b/tests/containers/QA_TAG @@ -0,0 +1 @@ +0.2.0 diff --git a/tests/containers/base/Containerfile b/tests/containers/base/Containerfile new file mode 100644 index 00000000..102da78d --- /dev/null +++ b/tests/containers/base/Containerfile @@ -0,0 +1,2 @@ +# CentOS Stream 10 +FROM quay.io/centos/centos@sha256:6f8d618844ed5af4365bad24bea19fb0435fd5ec808201af9aeb19d7a28eb515 diff --git a/tests/containers/base/Makefile b/tests/containers/base/Makefile new file mode 100644 index 00000000..9065f26a --- /dev/null +++ b/tests/containers/base/Makefile @@ -0,0 +1,22 @@ +include ../constants.mk + +FACT_QA_BASE_TAG := fact-base-$(FACT_QA_TAG) + +all: build + +run: + $(DOCKER) buildx build $(BUILD_ARGS) --platform $(PLATFORM) \ + -t quay.io/rhacs-eng/qa-multi-arch:$(FACT_QA_BASE_TAG) \ + -f Containerfile \ + $(CURDIR) + +build: BUILD_ARGS = --load +build: run + +build-and-push: BUILD_ARGS = --push +build-and-push: run + +image-names: + @echo quay.io/rhacs-eng/qa-multi-arch:$(FACT_QA_BASE_TAG) + +.PHONY: build build-and-push all run image-names diff --git a/tests/containers/constants.mk b/tests/containers/constants.mk new file mode 100644 index 00000000..01b5cb2a --- /dev/null +++ b/tests/containers/constants.mk @@ -0,0 +1,13 @@ +REPO_ROOT := $(shell git rev-parse --show-toplevel) + +include $(REPO_ROOT)/constants.mk + +# PLATFORM can be a comma separated list of platforms of the form linux/ +# it is passed to buildx, which will build for each one (this is important +# for pushing multi-arch images because `buildx --push` will push a manifest list +# containing all the relevant platforms) +PLATFORM ?= linux/amd64 + +# Path needs to be absolute so subdirectories don't fail when they include this +# file. +FACT_QA_TAG ?= $(shell cat "$(REPO_ROOT)/tests/containers/QA_TAG") diff --git a/tests/containers/editors/Containerfile b/tests/containers/editors/Containerfile index 47c91b43..0c8529e1 100644 --- a/tests/containers/editors/Containerfile +++ b/tests/containers/editors/Containerfile @@ -1,5 +1,9 @@ -FROM quay.io/fedora/fedora:43 +# CentOS Stream 10 +FROM quay.io/centos/centos@sha256:6f8d618844ed5af4365bad24bea19fb0435fd5ec808201af9aeb19d7a28eb515 -RUN dnf install -y \ - neovim \ - vim +RUN dnf config-manager --set-enabled crb && \ + dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm && \ + dnf install -y \ + neovim-0.10.1-4.el10_0 \ + vim-enhanced-2:9.1.083-25.el10 && \ + dnf clean all diff --git a/tests/containers/editors/Makefile b/tests/containers/editors/Makefile new file mode 100644 index 00000000..384d30d6 --- /dev/null +++ b/tests/containers/editors/Makefile @@ -0,0 +1,22 @@ +include ../constants.mk + +FACT_QA_EDITORS_TAG := fact-editors-$(FACT_QA_TAG) + +all: build + +run: + $(DOCKER) buildx build $(BUILD_ARGS) --platform $(PLATFORM) \ + -t quay.io/rhacs-eng/qa-multi-arch:$(FACT_QA_EDITORS_TAG) \ + -f Containerfile \ + $(CURDIR) + +build: BUILD_ARGS = --load +build: run + +build-and-push: BUILD_ARGS = --push +build-and-push: run + +image-names: + @echo quay.io/rhacs-eng/qa-multi-arch:$(FACT_QA_EDITORS_TAG) + +.PHONY: build build-and-push all run image-names diff --git a/tests/containers/self-deleter/Makefile b/tests/containers/self-deleter/Makefile new file mode 100644 index 00000000..0a0fd6c7 --- /dev/null +++ b/tests/containers/self-deleter/Makefile @@ -0,0 +1,22 @@ +include ../constants.mk + +FACT_QA_SELF_DELETER_TAG := fact-self-deleter-$(FACT_QA_TAG) + +all: build + +run: + $(DOCKER) buildx build $(BUILD_ARGS) --platform $(PLATFORM) \ + -t quay.io/rhacs-eng/qa-multi-arch:$(FACT_QA_SELF_DELETER_TAG) \ + -f Containerfile \ + $(CURDIR) + +build: BUILD_ARGS = --load +build: run + +build-and-push: BUILD_ARGS = --push +build-and-push: run + +image-names: + @echo quay.io/rhacs-eng/qa-multi-arch:$(FACT_QA_SELF_DELETER_TAG) + +.PHONY: build build-and-push all run image-names diff --git a/tests/test_editors/commons.py b/tests/test_editors/commons.py index 150e662d..4639b5df 100644 --- a/tests/test_editors/commons.py +++ b/tests/test_editors/commons.py @@ -1,20 +1,27 @@ import os +import docker +import docker.models.images import pytest +from containers import pull_or_build + def get_vi_test_file(dir): return os.path.join(dir, '4913') @pytest.fixture(scope='session') -def build_editor_image(docker_client): - image, _ = docker_client.images.build( +def build_editor_image( + request: pytest.FixtureRequest, docker_client: docker.DockerClient +): + no_local_builds = bool(request.config.getoption('--no-local-builds')) + return pull_or_build( + docker_client, + tag='fact-editors', path='containers/editors', - tag='editors:latest', - dockerfile='Containerfile', + no_local_builds=no_local_builds, ) - return image def run_editor_container(image, docker_client, ignored_dir): @@ -38,9 +45,31 @@ def run_editor_container(image, docker_client, ignored_dir): container.remove() +@pytest.fixture(scope='session') +def build_base_image( + request: pytest.FixtureRequest, docker_client: docker.DockerClient +) -> docker.models.images.Image: + no_local_builds = bool(request.config.getoption('--no-local-builds')) + return pull_or_build( + docker_client, + tag='fact-base', + path='containers/base', + no_local_builds=no_local_builds, + ) + + @pytest.fixture -def vi_container(docker_client, ignored_dir): - yield from run_editor_container('quay.io/fedora/fedora:43', docker_client, ignored_dir) +def base_container( + docker_client: docker.DockerClient, + build_base_image: docker.models.images.Image, + ignored_dir: str, +): + image = build_base_image.tags[0] + yield from run_editor_container( + image, + docker_client, + ignored_dir, + ) @pytest.fixture diff --git a/tests/test_editors/test_nvim.py b/tests/test_editors/test_nvim.py index 51ffc26b..1f265958 100644 --- a/tests/test_editors/test_nvim.py +++ b/tests/test_editors/test_nvim.py @@ -34,8 +34,9 @@ def test_open_file(editor_container, server): editor_container.exec_run(cmd) touch = Process.in_container( - exe_path='/usr/bin/touch', - args=f'touch {fut}', + exe_path='/usr/bin/coreutils', + args="/usr/bin/coreutils '--coreutils-prog-shebang=touch' " + + f'/usr/bin/touch {fut}', name='touch', container_id=container_id, ) @@ -101,8 +102,9 @@ def test_open_file_ovfs(editor_container, server): editor_container.exec_run(cmd) touch = Process.in_container( - exe_path='/usr/bin/touch', - args=f'touch {fut}', + exe_path='/usr/bin/coreutils', + args="/usr/bin/coreutils '--coreutils-prog-shebang=touch' " + + f'/usr/bin/touch {fut}', name='touch', container_id=container_id, ) diff --git a/tests/test_editors/test_sed.py b/tests/test_editors/test_sed.py index 122d1527..c45aca6d 100644 --- a/tests/test_editors/test_sed.py +++ b/tests/test_editors/test_sed.py @@ -2,15 +2,16 @@ from event import Event, EventType, Process -def test_sed(vi_container, server): +def test_sed(base_container, server): + assert base_container.id is not None # File Under Test fut = '/mounted/test.txt' - create_cmd = f"sh -c \"echo 'This is a test' > {fut}\"" - sed_cmd = fr'sed -i -e "s/a test/not \\0/" {fut}' - container_id = vi_container.id[:12] + create_cmd = f'sh -c "echo \'This is a test\' > {fut}"' + sed_cmd = rf'sed -i -e "s/a test/not \\0/" {fut}' + container_id = base_container.id[:12] - vi_container.exec_run(create_cmd) - vi_container.exec_run(sed_cmd) + base_container.exec_run(create_cmd) + base_container.exec_run(sed_cmd) shell = Process.in_container( exe_path='/usr/bin/bash', @@ -41,15 +42,16 @@ def test_sed(vi_container, server): server.wait_events(events, strict=True) -def test_sed_ovfs(vi_container, server): +def test_sed_ovfs(base_container, server): + assert base_container.id is not None # File Under Test fut = '/container-dir/test.txt' - create_cmd = f"sh -c \"echo 'This is a test' > {fut}\"" - sed_cmd = fr'sed -i -e "s/a test/not \\0/" {fut}' - container_id = vi_container.id[:12] + create_cmd = f'sh -c "echo \'This is a test\' > {fut}"' + sed_cmd = rf'sed -i -e "s/a test/not \\0/" {fut}' + container_id = base_container.id[:12] - vi_container.exec_run(create_cmd) - vi_container.exec_run(sed_cmd) + base_container.exec_run(create_cmd) + base_container.exec_run(sed_cmd) shell = Process.in_container( exe_path='/usr/bin/bash', diff --git a/tests/test_editors/test_vi.py b/tests/test_editors/test_vi.py index 6d1d4434..10b6002b 100644 --- a/tests/test_editors/test_vi.py +++ b/tests/test_editors/test_vi.py @@ -2,7 +2,8 @@ from test_editors.commons import get_vi_test_file -def test_new_file(vi_container, server): +def test_new_file(base_container, server): + assert base_container.id is not None fut = '/mounted/test.txt' swap_file = '/mounted/.test.txt.swp' swx_file = '/mounted/.test.txt.swx' @@ -10,13 +11,13 @@ def test_new_file(vi_container, server): cmd = f"{exe} {fut} '+:normal iThis is a test' -c x" - vi_container.exec_run(cmd) + base_container.exec_run(cmd) process = Process.in_container( exe_path=exe, args=cmd, name='vi', - container_id=vi_container.id[:12], + container_id=base_container.id[:12], ) events = [ @@ -39,7 +40,8 @@ def test_new_file(vi_container, server): server.wait_events(events, strict=True) -def test_new_file_ovfs(vi_container, server): +def test_new_file_ovfs(base_container, server): + assert base_container.id is not None fut = '/container-dir/test.txt' swap_file = '/container-dir/.test.txt.swp' swx_file = '/container-dir/.test.txt.swx' @@ -47,13 +49,13 @@ def test_new_file_ovfs(vi_container, server): cmd = f"{exe} {fut} '+:normal iThis is a test' -c x" - vi_container.exec_run(cmd) + base_container.exec_run(cmd) process = Process.in_container( exe_path=exe, args=cmd, name='vi', - container_id=vi_container.id[:12], + container_id=base_container.id[:12], ) events = [ @@ -76,24 +78,26 @@ def test_new_file_ovfs(vi_container, server): server.wait_events(events, strict=True) -def test_open_file(vi_container, server): +def test_open_file(base_container, server): + assert base_container.id is not None fut = '/mounted/test.txt' fut_backup = f'{fut}~' swap_file = '/mounted/.test.txt.swp' swx_file = '/mounted/.test.txt.swx' vi_test_file = get_vi_test_file('/mounted') exe = '/usr/bin/vi' - container_id = vi_container.id[:12] + container_id = base_container.id[:12] cmd = f"{exe} {fut} '+:normal iThis is a test' -c x" # We ensure the file exists before editing. - vi_container.exec_run(f'touch {fut}') - vi_container.exec_run(cmd) + base_container.exec_run(f'touch {fut}') + base_container.exec_run(cmd) touch_process = Process.in_container( - exe_path='/usr/bin/touch', - args=f'touch {fut}', + exe_path='/usr/bin/coreutils', + args="/usr/bin/coreutils '--coreutils-prog-shebang=touch' " + + f'/usr/bin/touch {fut}', name='touch', container_id=container_id, ) @@ -142,24 +146,26 @@ def test_open_file(vi_container, server): server.wait_events(events, strict=True) -def test_open_file_ovfs(vi_container, server): +def test_open_file_ovfs(base_container, server): + assert base_container.id is not None fut = '/container-dir/test.txt' fut_backup = f'{fut}~' swap_file = '/container-dir/.test.txt.swp' swx_file = '/container-dir/.test.txt.swx' vi_test_file = get_vi_test_file('/container-dir') exe = '/usr/bin/vi' - container_id = vi_container.id[:12] + container_id = base_container.id[:12] cmd = f"{exe} {fut} '+:normal iThis is a test' -c x" # We ensure the file exists before editing. - vi_container.exec_run(f'touch {fut}') - vi_container.exec_run(cmd) + base_container.exec_run(f'touch {fut}') + base_container.exec_run(cmd) touch_process = Process.in_container( - exe_path='/usr/bin/touch', - args=f'touch {fut}', + exe_path='/usr/bin/coreutils', + args="/usr/bin/coreutils '--coreutils-prog-shebang=touch' " + + f'/usr/bin/touch {fut}', name='touch', container_id=container_id, ) diff --git a/tests/test_editors/test_vim.py b/tests/test_editors/test_vim.py index 20505b54..a315daef 100644 --- a/tests/test_editors/test_vim.py +++ b/tests/test_editors/test_vim.py @@ -87,8 +87,9 @@ def test_open_file(editor_container, server): editor_container.exec_run(cmd) touch_process = Process.in_container( - exe_path='/usr/bin/touch', - args=f'touch {fut}', + exe_path='/usr/bin/coreutils', + args="/usr/bin/coreutils '--coreutils-prog-shebang=touch' " + + f'/usr/bin/touch {fut}', name='touch', container_id=container_id, ) @@ -152,8 +153,9 @@ def test_open_file_ovfs(editor_container, server): editor_container.exec_run(cmd) touch_process = Process.in_container( - exe_path='/usr/bin/touch', - args=f'touch {fut}', + exe_path='/usr/bin/coreutils', + args="/usr/bin/coreutils '--coreutils-prog-shebang=touch' " + + f'/usr/bin/touch {fut}', name='touch', container_id=container_id, ) diff --git a/tests/test_misc.py b/tests/test_misc.py index a18814a4..815e46e1 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -1,19 +1,21 @@ import os from conftest import dump_logs +from containers import pull_or_build from event import Event, EventType, Process import pytest -@pytest.fixture -def build_self_deleter(docker_client): - image, _ = docker_client.images.build( +@pytest.fixture(scope='session') +def build_self_deleter(request: pytest.FixtureRequest, docker_client): + no_local_builds = bool(request.config.getoption('--no-local-builds')) + return pull_or_build( + docker_client, + tag='fact-self-deleter', path='containers/self-deleter', - tag='self-deleter:latest', - dockerfile='Containerfile' + no_local_builds=no_local_builds, ) - return image @pytest.fixture