|
| 1 | +name: Heartbeats Processor Docker Build |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + version: |
| 6 | + description: 'Version tag for the image' |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +env: |
| 11 | + REGISTRY_IMAGE: openmina/heartbeats-processor |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-heartbeat-processor-image: |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + arch: |
| 18 | + - platform: linux/amd64 |
| 19 | + runs-on: ubuntu-latest |
| 20 | + - platform: linux/arm64 |
| 21 | + runs-on: ubuntu-arm64 |
| 22 | + runs-on: ${{ matrix.arch.runs-on }} |
| 23 | + steps: |
| 24 | + - name: Prepare |
| 25 | + run: | |
| 26 | + platform=${{ matrix.arch.platform }} |
| 27 | + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV |
| 28 | +
|
| 29 | + - name: Git checkout |
| 30 | + uses: actions/checkout@v3 |
| 31 | + |
| 32 | + - name: Login to Docker Hub |
| 33 | + uses: docker/login-action@v3 |
| 34 | + with: |
| 35 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 36 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 37 | + |
| 38 | + - name: Set up Docker Buildx |
| 39 | + uses: docker/setup-buildx-action@v3 |
| 40 | + |
| 41 | + - name: Build and push by digest |
| 42 | + id: build |
| 43 | + uses: docker/build-push-action@v6 |
| 44 | + with: |
| 45 | + context: . |
| 46 | + file: ./tools/heartbeats-processor/Dockerfile |
| 47 | + platforms: ${{ matrix.arch.platform }} |
| 48 | + cache-from: type=gha |
| 49 | + cache-to: type=gha,mode=max |
| 50 | + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true |
| 51 | + |
| 52 | + - name: Export digest |
| 53 | + run: | |
| 54 | + mkdir -p /tmp/digests |
| 55 | + digest="${{ steps.build.outputs.digest }}" |
| 56 | + touch "/tmp/digests/${digest#sha256:}" |
| 57 | +
|
| 58 | + - name: Upload digest |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + with: |
| 61 | + name: heartbeat-processor-digests-${{ env.PLATFORM_PAIR }} |
| 62 | + path: /tmp/digests/* |
| 63 | + if-no-files-found: error |
| 64 | + retention-days: 1 |
| 65 | + |
| 66 | + merge-heartbeat-processor-image: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + needs: |
| 69 | + - build-heartbeat-processor-image |
| 70 | + steps: |
| 71 | + - name: Download digests |
| 72 | + uses: actions/download-artifact@v4 |
| 73 | + with: |
| 74 | + path: /tmp/digests |
| 75 | + pattern: heartbeat-processor-digests-* |
| 76 | + merge-multiple: true |
| 77 | + |
| 78 | + - name: Set up Docker Buildx |
| 79 | + uses: docker/setup-buildx-action@v3 |
| 80 | + |
| 81 | + - name: Docker meta |
| 82 | + id: meta |
| 83 | + uses: docker/metadata-action@v5 |
| 84 | + with: |
| 85 | + images: ${{ env.REGISTRY_IMAGE }} |
| 86 | + tags: | |
| 87 | + type=sha,format=short |
| 88 | + type=raw,value=${{ inputs.version }},enable=${{ inputs.version != '' }} |
| 89 | + type=raw,value=v${{ inputs.version }},enable=${{ inputs.version != '' }} |
| 90 | +
|
| 91 | + - name: Login to Docker Hub |
| 92 | + uses: docker/login-action@v3 |
| 93 | + with: |
| 94 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 95 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 96 | + |
| 97 | + - name: Create manifest list and push |
| 98 | + working-directory: /tmp/digests |
| 99 | + run: | |
| 100 | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
| 101 | + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
| 102 | +
|
| 103 | + - name: Inspect image |
| 104 | + run: | |
| 105 | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments