From 2d3fcc1f26c2a225e56f20da389160de5c7a4209 Mon Sep 17 00:00:00 2001 From: Simon Walker Date: Tue, 15 Aug 2023 09:23:53 +0100 Subject: [PATCH] Split build to test built docker image --- .github/workflows/docker-publish.yml | 43 ++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 4887246..bfa59f8 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -11,9 +11,15 @@ on: pull_request: branches: [ "main" ] +# cancel in-flight CI runs +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + TEST_TAG: ${{ github.repository }}:test jobs: # Test the package @@ -41,26 +47,52 @@ jobs: needs: - test runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and export to docker for testing + uses: docker/build-push-action@v4 + with: + context: . + load: true + tags: ${{ env.TEST_TAG }} + + - name: Test the docker image + run: | + docker run --rm ${{ env.TEST_TAG }} diagnose --help + docker run --rm ${{ env.TEST_TAG }} probe --help + + publish: + runs-on: ubuntu-latest + needs: + - build permissions: contents: read packages: write # This is used to complete the identity challenge # with sigstore/fulcio when running outside of PRs. id-token: write - steps: - name: Checkout repository uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + # Workaround: https://github.com/docker/build-push-action/issues/461 - name: Setup Docker buildx - uses: docker/setup-buildx-action@v2.9.1 + uses: docker/setup-buildx-action@v2 # Login against a Docker registry except on PR # https://github.com/docker/login-action - name: Log into registry ${{ env.REGISTRY }} if: github.event_name != 'pull_request' - uses: docker/login-action@v2.2.0 + uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -78,11 +110,12 @@ jobs: # https://github.com/docker/build-push-action - name: Build and push Docker image id: build-and-push - uses: docker/build-push-action@v4.1.1 + uses: docker/build-push-action@v4 with: context: . push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64