|
| 1 | +name: Build and push Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v[0-9]*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: Build (${{ matrix.platform }}) |
| 11 | + runs-on: ${{ matrix.runner }} |
| 12 | + strategy: |
| 13 | + fail-fast: false |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + - platform: linux/amd64 |
| 17 | + runner: ubuntu-24.04 |
| 18 | + - platform: linux/arm64 |
| 19 | + runner: ubuntu-24.04-arm |
| 20 | + |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Log in to Docker Hub |
| 25 | + uses: docker/login-action@v3 |
| 26 | + with: |
| 27 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 28 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 29 | + |
| 30 | + - name: Set up Docker Buildx |
| 31 | + uses: docker/setup-buildx-action@v3 |
| 32 | + |
| 33 | + # Build and push platform-specific digest (no manifest tag yet) |
| 34 | + - name: Build and push by digest |
| 35 | + id: build |
| 36 | + uses: docker/build-push-action@v6 |
| 37 | + with: |
| 38 | + context: . |
| 39 | + file: docker/Dockerfile |
| 40 | + platforms: ${{ matrix.platform }} |
| 41 | + push: true |
| 42 | + outputs: type=image,name=apluslms/run-gitmanager,push-by-digest=true,name-canonical=true |
| 43 | + |
| 44 | + # Save the digest so the merge job can find it |
| 45 | + - name: Export digest |
| 46 | + run: | |
| 47 | + mkdir -p /tmp/digests |
| 48 | + digest="${{ steps.build.outputs.digest }}" |
| 49 | + touch "/tmp/digests/${digest#sha256:}" |
| 50 | +
|
| 51 | + - name: Upload digest artifact |
| 52 | + uses: actions/upload-artifact@v4 |
| 53 | + with: |
| 54 | + name: digest-${{ matrix.platform == 'linux/amd64' && 'amd64' || 'arm64' }} |
| 55 | + path: /tmp/digests/* |
| 56 | + retention-days: 1 |
| 57 | + |
| 58 | + merge: |
| 59 | + name: Merge manifests |
| 60 | + runs-on: ubuntu-24.04 |
| 61 | + needs: build |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Download digests |
| 65 | + uses: actions/download-artifact@v4 |
| 66 | + with: |
| 67 | + path: /tmp/digests |
| 68 | + pattern: digest-* |
| 69 | + merge-multiple: true |
| 70 | + |
| 71 | + - name: Log in to Docker Hub |
| 72 | + uses: docker/login-action@v3 |
| 73 | + with: |
| 74 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 75 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 76 | + |
| 77 | + - name: Set up Docker Buildx |
| 78 | + uses: docker/setup-buildx-action@v3 |
| 79 | + |
| 80 | + - name: Determine tags |
| 81 | + id: meta |
| 82 | + uses: docker/metadata-action@v5 |
| 83 | + with: |
| 84 | + images: apluslms/run-gitmanager |
| 85 | + tags: | |
| 86 | + type=raw,value=latest |
| 87 | + type=match,pattern=v(\d+\.\d+)\.\d+$,group=1 |
| 88 | +
|
| 89 | + - name: Create and push multi-arch manifest |
| 90 | + working-directory: /tmp/digests |
| 91 | + run: | |
| 92 | + docker buildx imagetools create \ |
| 93 | + $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 94 | + $(printf 'apluslms/run-gitmanager@sha256:%s ' *) |
0 commit comments