|
| 1 | +name: Build and Test Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: ["main"] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + should-test-docker-build: |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: read |
| 13 | + name: Check if should `test_docker_build` run |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Check out the repo |
| 17 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 18 | + |
| 19 | + - name: Check if Dockerfile changed |
| 20 | + uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2 |
| 21 | + id: docker-changes |
| 22 | + with: |
| 23 | + filters: | |
| 24 | + docker: |
| 25 | + - 'Dockerfile' |
| 26 | + - '.dockerignore' |
| 27 | + workflow: |
| 28 | + - ./.github/actions/docker-build/action.yml |
| 29 | + outputs: |
| 30 | + docker: ${{ steps.docker-changes.outputs.docker }} |
| 31 | + workflow: ${{ steps.docker-changes.outputs.workflow }} |
| 32 | + |
| 33 | + test-docker-build: |
| 34 | + needs: [should-test-docker-build] |
| 35 | + name: Test Docker build ${{ matrix.arch }} |
| 36 | + runs-on: ubuntu-latest |
| 37 | + if: (needs.should-test-docker-build.outputs.workflow == 'true' || needs.should-test-docker-build.outputs.docker == 'true') |
| 38 | + permissions: |
| 39 | + contents: read |
| 40 | + packages: read |
| 41 | + strategy: |
| 42 | + matrix: |
| 43 | + include: |
| 44 | + - arch: amd64 |
| 45 | + platform: linux/amd64 |
| 46 | + image-name: build-amd64 |
| 47 | + needs-qemu: false |
| 48 | + - arch: arm64 |
| 49 | + platform: linux/arm64 |
| 50 | + image-name: build-arm64 |
| 51 | + needs-qemu: true |
| 52 | + steps: |
| 53 | + - name: Check out the repo |
| 54 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 55 | + |
| 56 | + - name: Log in to GitHub Container Registry |
| 57 | + uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0 |
| 58 | + with: |
| 59 | + registry: ghcr.io |
| 60 | + username: ${{ github.actor }} |
| 61 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + |
| 63 | + - name: Build image |
| 64 | + uses: ./.github/actions/docker-build |
| 65 | + with: |
| 66 | + context: . |
| 67 | + file: ./Dockerfile |
| 68 | + push: false |
| 69 | + load: true |
| 70 | + platforms: ${{ matrix.platform }} |
| 71 | + cache-from: type=registry,ref=ghcr.io/elementsinteractive/twyn:buildcache-${{ matrix.arch }} |
| 72 | + image-name: ${{ matrix.image-name }} |
| 73 | + setup-qemu: ${{ matrix.needs-qemu }} |
| 74 | + |
| 75 | + - name: Test |
| 76 | + run: | |
| 77 | + docker run --platform ${{ matrix.platform }} --rm ${{ matrix.image-name }}:pr-${{ github.event.pull_request.number }} --version |
0 commit comments