|
| 1 | +name: Build Multi-Arch Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + BWDC_VERSION: |
| 7 | + description: "BWDC Version (used as build arg and image tag)" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + push: |
| 11 | + tags: |
| 12 | + - "v*" |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + IMAGE_NAME: ${{ github.repository }} |
| 17 | + |
| 18 | +jobs: |
| 19 | + build: |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - platform: linux/amd64 |
| 24 | + runner: ubuntu-latest |
| 25 | + - platform: linux/arm64 |
| 26 | + runner: ubuntu-24.04-arm |
| 27 | + |
| 28 | + runs-on: ${{ matrix.runner }} |
| 29 | + |
| 30 | + permissions: |
| 31 | + contents: read |
| 32 | + packages: write |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set version |
| 39 | + id: version |
| 40 | + run: | |
| 41 | + if [ -n "${{ inputs.BWDC_VERSION }}" ]; then |
| 42 | + echo "version=${{ inputs.BWDC_VERSION }}" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Log in to registry |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + registry: ${{ env.REGISTRY }} |
| 51 | + username: ${{ github.actor }} |
| 52 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + - name: Extract platform name |
| 58 | + id: platform |
| 59 | + run: | |
| 60 | + PLATFORM=${{ matrix.platform }} |
| 61 | + echo "name=${PLATFORM//\//-}" >> $GITHUB_OUTPUT |
| 62 | +
|
| 63 | + - name: Build and push by digest |
| 64 | + id: build |
| 65 | + uses: docker/build-push-action@v6 |
| 66 | + with: |
| 67 | + context: . |
| 68 | + platforms: ${{ matrix.platform }} |
| 69 | + build-args: | |
| 70 | + BWDC_VERSION=${{ steps.version.outputs.version }} |
| 71 | + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 72 | + |
| 73 | + - name: Export digest |
| 74 | + run: | |
| 75 | + mkdir -p /tmp/digests |
| 76 | + digest="${{ steps.build.outputs.digest }}" |
| 77 | + touch "/tmp/digests/${digest#sha256:}" |
| 78 | +
|
| 79 | + - name: Upload digest |
| 80 | + uses: actions/upload-artifact@v4 |
| 81 | + with: |
| 82 | + name: digests-${{ steps.platform.outputs.name }} |
| 83 | + path: /tmp/digests/* |
| 84 | + if-no-files-found: error |
| 85 | + retention-days: 1 |
| 86 | + |
| 87 | + merge: |
| 88 | + runs-on: ubuntu-latest |
| 89 | + needs: build |
| 90 | + |
| 91 | + permissions: |
| 92 | + contents: read |
| 93 | + packages: write |
| 94 | + |
| 95 | + steps: |
| 96 | + - name: Set version |
| 97 | + id: version |
| 98 | + run: | |
| 99 | + if [ -n "${{ inputs.BWDC_VERSION }}" ]; then |
| 100 | + echo "version=${{ inputs.BWDC_VERSION }}" >> $GITHUB_OUTPUT |
| 101 | + else |
| 102 | + echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT |
| 103 | + fi |
| 104 | +
|
| 105 | + - name: Download digests |
| 106 | + uses: actions/download-artifact@v4 |
| 107 | + with: |
| 108 | + path: /tmp/digests |
| 109 | + pattern: digests-* |
| 110 | + merge-multiple: true |
| 111 | + |
| 112 | + - name: Log in to registry |
| 113 | + uses: docker/login-action@v3 |
| 114 | + with: |
| 115 | + registry: ${{ env.REGISTRY }} |
| 116 | + username: ${{ github.actor }} |
| 117 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + |
| 119 | + - name: Create manifest list and push |
| 120 | + working-directory: /tmp/digests |
| 121 | + run: | |
| 122 | + docker buildx imagetools create \ |
| 123 | + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} \ |
| 124 | + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ |
| 125 | + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) |
| 126 | +
|
| 127 | + - name: Inspect image |
| 128 | + run: | |
| 129 | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} |
0 commit comments