77 push :
88 branches :
99 - ' v5'
10+ - ' feat/split-multi-arch-build' # FIXME test
1011 schedule :
1112 - cron : ' 42 3 * * 0'
1213 workflow_dispatch :
1314
1415jobs :
15- test :
16+ build :
1617 strategy :
1718 fail-fast : false
1819 matrix :
1920 php_version : ['8.5', '8.4', '8.3','8.2','8.1']
2021 variant : ['apache','cli','fpm']
21- # builder: [ {arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "macos-latest"}]
22- builder : [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04"}]
22+ builder : [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}]
2323 runs-on : ${{ matrix.builder.os }}
24- name : Test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} only
24+ name : Build ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }}
2525 steps :
2626 - name : Checkout
2727 uses : actions/checkout@v4
2828 - name : Set up Docker
29- # /!\ this action is marked as experimental
30- # It's required only for macos
31- if : ${{ matrix.builder.os == 'macos-latest' }}
3229 uses : docker-practice/actions-setup-docker@master
33- - name : Set up QEMU
34- uses : docker/setup-qemu-action@v3
30+ - name : Login to GHCR
31+ uses : docker/login-action@v3
32+ with :
33+ registry : ghcr.io
34+ username : ${{ github.actor }}
35+ password : ${{ secrets.GITHUB_TOKEN }}
3536 - name : Set up Docker Buildx
3637 uses : docker/setup-buildx-action@v3
3738 - name : Build
3839 run : |
3940 PHP_VERSION="${{ matrix.php_version }}"
41+ # Get last cached successful builds
42+ TARGETS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="" docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print | jq -r '.target[].tags[]')
43+ for TARGET in $TARGETS; do
44+ docker --quiet pull ${TARGET} || echo ""
45+ done;
46+ # Build the current builds
47+ REPO="ghcr.io/${{ github.repository_owner }}/php" \
48+ ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
4049 TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
4150 docker buildx bake \
4251 --set "*.platform=linux/${{ matrix.builder.arch }}" \
@@ -45,23 +54,36 @@ jobs:
4554 php${PHP_VERSION//.}-${{ matrix.variant }}-all
4655 - name : Display tags built
4756 run : |
48- docker image ls --filter="reference=thecodingmachine /php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}"
57+ docker image ls --filter="reference=ghcr.io/${{ github.repository_owner }} /php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}"
4958 - name : Test
5059 run : |
60+ REPO="ghcr.io/${{ github.repository_owner }}/php" \
5161 TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
5262 PHP_VERSION="${{ matrix.php_version }}" \
63+ ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
5364 BRANCH="v5" \
5465 VARIANT="${{ matrix.variant }}" \
5566 PLATFORM="linux/${{ matrix.builder.arch }}" \
5667 ./tests-suite/bash_unit -f tap ./tests-suite/*.sh
68+ - name : Publish specific arch version
69+ if : > # Only from the main repo
70+ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' ||
71+ (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
72+ run : |
73+ TAGS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" \
74+ ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
75+ TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
76+ docker buildx bake \
77+ --print \
78+ php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq -r '.target[].tags[]');
79+ for TAG in $TAGS; do docker pull --quiet ${TAG}; done;
5780
58- publish :
59- # push ~ schedule
81+ merge-and-publish :
6082 if : ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
6183 needs :
6284 - test
6385 runs-on : ubuntu-latest
64- name : Publish ${{ matrix.php_version }}-${{ matrix.variant }} multi-arch to dockerhub
86+ name : Merge and publish ${{ matrix.php_version }}-${{ matrix.variant }}
6587 strategy :
6688 fail-fast : false
6789 matrix :
@@ -70,49 +92,69 @@ jobs:
7092 steps :
7193 - name : Checkout
7294 uses : actions/checkout@v4
73- - name : Set up QEMU
74- uses : docker/setup-qemu-action@v3
7595 - name : Set up Docker Buildx
7696 uses : docker/setup-buildx-action@v3
97+ - name : Login to GHCR
98+ uses : docker/login-action@v3
99+ with :
100+ registry : ghcr.io
101+ username : ${{ github.actor }}
102+ password : ${{ secrets.GITHUB_TOKEN }}
77103 - name : Login to DockerHub
78104 uses : docker/login-action@v3
105+ if : ${{ github.repository_owner == 'thecodingmachine' }}
79106 with :
80107 username : ${{ secrets.DOCKERHUB_USERNAME }}
81108 password : ${{ secrets.DOCKERHUB_TOKEN }}
109+ - name : Install regctl
110+ uses : regclient/actions/regctl-installer@main
111+ with :
112+ release : ' v0.8.1'
82113 - name : Fetch minor version of php
83114 run : |
84- # Build slim one
85- PHP_VERSION="${{ matrix.php_version }}"
86- TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
87- docker buildx bake \
88- --set "*.platform=linux/amd64" \
89- --set "*.output=type=docker" \
90- --load \
91- php${PHP_VERSION//.}-slim-${{ matrix.variant }}
115+ # Pull amd64 slim image to get PHP version
116+ docker pull ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64
92117 # Retrieve minor
93- PHP_PATCH_MINOR=`docker run --rm thecodingmachine/ php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }} php -v | head -n1 | grep -P '\d+\.\d+\.\d+' -o | head -n1`
118+ 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`
94119 echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV
95- - name : Display tags to build
120+ - name : Get list of images for this variant
121+ id : get-images
96122 run : |
97123 PHP_VERSION="${{ matrix.php_version }}"
98- PHP_PATCH_MINOR=" ${{ env.PHP_PATCH_MINOR }}" \
124+ REPO="ghcr.io/ ${{ github.repository_owner }}/php " \
99125 TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
100- IS_RELEASE="1" \
101- docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all -- print --progress plain | jq ".target[].tags | join(\" \")" -r > "/tmp/tags.log"
102- cat "/tmp/tags.log"
103- - name : Build and push ${{ matrix.php_version }}-${{ matrix.variant }}
126+ docker buildx bake \
127+ -- print \
128+ php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq '.target[].tags[]'
129+ - name : Create multiarch manifests
104130 run : |
105131 PHP_VERSION="${{ matrix.php_version }}"
106- PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \
107- TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
108- IS_RELEASE="1" \
109- docker buildx bake \
110- --set "*.platform=linux/amd64,linux/arm64" \
111- --set "*.output=type=registry" \
112- php${PHP_VERSION//.}-${{ matrix.variant }}-all
113- - name : Push artifacts
114- uses : actions/upload-artifact@v4
115- with :
116- name : ${{ matrix.php_version }}-${{ matrix.variant }}
117- path : /tmp/tags.log
118- retention-days : 60
132+
133+ # Get all targets from the bake group
134+ TARGETS=$(docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print | jq -r '.group["php${PHP_VERSION//.}-${{ matrix.variant }}-all"].targets[]')
135+
136+ for TARGET in $TARGETS; do
137+ TAG_ORI=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="rc${GITHUB_RUN_ID}-" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
138+ TAG_PATH=$(REPO="php" PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
139+ TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
140+ echo "Processing target: $TARGET"
141+ # Extract the tag suffix from generated tag (e.g., php:8.5-v5-slim-apache -> v5-slim-apache)
142+ TAG_SUFFIX=$(echo $TARGET | sed "s/^.*${PHP_VERSION}-v5-/v5-/")
143+
144+ # Create manifest for rc tag (always)
145+ echo "Creating manifest: ${TARGET}"
146+ docker buildx imagetools create -t ${TAG_ORI} ${TAG_ORI}-amd64 ${TAG_ORI}-arm64
147+
148+ # Create manifest for PHP_PATCH
149+ regctl image copy ${TAG_ORI} ghcr.io/${{ github.repository_owner }}/${TAG_PATH}
150+ # Create manifest for PHP_MINOR
151+ regctl image copy ${TAG_ORI} ghcr.io/${{ github.repository_owner }}/${TAG_MINOR}
152+
153+ # SAME FOR DOCKERHUB (for the official repository)
154+ if [ "${{ github.repository_owner }}" == "thecodingmachine" ]; then
155+ # Create manifest for PHP_PATCH_MINOR
156+ regctl image copy ${TAG_ORI} thecodingmachine/${TAG_PATH}
157+ # Create manifest for PHP_VERSION
158+ regctl image copy ${TAG_ORI} thecodingmachine/${TAG_MINOR}
159+ fi
160+ done
0 commit comments