|
8 | 8 | types: |
9 | 9 | - completed |
10 | 10 |
|
| 11 | +env: |
| 12 | + REGISTRY_IMAGE: ghcr.io/memoryleek/party-api |
| 13 | + |
11 | 14 | jobs: |
12 | 15 | build: |
13 | 16 | runs-on: ubuntu-latest |
14 | 17 | if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + platform: |
| 22 | + - linux/amd64 |
| 23 | + - linux/arm64 |
| 24 | + include: |
| 25 | + - platform: linux/amd64 |
| 26 | + runner: ubuntu-24.04 |
| 27 | + - platform: linux/arm64 |
| 28 | + runner: ubuntu-24.04-arm |
15 | 29 | steps: |
16 | 30 | - name: Checkout |
17 | 31 | uses: actions/checkout@v5 |
18 | 32 |
|
19 | | - - name: Set up QEMU |
20 | | - uses: docker/setup-qemu-action@v3 |
| 33 | + - name: Prepare |
| 34 | + run: | |
| 35 | + platform=${{ matrix.platform }} |
| 36 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 37 | +
|
| 38 | + - name: Docker meta |
| 39 | + id: meta |
| 40 | + uses: docker/metadata-action@v5 |
| 41 | + with: |
| 42 | + images: ${{ env.REGISTRY_IMAGE }} |
| 43 | + tags: latest |
| 44 | + |
| 45 | + - name: Login to GitHub Container Registry |
| 46 | + uses: docker/login-action@v3 |
| 47 | + with: |
| 48 | + registry: ghcr.io |
| 49 | + username: "${{ github.actor }}" |
| 50 | + password: "${{ secrets.GITHUB_TOKEN }}" |
21 | 51 |
|
22 | 52 | - name: Set up Docker Buildx |
23 | 53 | uses: docker/setup-buildx-action@v3 |
24 | 54 |
|
| 55 | + - name: Build and push by digest |
| 56 | + id: build |
| 57 | + uses: docker/build-push-action@v6 |
| 58 | + with: |
| 59 | + platforms: ${{ matrix.platform }} |
| 60 | + labels: ${{ steps.meta.outputs.labels }} |
| 61 | + tags: ${{ env.REGISTRY_IMAGE }} |
| 62 | + outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 63 | + |
| 64 | + - name: Export digest |
| 65 | + run: | |
| 66 | + mkdir -p ${{ runner.temp }}/digests |
| 67 | + digest="${{ steps.build.outputs.digest }}" |
| 68 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 69 | +
|
| 70 | + - name: Upload digest |
| 71 | + uses: actions/upload-artifact@v4 |
| 72 | + with: |
| 73 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 74 | + path: ${{ runner.temp }}/digests/* |
| 75 | + if-no-files-found: error |
| 76 | + retention-days: 1 |
| 77 | + |
| 78 | + merge: |
| 79 | + runs-on: ubuntu-latest |
| 80 | + needs: |
| 81 | + - build |
| 82 | + steps: |
| 83 | + - name: Download digests |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + path: ${{ runner.temp }}/digests |
| 87 | + pattern: digests-* |
| 88 | + merge-multiple: true |
| 89 | + |
25 | 90 | - name: Login to GitHub Container Registry |
26 | 91 | uses: docker/login-action@v3 |
27 | 92 | with: |
28 | 93 | registry: ghcr.io |
29 | 94 | username: "${{ github.actor }}" |
30 | 95 | password: "${{ secrets.GITHUB_TOKEN }}" |
31 | 96 |
|
32 | | - - name: Build and push |
33 | | - uses: docker/build-push-action@v6 |
| 97 | + - name: Set up Docker Buildx |
| 98 | + uses: docker/setup-buildx-action@v3 |
| 99 | + |
| 100 | + - name: Docker meta |
| 101 | + id: meta |
| 102 | + uses: docker/metadata-action@v5 |
34 | 103 | with: |
35 | | - platforms: linux/amd64,linux/arm64 |
36 | | - push: true |
37 | | - tags: "ghcr.io/memoryleek/party-api:latest" |
| 104 | + images: ${{ env.REGISTRY_IMAGE }} |
| 105 | + tags: | |
| 106 | + type=ref,event=branch |
| 107 | + type=ref,event=pr |
| 108 | + type=semver,pattern={{version}} |
| 109 | + type=semver,pattern={{major}}.{{minor}} |
| 110 | +
|
| 111 | + - name: Create manifest list and push |
| 112 | + working-directory: ${{ runner.temp }}/digests |
| 113 | + run: | |
| 114 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 115 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 116 | +
|
| 117 | + - name: Inspect image |
| 118 | + run: | |
| 119 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments