Create build with multi arch splitted (get rid of emulation) #604
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: Auto test and build v5 | |
| on: | |
| pull_request: | |
| branches: | |
| - 'v5' | |
| push: | |
| branches: | |
| - 'v5' | |
| - 'feat/split-multi-arch-build' # FIXME test | |
| schedule: | |
| - cron: '42 3 * * 0' | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # php_version: ['8.5', '8.4', '8.3','8.2','8.1'] | |
| php_version: ['8.5'] | |
| variant: ['apache','cli','fpm'] | |
| builder: [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}] | |
| runs-on: ${{ matrix.builder.os }} | |
| name: Build&test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker | |
| uses: docker-practice/actions-setup-docker@master | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build | |
| run: | | |
| PHP_VERSION="${{ matrix.php_version }}" | |
| # Get last cached successful builds | |
| TAGS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="" docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --progress=quiet --print | jq -r '.target[].tags[]') | |
| for TAG in $TAGS; do | |
| docker pull --quiet ${TAG} || echo "" | |
| done; | |
| # Build the current builds | |
| REPO="ghcr.io/${{ github.repository_owner }}/php" \ | |
| ARCH_SUFFIX="-${{ matrix.builder.arch }}" \ | |
| TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
| docker buildx bake \ | |
| --set "*.platform=linux/${{ matrix.builder.arch }}" \ | |
| --set "*.output=type=docker" \ | |
| --load --progress=quiet \ | |
| php${PHP_VERSION//.}-${{ matrix.variant }}-all | |
| - name: Display tags built | |
| run: | | |
| docker image ls --filter="reference=ghcr.io/${{ github.repository_owner }}/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" | |
| - name: Test | |
| run: | | |
| REPO="ghcr.io/${{ github.repository_owner }}/php" \ | |
| TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
| PHP_VERSION="${{ matrix.php_version }}" \ | |
| ARCH_SUFFIX="-${{ matrix.builder.arch }}" \ | |
| BRANCH="v5" \ | |
| VARIANT="${{ matrix.variant }}" \ | |
| PLATFORM="linux/${{ matrix.builder.arch }}" \ | |
| ./tests-suite/bash_unit -f tap ./tests-suite/*.sh | |
| - name: Publish specific arch version | |
| if: > # Only from the main repo | |
| github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || | |
| (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) | |
| run: | | |
| PHP_VERSION="${{ matrix.php_version }}" | |
| TAGS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" \ | |
| ARCH_SUFFIX="-${{ matrix.builder.arch }}" \ | |
| TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
| docker buildx bake \ | |
| --print --progress=quiet \ | |
| php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq -r '.target[].tags[]'); | |
| for TAG in $TAGS; do docker push --quiet ${TAG}; done; | |
| merge-and-publish: | |
| if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} | |
| needs: | |
| - build | |
| runs-on: ubuntu-latest | |
| name: Merge and publish ${{ matrix.php_version }}-${{ matrix.variant }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| # php_version: ['8.5', '8.4', '8.3','8.2','8.1'] | |
| php_version: ['8.5'] | |
| variant: ['apache','cli','fpm'] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| if: ${{ github.repository_owner == 'thecodingmachine' }} | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Install regctl | |
| uses: regclient/actions/regctl-installer@main | |
| with: | |
| release: 'v0.8.1' | |
| - name: Fetch minor version of php | |
| run: | | |
| # Pull amd64 slim image to get PHP version | |
| docker pull --quiet ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64 | |
| # Retrieve minor | |
| PHP_PATCH_MINOR=`docker run --rm ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64 php -v | head -n1 | grep -P '\d+\.\d+\.\d+' -o | head -n1` | |
| echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" | |
| echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV | |
| - name: Get list of images for this variant | |
| id: get-images | |
| run: | | |
| PHP_VERSION="${{ matrix.php_version }}" | |
| REPO="ghcr.io/${{ github.repository_owner }}/php" \ | |
| TAG_PREFIX="rc${GITHUB_RUN_ID}-" \ | |
| docker buildx bake \ | |
| --print --progress=quiet \ | |
| php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq '.target[].tags[]' | |
| - name: Create multiarch manifests | |
| run: | | |
| PHP_VERSION="${{ matrix.php_version }}" | |
| # Get all targets from the bake group | |
| TARGETS=$(docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --progress=quiet --print | jq -r ".group[\"php${PHP_VERSION//.}-${{ matrix.variant }}-all\"].targets[]") | |
| for TARGET in $TARGETS; do | |
| TAG_ORI=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="rc${GITHUB_RUN_ID}-" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]") | |
| TAG_PATH=$(REPO="php" PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]") | |
| TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]") | |
| # Create manifest for rc tag (always) | |
| echo "Creating manifest: ${TARGET} - ${TAG_ORI}" | |
| docker buildx imagetools create --progress=plain -t "${TAG_ORI}" "${TAG_ORI}-amd64" "${TAG_ORI}-arm64" | |
| # Create manifest for PHP_PATCH | |
| regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_PATH}" | |
| # Create manifest for PHP_MINOR | |
| regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_MINOR}" | |
| # SAME FOR DOCKERHUB (for the official repository) | |
| if [ "${{ github.repository_owner }}" == "thecodingmachine" ]; then | |
| # Create manifest for PHP_PATCH_MINOR | |
| regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_PATH}" | |
| # Create manifest for PHP_VERSION | |
| regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_MINOR}" | |
| fi | |
| done |