|
| 1 | +name: Publish Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + tags: |
| 8 | + - "*" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: docker-publish-${{ github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + resolve: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + should_publish: ${{ steps.publish.outputs.should_publish }} |
| 20 | + image_tag: ${{ steps.publish.outputs.image_tag }} |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Resolve publish tag |
| 28 | + id: publish |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | +
|
| 33 | + should_publish=false |
| 34 | + image_tag="" |
| 35 | +
|
| 36 | + if [[ "${GITHUB_REF_TYPE}" == "branch" && "${GITHUB_REF_NAME}" == "master" ]]; then |
| 37 | + should_publish=true |
| 38 | + image_tag="latest" |
| 39 | + elif [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then |
| 40 | + git fetch --no-tags origin master |
| 41 | + if git merge-base --is-ancestor "${GITHUB_SHA}" "origin/master"; then |
| 42 | + should_publish=true |
| 43 | + image_tag="${GITHUB_REF_NAME}" |
| 44 | + fi |
| 45 | + fi |
| 46 | +
|
| 47 | + echo "should_publish=${should_publish}" >> "${GITHUB_OUTPUT}" |
| 48 | + echo "image_tag=${image_tag}" >> "${GITHUB_OUTPUT}" |
| 49 | +
|
| 50 | + build: |
| 51 | + needs: resolve |
| 52 | + if: needs.resolve.outputs.should_publish == 'true' |
| 53 | + strategy: |
| 54 | + fail-fast: false |
| 55 | + matrix: |
| 56 | + include: |
| 57 | + - arch: amd64 |
| 58 | + platform: linux/amd64 |
| 59 | + runner: ubuntu-latest |
| 60 | + - arch: arm64 |
| 61 | + platform: linux/arm64 |
| 62 | + runner: ubuntu-24.04-arm |
| 63 | + runs-on: ${{ matrix.runner }} |
| 64 | + permissions: |
| 65 | + contents: read |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Set up Docker Buildx |
| 71 | + uses: docker/setup-buildx-action@v3 |
| 72 | + |
| 73 | + - name: Log in to Docker Hub |
| 74 | + uses: docker/login-action@v3 |
| 75 | + with: |
| 76 | + username: blockstream |
| 77 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 78 | + |
| 79 | + - name: Build and push ${{ matrix.arch }} |
| 80 | + uses: docker/build-push-action@v6 |
| 81 | + with: |
| 82 | + context: . |
| 83 | + file: ./Dockerfile |
| 84 | + platforms: ${{ matrix.platform }} |
| 85 | + push: true |
| 86 | + tags: blockstream/waterfalls:${{ needs.resolve.outputs.image_tag }}-${{ matrix.arch }} |
| 87 | + cache-from: type=gha,scope=waterfalls-${{ matrix.arch }} |
| 88 | + cache-to: type=gha,mode=max,scope=waterfalls-${{ matrix.arch }} |
| 89 | + |
| 90 | + manifest: |
| 91 | + needs: |
| 92 | + - resolve |
| 93 | + - build |
| 94 | + if: needs.resolve.outputs.should_publish == 'true' |
| 95 | + runs-on: ubuntu-latest |
| 96 | + permissions: |
| 97 | + contents: read |
| 98 | + steps: |
| 99 | + - name: Set up Docker Buildx |
| 100 | + uses: docker/setup-buildx-action@v3 |
| 101 | + |
| 102 | + - name: Log in to Docker Hub |
| 103 | + uses: docker/login-action@v3 |
| 104 | + with: |
| 105 | + username: blockstream |
| 106 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 107 | + |
| 108 | + - name: Create multi-arch manifest |
| 109 | + shell: bash |
| 110 | + run: | |
| 111 | + set -euo pipefail |
| 112 | + docker buildx imagetools create \ |
| 113 | + -t blockstream/waterfalls:${{ needs.resolve.outputs.image_tag }} \ |
| 114 | + blockstream/waterfalls:${{ needs.resolve.outputs.image_tag }}-amd64 \ |
| 115 | + blockstream/waterfalls:${{ needs.resolve.outputs.image_tag }}-arm64 |
| 116 | +
|
| 117 | + - name: Inspect manifest |
| 118 | + run: docker buildx imagetools inspect blockstream/waterfalls:${{ needs.resolve.outputs.image_tag }} |
0 commit comments