Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests #5

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"

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"]
13 changes: 13 additions & 0 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -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")