diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4980a80..222f53f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,37 +80,37 @@ jobs: - run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar - run: rm -Rf /tmp/docker-image/ - run: echo -e "${{ env.DOCKER_IMAGE }}:${{ env.PLATFORM_PAIR }}" | xargs -I % sh -c 'docker run -v /tmp/trivy:/var/lib/trivy -v /var/run/docker.sock:/var/run/docker.sock -t aquasec/trivy:latest --cache-dir /var/lib/trivy image --exit-code 1 --no-progress --format table % || true' -# tests: -# name: Test ${{ matrix.platform }} -# needs: -# - supported-platform-matrix -# - scan-vulnerability -# strategy: -# fail-fast: false -# matrix: -# platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }} -# runs-on: ubuntu-latest -# steps: -# - name: Prepare -# run: | -# platform=${{ matrix.platform }} -# echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV -# - name: Set up QEMU -# uses: docker/setup-qemu-action@v3 -# - uses: actions/checkout@v4 -# - uses: actions/download-artifact@v4 -# with: -# name: docker-image-${{ env.PLATFORM_PAIR }} -# path: /tmp/docker-image -# - run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar -# - run: docker image ls -a -# - run: ./tests.sh "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}" + tests: + name: Test ${{ matrix.platform }} + needs: + - supported-platform-matrix + - scan-vulnerability + strategy: + fail-fast: false + matrix: + platform: ${{ fromJson(needs.supported-platform-matrix.outputs.platform) }} + runs-on: ubuntu-latest + steps: + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: docker-image-${{ env.PLATFORM_PAIR }} + path: /tmp/docker-image + - run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar + - run: docker image ls -a + - run: docker run --platform "${{ matrix.platform }}" --rm -v "$(pwd)/tests:/tests" -v "/var/run/docker.sock:/var/run/docker.sock:ro" -t "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}" --verbose push-image: if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/main' name: Push needs: - supported-platform-matrix -# - tests + - tests runs-on: ubuntu-latest services: registry: diff --git a/Dockerfile b/Dockerfile index bcb7024..8ca97e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,12 +17,13 @@ LABEL org.label-schema.title="Testinfra Docker container" \ org.opencontainers.image.vendor="WyriHaximus.net" \ org.opencontainers.image.authors="Cees-Jan Kiewiet " -WORKDIR /project - -# hadolint ignore=DL3018 -RUN apk add --no-cache docker python3 py-pip -# hadolint ignore=DL3013 -RUN pip install --no-cache-dir docker --break-system-packages && \ +# hadolint ignore=DL3018,DL3013 +RUN set -e && \ + apk add --no-cache docker python3 py-pip && \ + pip3 install --no-cache-dir --upgrade pip --break-system-packages && \ + pip install --no-cache-dir docker --break-system-packages && \ pip install --no-cache-dir pytest-testinfra --break-system-packages +WORKDIR /tests + ENTRYPOINT ["py.test", "-p", "no:cacheprovider"] diff --git a/tests/test_image.py b/tests/test_image.py new file mode 100644 index 0000000..be6a62e --- /dev/null +++ b/tests/test_image.py @@ -0,0 +1,13 @@ +import pytest + +def test_docker(host): + output = host.run('docker -v') + assert output.rc == 0 + assert u'Docker version ' in output.stdout + assert output.stderr == '' + +def test_pip(host): + assert host.exists("pip") + +def test_pytest(host): + assert host.exists("py.test")