docker #81
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: docker | |
| on: | |
| workflow_run: | |
| workflows: [build-app] | |
| types: [completed] | |
| jobs: | |
| build: | |
| if: >- | |
| github.event.workflow_run.conclusion == 'success' && | |
| (github.event.workflow_run.head_branch == 'master' || | |
| startsWith(github.event.workflow_run.head_branch, 'v')) | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| runner: ubuntu-latest | |
| artifact: linux-amd64 | |
| - platform: linux/arm64 | |
| runner: ubuntu-24.04-arm | |
| artifact: linux-arm64 | |
| permissions: | |
| contents: read | |
| packages: write | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| persist-credentials: false | |
| - name: set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: login to ghcr.io | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: build and push to ghcr.io | |
| id: build-ghcr | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform }} | |
| build-args: | | |
| CI=github | |
| GITHUB_SHA=${{ github.event.workflow_run.head_sha }} | |
| GIT_BRANCH=${{ github.event.workflow_run.head_branch }} | |
| outputs: type=image,name=ghcr.io/${{ github.repository_owner }}/tg-spam,push-by-digest=true,name-canonical=true,push=true | |
| - name: export digest | |
| run: | | |
| mkdir -p /tmp/digests/ghcr | |
| digest_ghcr="${{ steps.build-ghcr.outputs.digest }}" | |
| touch "/tmp/digests/ghcr/${digest_ghcr#sha256:}" | |
| - name: upload ghcr digest | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: digests-ghcr-${{ matrix.artifact }} | |
| path: /tmp/digests/ghcr/* | |
| retention-days: 1 | |
| merge: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: download ghcr digests | |
| uses: actions/download-artifact@v8 | |
| with: | |
| path: /tmp/digests/ghcr | |
| pattern: digests-ghcr-* | |
| merge-multiple: true | |
| - name: verify all digests present | |
| run: | | |
| expected=2 | |
| actual=$(find /tmp/digests/ghcr -maxdepth 1 -type f | wc -l) | |
| if [ "$actual" -ne "$expected" ]; then | |
| echo "Expected $expected digests for ghcr, found $actual" | |
| ls -la /tmp/digests/ghcr | |
| exit 1 | |
| fi | |
| echo "All $expected digests present for ghcr" | |
| - name: set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: login to ghcr.io | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: set docker tags | |
| id: tags | |
| env: | |
| HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} | |
| run: | | |
| if [[ "$HEAD_BRANCH" == v* ]]; then | |
| echo "tag=${HEAD_BRANCH}" >> $GITHUB_OUTPUT | |
| echo "is_release=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "tag=${HEAD_BRANCH}" >> $GITHUB_OUTPUT | |
| echo "is_release=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: create ghcr manifest and push | |
| working-directory: /tmp/digests/ghcr | |
| run: | | |
| tags="-t ghcr.io/${{ github.repository_owner }}/tg-spam:${{ steps.tags.outputs.tag }}" | |
| if [[ "${{ steps.tags.outputs.is_release }}" == "true" ]]; then | |
| tags="$tags -t ghcr.io/${{ github.repository_owner }}/tg-spam:latest" | |
| fi | |
| docker buildx imagetools create $tags \ | |
| $(printf 'ghcr.io/${{ github.repository_owner }}/tg-spam@sha256:%s ' *) |