chore: refactor Docker build workflow for multi-platform support and … #12
Workflow file for this run
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: Build and publish Docker images for Energy Tracker | |
| on: | |
| push: | |
| branches: [ "staging", "main" ] | |
| pull_request: | |
| branches: [ "staging", "main" ] | |
| env: | |
| REGISTRY: ghcr.io | |
| jobs: | |
| build-platform: | |
| strategy: | |
| matrix: | |
| include: | |
| - platform: linux/amd64 | |
| runner: ubuntu-latest | |
| arch: amd64 | |
| - platform: linux/arm64 | |
| runner: ubuntu-24.04-arm | |
| arch: arm64 | |
| runs-on: ${{ matrix.runner }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Normalize image names | |
| run: | | |
| echo "PROVER_IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| echo "STREAMR_IMAGE_NAME=${GITHUB_REPOSITORY,,}/streamr-client" >> $GITHUB_ENV | |
| - name: Free disk space | |
| uses: jlumbroso/free-disk-space@main | |
| with: | |
| tool-cache: true | |
| android: true | |
| dotnet: true | |
| haskell: true | |
| large-packages: true | |
| docker-images: true | |
| swap-storage: true | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # ---------- Prover image ---------- | |
| - name: Extract metadata for Prover image | |
| id: meta-prover | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }} | |
| - name: Build Prover image (single platform) | |
| id: build-prover | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta-prover.outputs.tags }} | |
| labels: ${{ steps.meta-prover.outputs.labels }} | |
| outputs: type=image,push-by-digest=true,name-canonical=true | |
| cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}:buildcache-${{ matrix.arch }} | |
| cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max | |
| - name: Record Prover digest | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| echo "${{ matrix.arch }}=${{ steps.build-prover.outputs.digest }}" >> prover-digests.txt | |
| # ---------- Streamr client image ---------- | |
| - name: Extract metadata for Streamr client image | |
| id: meta-streamr | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }} | |
| - name: Build Streamr client image (single platform) | |
| id: build-streamr | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./streamr-client | |
| platforms: ${{ matrix.platform }} | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta-streamr.outputs.tags }} | |
| labels: ${{ steps.meta-streamr.outputs.labels }} | |
| outputs: type=image,push-by-digest=true,name-canonical=true | |
| cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}:buildcache-${{ matrix.arch }} | |
| cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max | |
| - name: Record Streamr digest | |
| if: github.event_name != 'pull_request' | |
| run: | | |
| echo "${{ matrix.arch }}=${{ steps.build-streamr.outputs.digest }}" >> streamr-digests.txt | |
| - name: Upload digests | |
| if: github.event_name != 'pull_request' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: digests-${{ matrix.arch }} | |
| path: | | |
| prover-digests.txt | |
| streamr-digests.txt | |
| create-manifests: | |
| needs: build-platform | |
| if: github.event_name != 'pull_request' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Normalize image names | |
| run: | | |
| echo "PROVER_IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV | |
| echo "STREAMR_IMAGE_NAME=${GITHUB_REPOSITORY,,}/streamr-client" >> $GITHUB_ENV | |
| - name: Download digests | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: digests | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Extract metadata for Prover image | |
| id: meta-prover | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }} | |
| - name: Create and push Prover multi-arch manifest | |
| run: | | |
| docker buildx imagetools create \ | |
| $(printf -- '--tag %s ' ${{ steps.meta-prover.outputs.tags }}) \ | |
| ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}@$(grep amd64 digests/**/prover-digests.txt | cut -d= -f2) \ | |
| ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}@$(grep arm64 digests/**/prover-digests.txt | cut -d= -f2) | |
| - name: Extract metadata for Streamr client image | |
| id: meta-streamr | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }} | |
| - name: Create and push Streamr multi-arch manifest | |
| run: | | |
| docker buildx imagetools create \ | |
| $(printf -- '--tag %s ' ${{ steps.meta-streamr.outputs.tags }}) \ | |
| ${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}@$(grep amd64 digests/**/streamr-digests.txt | cut -d= -f2) \ | |
| ${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}@$(grep arm64 digests/**/streamr-digests.txt | cut -d= -f2) |