1212 workflow_dispatch :
1313
1414jobs :
15- test :
15+ build :
1616 strategy :
1717 fail-fast : false
1818 matrix :
1919 php_version : ['8.5', '8.4', '8.3','8.2','8.1']
2020 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"}]
21+ builder : [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}]
2322 runs-on : ${{ matrix.builder.os }}
24- name : Test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} only
23+ name : Build ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }}
2524 steps :
2625 - name : Checkout
2726 uses : actions/checkout@v4
2827 - 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' }}
3228 uses : docker-practice/actions-setup-docker@master
33- - name : Set up QEMU
34- uses : docker/setup-qemu-action@v3
29+ - name : Login to GHCR
30+ uses : docker/login-action@v3
31+ with :
32+ registry : ghcr.io
33+ username : ${{ github.actor }}
34+ password : ${{ secrets.GITHUB_TOKEN }}
3535 - name : Set up Docker Buildx
3636 uses : docker/setup-buildx-action@v3
3737 - name : Build
3838 run : |
3939 PHP_VERSION="${{ matrix.php_version }}"
40+ # Get last cached successful builds
41+ TARGETS=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="" docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print | jq -r '.target[].tags[]')
42+ for TARGET in $TARGETS; do
43+ docker --quiet pull ${TARGET} || echo ""
44+ done;
45+ # Build the current builds
46+ REPO="ghcr.io/${{ github.repository_owner }}/php" \
47+ ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
4048 TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
4149 docker buildx bake \
4250 --set "*.platform=linux/${{ matrix.builder.arch }}" \
43- --set "*.output=type=docker " \
51+ --set "*.output=type=registry " \
4452 --load \
4553 php${PHP_VERSION//.}-${{ matrix.variant }}-all
4654 - name : Display tags built
4755 run : |
48- docker image ls --filter="reference=thecodingmachine/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}"
56+ docker image ls --filter="reference=ghcr.io/${{ github.repository_owner }}/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}"
57+
58+ test :
59+ needs :
60+ - build
61+ strategy :
62+ fail-fast : false
63+ matrix :
64+ php_version : ['8.5', '8.4', '8.3','8.2','8.1']
65+ variant : ['apache','cli','fpm']
66+ builder : [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}]
67+ runs-on : ${{ matrix.builder.os }}
68+ name : Test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }}
69+ steps :
70+ - name : Checkout
71+ uses : actions/checkout@v4
72+ - name : Set up Docker
73+ uses : docker-practice/actions-setup-docker@master
74+ - name : Login to GHCR
75+ uses : docker/login-action@v3
76+ with :
77+ registry : ghcr.io
78+ username : ${{ github.actor }}
79+ password : ${{ secrets.GITHUB_TOKEN }}
4980 - name : Test
5081 run : |
82+ REPO="ghcr.io/${{ github.repository_owner }}/php" \
5183 TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
5284 PHP_VERSION="${{ matrix.php_version }}" \
85+ ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
5386 BRANCH="v5" \
5487 VARIANT="${{ matrix.variant }}" \
5588 PLATFORM="linux/${{ matrix.builder.arch }}" \
5689 ./tests-suite/bash_unit -f tap ./tests-suite/*.sh
5790
58- publish :
59- # push ~ schedule
91+ merge-and-publish :
6092 if : ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
6193 needs :
6294 - test
6395 runs-on : ubuntu-latest
64- name : Publish ${{ matrix.php_version }}-${{ matrix.variant }} multi-arch to dockerhub
96+ name : Merge and publish ${{ matrix.php_version }}-${{ matrix.variant }}
6597 strategy :
6698 fail-fast : false
6799 matrix :
@@ -70,49 +102,69 @@ jobs:
70102 steps :
71103 - name : Checkout
72104 uses : actions/checkout@v4
73- - name : Set up QEMU
74- uses : docker/setup-qemu-action@v3
75105 - name : Set up Docker Buildx
76106 uses : docker/setup-buildx-action@v3
107+ - name : Login to GHCR
108+ uses : docker/login-action@v3
109+ with :
110+ registry : ghcr.io
111+ username : ${{ github.actor }}
112+ password : ${{ secrets.GITHUB_TOKEN }}
77113 - name : Login to DockerHub
78114 uses : docker/login-action@v3
115+ if : ${{ github.repository_owner == 'thecodingmachine' }}
79116 with :
80117 username : ${{ secrets.DOCKERHUB_USERNAME }}
81118 password : ${{ secrets.DOCKERHUB_TOKEN }}
119+ - name : Install regctl
120+ uses : regclient/actions/regctl-installer@main
121+ with :
122+ release : ' v0.8.1'
82123 - name : Fetch minor version of php
83124 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 }}
125+ # Pull amd64 slim image to get PHP version
126+ docker pull ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64
92127 # 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`
128+ 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`
94129 echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV
95- - name : Display tags to build
130+ - name : Get list of images for this variant
131+ id : get-images
96132 run : |
97133 PHP_VERSION="${{ matrix.php_version }}"
98- PHP_PATCH_MINOR=" ${{ env.PHP_PATCH_MINOR }}" \
134+ REPO="ghcr.io/ ${{ github.repository_owner }}/php " \
99135 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 }}
136+ docker buildx bake \
137+ -- print \
138+ php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq '.target[].tags[]'
139+ - name : Create multiarch manifests
104140 run : |
105141 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
142+
143+ # Get all targets from the bake group
144+ TARGETS=$(docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print | jq -r '.group["php${PHP_VERSION//.}-${{ matrix.variant }}-all"].targets[]')
145+
146+ for TARGET in $TARGETS; do
147+ TAG_ORI=$(REPO="ghcr.io/${{ github.repository_owner }}/php" TAG_PREFIX="rc${GITHUB_RUN_ID}-" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
148+ TAG_PATH=$(REPO="php" PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
149+ TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --print | jq -r '.target[].tags[]')
150+ echo "Processing target: $TARGET"
151+ # Extract the tag suffix from generated tag (e.g., php:8.5-v5-slim-apache -> v5-slim-apache)
152+ TAG_SUFFIX=$(echo $TARGET | sed "s/^.*${PHP_VERSION}-v5-/v5-/")
153+
154+ # Create manifest for rc tag (always)
155+ echo "Creating manifest: ${TARGET}"
156+ docker buildx imagetools create -t ${TAG_ORI} ${TAG_ORI}-amd64 ${TAG_ORI}-arm64
157+
158+ # Create manifest for PHP_PATCH
159+ regctl image copy ${TAG_ORI} ghcr.io/${{ github.repository_owner }}/${TAG_PATH}
160+ # Create manifest for PHP_MINOR
161+ regctl image copy ${TAG_ORI} ghcr.io/${{ github.repository_owner }}/${TAG_MINOR}
162+
163+ # SAME FOR DOCKERHUB (for the official repository)
164+ if [ "${{ github.repository_owner }}" == "thecodingmachine" ]; then
165+ # Create manifest for PHP_PATCH_MINOR
166+ regctl image copy ${TAG_ORI} thecodingmachine/${TAG_PATH}
167+ # Create manifest for PHP_VERSION
168+ regctl image copy ${TAG_ORI} thecodingmachine/${TAG_MINOR}
169+ fi
170+ done
0 commit comments