Skip to content

Create build with multi arch splitted (get rid of emulation) #594

Create build with multi arch splitted (get rid of emulation)

Create build with multi arch splitted (get rid of emulation) #594

Workflow file for this run

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']
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 ${{ 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

Check failure on line 37 in .github/workflows/workflow.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/workflow.yml

Invalid workflow file

You have an error in your yaml syntax on line 37
- name: Build
run: |
if: >
github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
PHP_VERSION="${{ matrix.php_version }}"
# Get last cached successful builds
TARGETS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="" docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print | jq -r '.target[].tags[]')
for TARGET in $TARGETS; do
docker --quiet pull ${TARGET} || 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 \
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: |
TAGS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" \
ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
docker buildx bake \
--print \
php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq -r '.target[].tags[]');
for TAG in $TAGS; do docker pull --quiet ${TAG}; done;
merge-and-publish:
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
needs:
- test
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']
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 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}" >> $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 \
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 --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} --print | jq -r '.target[].tags[]')
TAG_PATH=$(REPO="php" PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
echo "Processing target: $TARGET"
# Extract the tag suffix from generated tag (e.g., php:8.5-v5-slim-apache -> v5-slim-apache)
TAG_SUFFIX=$(echo $TARGET | sed "s/^.*${PHP_VERSION}-v5-/v5-/")
# Create manifest for rc tag (always)
echo "Creating manifest: ${TARGET}"
docker buildx imagetools create -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