|
5 | 5 | release: |
6 | 6 | types: [published] |
7 | 7 | pull_request: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - development |
| 11 | + |
| 12 | +env: |
| 13 | + REGISTRY_IMAGE: ghcr.io/${{ github.repository }} |
8 | 14 |
|
9 | 15 | jobs: |
10 | | - build-and-push: |
| 16 | + build: |
11 | 17 | runs-on: ubuntu-latest |
12 | 18 | permissions: |
13 | 19 | contents: read |
14 | 20 | packages: write |
| 21 | + strategy: |
| 22 | + fail-fast: true |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - platform: linux/amd64 |
| 26 | + - platform: linux/arm64 |
| 27 | + - platform: linux/arm/v6 |
| 28 | + - platform: linux/arm/v7 |
| 29 | + - platform: linux/386 |
15 | 30 | steps: |
| 31 | + - name: Prepare name for digest up/download |
| 32 | + run: | |
| 33 | + platform=${{ matrix.platform }} |
| 34 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 35 | +
|
16 | 36 | - name: Checkout Code |
17 | | - uses: actions/checkout@v3.6.0 |
| 37 | + uses: actions/checkout@v4.1.1 |
18 | 38 |
|
19 | 39 | - name: Set up QEMU |
20 | | - uses: docker/setup-qemu-action@v2.2.0 |
| 40 | + uses: docker/setup-qemu-action@v3.0.0 |
21 | 41 |
|
22 | 42 | - name: Set up Docker Buildx |
23 | | - |
| 43 | + |
| 44 | + with: |
| 45 | + buildkitd-flags: --debug |
24 | 46 |
|
25 | 47 | - name: Extract metadata (tags, labels) for Docker |
26 | 48 | id: meta |
27 | | - uses: docker/metadata-action@v4 |
| 49 | + uses: docker/metadata-action@v5 |
28 | 50 | with: |
29 | 51 | images: | |
30 | | - ghcr.io/${{ github.repository_owner }}/${{ github.repository }} |
31 | | - flavor: latest=${{ startsWith(github.ref, 'refs/tags/') }} |
32 | | - tags: | |
33 | | - type=semver,pattern={{version}} |
34 | | - type=semver,pattern={{major}}.{{minor}} |
35 | | - type=semver,pattern={{major}} |
36 | | - type=sha, enable=${{ !startsWith(github.ref, 'refs/tags/') }} |
37 | | - type=edge |
38 | | -
|
| 52 | + ${{ env.REGISTRY_IMAGE }} |
39 | 53 | - name: Login to GitHub Container Registry |
40 | | - if: github.event_name != 'pull_request' |
41 | | - |
| 54 | + |
42 | 55 | with: |
43 | 56 | registry: ghcr.io |
44 | 57 | username: ${{ github.repository_owner }} |
45 | 58 | password: ${{ secrets.GITHUB_TOKEN }} |
46 | 59 |
|
47 | 60 | - name: Build and push Docker image |
48 | | - |
| 61 | + |
| 62 | + id: build |
49 | 63 | with: |
50 | 64 | context: . |
51 | 65 | file: ./Dockerfile |
52 | | - platforms: linux/amd64, linux/arm64, linux/386, linux/arm/v7, linux/arm/v6 |
53 | | - push: ${{ github.event_name != 'pull_request' }} |
54 | | - cache-from: type=gha |
55 | | - cache-to: type=gha |
56 | | - provenance: false |
57 | | - tags: ${{ steps.meta.outputs.tags }} |
| 66 | + platforms: ${{ matrix.platform }} |
58 | 67 | labels: ${{ steps.meta.outputs.labels }} |
| 68 | + provenance: false |
| 69 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=${{ github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' || github.event_name == 'release' }} |
| 70 | + - name: Export digest |
| 71 | + run: | |
| 72 | + mkdir -p /tmp/digests |
| 73 | + digest="${{ steps.build.outputs.digest }}" |
| 74 | + touch "/tmp/digests/${digest#sha256:}" |
| 75 | + - name: Upload digest |
| 76 | + |
| 77 | + with: |
| 78 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 79 | + path: /tmp/digests/* |
| 80 | + if-no-files-found: error |
| 81 | + retention-days: 1 |
| 82 | + |
| 83 | + merge: |
| 84 | + runs-on: ubuntu-latest |
| 85 | + needs: |
| 86 | + - build |
| 87 | + if: | |
| 88 | + github.actor != 'dependabot[bot]' |
| 89 | + && ( github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' || github.event_name == 'release' ) |
| 90 | + permissions: |
| 91 | + contents: read |
| 92 | + packages: write |
| 93 | + steps: |
| 94 | + - name: Download digests |
| 95 | + |
| 96 | + with: |
| 97 | + path: /tmp/digests |
| 98 | + pattern: digests-* |
| 99 | + merge-multiple: true |
| 100 | + |
| 101 | + - name: Set up Docker Buildx |
| 102 | + |
| 103 | + - name: Docker meta |
| 104 | + id: meta |
| 105 | + uses: docker/metadata-action@v5 |
| 106 | + with: |
| 107 | + images: | |
| 108 | + ${{ env.REGISTRY_IMAGE }} |
| 109 | + flavor: latest=${{ startsWith(github.ref, 'refs/tags/') }} |
| 110 | + tags: | |
| 111 | + type=semver,pattern={{version}} |
| 112 | + type=semver,pattern={{major}}.{{minor}} |
| 113 | + type=semver,pattern={{major}} |
| 114 | + type=sha,enable=${{ github.event_name == 'workflow_dispatch' }} |
| 115 | + type=ref,event=pr |
| 116 | + type=ref,event=branch |
| 117 | + - name: Login to GitHub Container Registry |
| 118 | + |
| 119 | + with: |
| 120 | + registry: ghcr.io |
| 121 | + username: ${{ github.repository_owner }} |
| 122 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 123 | + - name: Create manifest list and push |
| 124 | + working-directory: /tmp/digests |
| 125 | + run: | |
| 126 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 127 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 128 | + - name: Inspect image |
| 129 | + run: | |
| 130 | + docker buildx imagetools inspect --raw ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
| 131 | +
|
| 132 | +
|
0 commit comments