|
1 | 1 | name: Build and push intermediary Docker image |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + push: |
5 | 5 | workflow_dispatch: |
6 | 6 |
|
7 | 7 | permissions: |
|
13 | 13 | REGISTRY_IMAGE: ghcr.io/${{ github.repository }} |
14 | 14 |
|
15 | 15 | jobs: |
16 | | - build-and-push: |
| 16 | + build: |
17 | 17 | runs-on: amd-runner-2204 |
18 | 18 | strategy: |
19 | 19 | fail-fast: false |
20 | 20 | matrix: |
21 | 21 | platform: |
22 | 22 | - linux/amd64 |
23 | 23 | - linux/arm64 |
| 24 | + outputs: |
| 25 | + full_image: ${{ steps.vars.outputs.FULL_IMAGE }} |
24 | 26 | steps: |
25 | 27 | - name: Checkout source |
26 | 28 | uses: actions/checkout@v4 |
@@ -51,13 +53,60 @@ jobs: |
51 | 53 | password: ${{ secrets.GITHUB_TOKEN }} |
52 | 54 |
|
53 | 55 | - name: Build and push image |
| 56 | + id: build |
54 | 57 | uses: docker/build-push-action@v6 |
55 | 58 | with: |
56 | 59 | context: . |
57 | 60 | platforms: ${{ matrix.platform }} |
58 | 61 | push: true |
59 | 62 | tags: ${{ steps.vars.outputs.FULL_IMAGE }} |
| 63 | + cache-from: type=gha |
| 64 | + cache-to: type=gha,mode=max |
| 65 | + outputs: type=image,name=${{ steps.vars.outputs.FULL_IMAGE }},push-by-digest=true |
60 | 66 |
|
61 | | - - name: Output pushed image |
| 67 | + - name: Save digest as artifact |
62 | 68 | run: | |
63 | | - echo "Image pushed: ${{ steps.vars.outputs.FULL_IMAGE }}" |
| 69 | + mkdir -p digests |
| 70 | + echo "${{ steps.build.outputs.digest }}" > "digests/${{ matrix.platform }}.txt" |
| 71 | + shell: bash |
| 72 | + |
| 73 | + - name: Upload digest artifact |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: image-digest-${{ matrix.platform }} |
| 77 | + path: digests/${{ matrix.platform }}.txt |
| 78 | + |
| 79 | + create-manifest: |
| 80 | + runs-on: amd-runner-2204 |
| 81 | + needs: build |
| 82 | + steps: |
| 83 | + - name: Download all digests |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + path: digests |
| 87 | + pattern: image-digest-* |
| 88 | + merge-multiple: true |
| 89 | + |
| 90 | + - name: Set up Docker Buildx |
| 91 | + uses: docker/setup-buildx-action@v3 |
| 92 | + |
| 93 | + - name: Login to GitHub Container Registry |
| 94 | + uses: docker/login-action@v3 |
| 95 | + with: |
| 96 | + registry: ${{ env.REGISTRY }} |
| 97 | + username: ${{ github.actor }} |
| 98 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 99 | + |
| 100 | + - name: Create and push multi-platform manifest |
| 101 | + run: | |
| 102 | + FULL_IMAGE="${{ needs.build.outputs.full_image }}" |
| 103 | + CREATE_ARGS="" |
| 104 | + for digest_file in digests/*.txt; do |
| 105 | + digest=$(cat "$digest_file") |
| 106 | + CREATE_ARGS="$CREATE_ARGS ${FULL_IMAGE}@${digest}" |
| 107 | + done |
| 108 | + docker buildx imagetools create -t $FULL_IMAGE $CREATE_ARGS |
| 109 | +
|
| 110 | + - name: Inspect final image |
| 111 | + run: | |
| 112 | + docker buildx imagetools inspect ${{ needs.build.outputs.full_image }} |
0 commit comments