From 2bfe53691352dbd00036faf293c754ea51008a9c Mon Sep 17 00:00:00 2001 From: Tom Tuffin Date: Thu, 5 Oct 2023 14:13:57 +0200 Subject: [PATCH] ci: update CI image build tests - Move build-and-test-image to actions - Run image test on PR and push to main - Run tests against multiple arch's --- .github/actions/image-test/action.yml | 26 ++++++++++++++++++++++++++ .github/workflows/build-image.yml | 10 ++-------- .github/workflows/ci.yml | 18 ++++++++++++++++++ 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 .github/actions/image-test/action.yml diff --git a/.github/actions/image-test/action.yml b/.github/actions/image-test/action.yml new file mode 100644 index 000000000..c6184589f --- /dev/null +++ b/.github/actions/image-test/action.yml @@ -0,0 +1,26 @@ +name: build-and-test-image +description: Build and test the container image + +runs: + using: composite + steps: + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build container image + uses: docker/build-push-action@v4 + with: + context: . + platforms: ${{ matrix.build-arch }} + tags: localhost/ansible-rulebook:test + load: true + + - name: Run tests + shell: bash + run: > + docker run --rm -u 0 localhost/ansible-rulebook:test bash -c ' + pip install -r requirements_test.txt && + pytest -m "e2e" -n auto' diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 8c3aebac7..204c0e598 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -21,14 +21,8 @@ jobs: - name: Checkout repository uses: actions/checkout@v3 - - name: Build local image - run: docker build -t localhost/ansible-rulebook:test . - - - name: Run tests - run: > - docker run --rm -u 0 localhost/ansible-rulebook:test bash -c ' - pip install -r requirements_test.txt && - pytest -m "e2e" -n auto' + - name: Build and test the container image + uses: ./.github/actions/image-test build-and-push-image: needs: build-and-test-image diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 783dfd4e7..22b4b9989 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,3 +79,21 @@ jobs: flags: "unittests-${{ matrix.python-version }}" name: codecov-umbrella verbose: true + + build-and-test-image: + # we must use a matrix because buildx load + # does not currently support multi-arch. + # https://docs.docker.com/engine/reference/commandline/buildx_build/#docker + strategy: + matrix: + build-arch: + - linux/amd64 + - linux/arm64 + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Build and test the container image + uses: ./.github/actions/image-test