From 5fbd528ed2616b462996f6be96282a4fb3939f19 Mon Sep 17 00:00:00 2001 From: nfebe Date: Fri, 27 Mar 2026 17:25:34 +0100 Subject: [PATCH] fix(ci): Add multi-platform build for arm64 support Build workflow now uses per-platform runners (ubuntu-latest for amd64, ubuntu-24.04-arm for arm64) with digest-based push and manifest merge, matching the laravel-docker-dev approach. The tag-latest job now uses imagetools to preserve both platforms. Signed-off-by: nfebe --- .github/workflows/build.yml | 119 ++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0d9e7b..24df96a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,12 +10,26 @@ on: branches: - main +env: + REGISTRY: ghcr.io + IMAGE_NAME: whilesmartphp/frankenphp + jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.runner }} + permissions: + contents: read + packages: write + strategy: matrix: php: ['8.2', '8.3', '8.4'] + platform: ['linux/amd64', 'linux/arm64'] + include: + - platform: linux/amd64 + runner: ubuntu-latest + - platform: linux/arm64 + runner: ubuntu-24.04-arm steps: - name: Checkout code @@ -25,38 +39,109 @@ jobs: 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: ghcr.io - username: ${{ github.repository_owner }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v5 + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6 with: context: . + platforms: ${{ matrix.platform }} build-args: PHP_VERSION=${{ matrix.php }} - push: ${{ github.event_name != 'pull_request' }} - tags: ghcr.io/whilesmartphp/frankenphp:${{ matrix.php }} - cache-from: type=gha,scope=php${{ matrix.php }} - cache-to: type=gha,mode=max,scope=php${{ matrix.php }} + cache-from: type=gha,scope=php${{ matrix.php }}-${{ matrix.platform }} + cache-to: type=gha,mode=max,scope=php${{ matrix.php }}-${{ matrix.platform }} + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }} - tag-latest: + - name: Export digest + if: github.event_name != 'pull_request' + run: | + mkdir -p /tmp/digests/${{ matrix.php }} + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${{ matrix.php }}/${digest#sha256:}" + + - name: Upload digest + if: github.event_name != 'pull_request' + uses: actions/upload-artifact@v4 + with: + name: digest-${{ matrix.php }}-${{ matrix.runner }} + path: /tmp/digests/${{ matrix.php }} + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' needs: build + permissions: + contents: read + packages: write + + strategy: + matrix: + php: ['8.2', '8.3', '8.4'] + + steps: + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Download digests + uses: actions/download-artifact@v4 + with: + pattern: digest-${{ matrix.php }}-* + merge-multiple: true + path: /tmp/digests + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ matrix.php }} + type=raw,value=${{ matrix.php }}-{{sha}} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php }} + + tag-latest: + needs: merge runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' + permissions: + contents: read + packages: write steps: - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: - registry: ghcr.io - username: ${{ github.repository_owner }} + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Tag latest + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Tag 8.4 as latest run: | - docker pull ghcr.io/whilesmartphp/frankenphp:8.4 - docker tag ghcr.io/whilesmartphp/frankenphp:8.4 ghcr.io/whilesmartphp/frankenphp:latest - docker push ghcr.io/whilesmartphp/frankenphp:latest + docker buildx imagetools create \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:8.4