|
15 | 15 | app-version: |
16 | 16 | value: ${{ jobs.build.outputs.app-version }} |
17 | 17 |
|
| 18 | +env: |
| 19 | + DOCKERHUB_REPO: capcom6/${{ inputs.app-name }} |
| 20 | + GHCR_REPO: ghcr.io/${{ github.repository }} |
| 21 | + |
18 | 22 | jobs: |
19 | 23 | build: |
20 | 24 | name: Docker image |
21 | 25 | runs-on: ubuntu-latest |
22 | | - if: github.actor != 'dependabot[bot]' # skip on dependabot because it's not allowed to access secrets |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + platform: |
| 30 | + - linux/amd64 |
| 31 | + - linux/arm64 |
23 | 32 | permissions: |
24 | 33 | packages: write |
25 | 34 | outputs: |
26 | 35 | app-version: ${{ steps.meta.outputs.version }} |
| 36 | + |
27 | 37 | steps: |
28 | | - - name: Checkout repository |
29 | | - uses: actions/checkout@v4 |
| 38 | + - name: Prepare |
| 39 | + run: | |
| 40 | + platform=${{ matrix.platform }} |
| 41 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
30 | 42 |
|
31 | 43 | - name: Docker meta |
32 | 44 | id: meta |
33 | 45 | uses: docker/metadata-action@v5 |
34 | 46 | with: |
35 | 47 | images: | |
36 | | - capcom6/${{ inputs.app-name }} |
37 | | - ghcr.io/${{ github.repository }} |
38 | | - tags: | |
39 | | - type=ref,event=branch |
40 | | - type=ref,event=pr |
41 | | - type=semver,pattern={{version}} |
42 | | - type=semver,pattern={{major}}.{{minor}} |
43 | | - type=semver,pattern={{major}} |
| 48 | + ${{ env.DOCKERHUB_REPO }} |
| 49 | + ${{ env.GHCR_REPO }} |
44 | 50 |
|
45 | 51 | - name: Log into Docker Hub |
46 | 52 | uses: docker/login-action@v3 |
| 53 | + if: github.actor != 'dependabot[bot]' |
47 | 54 | with: |
48 | 55 | username: ${{ secrets.username }} |
49 | 56 | password: ${{ secrets.password }} |
50 | 57 |
|
51 | 58 | - name: Login to Container registry |
52 | 59 | uses: docker/login-action@v3 |
| 60 | + if: github.actor != 'dependabot[bot]' |
53 | 61 | with: |
54 | 62 | registry: ghcr.io |
55 | | - username: ${{ github.actor }} |
| 63 | + username: ${{ github.repository_owner }} |
56 | 64 | password: ${{ secrets.GITHUB_TOKEN }} |
57 | 65 |
|
58 | 66 | - name: Set APP_VERSION env |
59 | 67 | run: echo APP_VERSION=$(echo ${GITHUB_REF} | rev | cut -d'/' -f 1 | rev ) >> ${GITHUB_ENV} |
60 | 68 | - name: Set APP_RELEASE env |
61 | 69 | run: echo APP_RELEASE=$(( ($(date +%s) - $(date -d "2022-06-15" +%s)) / 86400 )) >> ${GITHUB_ENV} |
62 | 70 |
|
| 71 | + - name: Set up QEMU |
| 72 | + uses: docker/setup-qemu-action@v3 |
| 73 | + |
| 74 | + - name: Set up Docker Buildx |
| 75 | + uses: docker/setup-buildx-action@v3 |
| 76 | + |
63 | 77 | - name: Build and push Docker image |
64 | | - uses: docker/build-push-action@v5 |
| 78 | + id: build |
| 79 | + uses: docker/build-push-action@v6 |
65 | 80 | with: |
66 | 81 | file: build/package/Dockerfile |
| 82 | + platforms: ${{ matrix.platform }} |
67 | 83 | build-args: | |
68 | 84 | APP=${{ inputs.app-name }} |
69 | 85 | APP_VERSION=${{ env.APP_VERSION }} |
70 | 86 | APP_RELEASE_ID=${{ env.APP_RELEASE }} |
71 | | - push: true |
72 | | - tags: ${{ steps.meta.outputs.tags }} |
| 87 | + push: ${{ github.actor != 'dependabot[bot]' }} |
73 | 88 | labels: ${{ steps.meta.outputs.labels }} |
74 | | - # cache-from: type=gha |
75 | | - # cache-to: type=gha,mode=max |
| 89 | + outputs: type=image,"name=${{ env.DOCKERHUB_REPO }},${{ env.GHCR_REPO }}",push-by-digest=true,name-canonical=true,push=true |
| 90 | + |
| 91 | + - name: Export digest |
| 92 | + run: | |
| 93 | + mkdir -p ${{ runner.temp }}/digests |
| 94 | + digest="${{ steps.build.outputs.digest }}" |
| 95 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 96 | +
|
| 97 | + - name: Upload digest |
| 98 | + uses: actions/upload-artifact@v4 |
| 99 | + with: |
| 100 | + name: digests-${{ env.PLATFORM_PAIR }} |
| 101 | + path: ${{ runner.temp }}/digests/* |
| 102 | + if-no-files-found: error |
| 103 | + retention-days: 1 |
| 104 | + |
| 105 | + merge: |
| 106 | + runs-on: ubuntu-latest |
| 107 | + needs: |
| 108 | + - build |
| 109 | + steps: |
| 110 | + - name: Download digests |
| 111 | + uses: actions/download-artifact@v4 |
| 112 | + with: |
| 113 | + path: ${{ runner.temp }}/digests |
| 114 | + pattern: digests-* |
| 115 | + merge-multiple: true |
| 116 | + |
| 117 | + - name: Log into Docker Hub |
| 118 | + uses: docker/login-action@v3 |
| 119 | + if: github.actor != 'dependabot[bot]' |
| 120 | + with: |
| 121 | + username: ${{ secrets.username }} |
| 122 | + password: ${{ secrets.password }} |
| 123 | + |
| 124 | + - name: Login to Container registry |
| 125 | + uses: docker/login-action@v3 |
| 126 | + if: github.actor != 'dependabot[bot]' |
| 127 | + with: |
| 128 | + registry: ghcr.io |
| 129 | + username: ${{ github.repository_owner }} |
| 130 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + |
| 132 | + - name: Set up Docker Buildx |
| 133 | + uses: docker/setup-buildx-action@v3 |
| 134 | + |
| 135 | + - name: Docker meta |
| 136 | + id: meta |
| 137 | + uses: docker/metadata-action@v5 |
| 138 | + with: |
| 139 | + images: | |
| 140 | + ${{ env.DOCKERHUB_REPO }} |
| 141 | + ${{ env.GHCR_REPO }} |
| 142 | + tags: | |
| 143 | + type=ref,event=branch |
| 144 | + type=ref,event=pr |
| 145 | + type=semver,pattern={{version}} |
| 146 | + type=semver,pattern={{major}}.{{minor}} |
| 147 | + type=semver,pattern={{major}} |
| 148 | +
|
| 149 | + - name: Create manifest list and push |
| 150 | + working-directory: ${{ runner.temp }}/digests |
| 151 | + run: | |
| 152 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 153 | + $(printf '${{ env.DOCKERHUB_REPO }}@sha256:%s ' *) |
| 154 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 155 | + $(printf '${{ env.GHCR_REPO }}@sha256:%s ' *) |
| 156 | +
|
| 157 | + - name: Inspect image |
| 158 | + run: | |
| 159 | + docker buildx imagetools inspect ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.version }} |
| 160 | + docker buildx imagetools inspect ${{ env.GHCR_REPO }}:${{ steps.meta.outputs.version }} |
0 commit comments