Skip to content

Commit 54426bf

Browse files
committed
Create build with multi arch splitted
1 parent ac028ad commit 54426bf

32 files changed

+265
-187
lines changed

.github/workflows/legacy-v5.yml

Lines changed: 96 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,55 @@ on:
44
workflow_dispatch:
55

66
jobs:
7-
test-and-publish:
7+
build:
8+
strategy:
9+
fail-fast: false
10+
matrix:
11+
php_version: ['8.1', '8.0', '7.4']
12+
variant: ['apache','cli','fpm']
13+
builder: [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}]
14+
runs-on: ${{ matrix.builder.os }}
15+
name: Build ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Set up Docker
20+
uses: docker-practice/actions-setup-docker@master
21+
- name: Login to GHCR
22+
uses: docker/login-action@v3
23+
with:
24+
registry: ghcr.io
25+
username: ${{ github.actor }}
26+
password: ${{ secrets.GITHUB_TOKEN }}
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v3
29+
- name: Build
30+
run: |
31+
PHP_VERSION="${{ matrix.php_version }}"
32+
# Get last cached successful builds
33+
TARGETS=$(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[]')
34+
for TARGET in $TARGETS; do
35+
docker --quiet pull ${TARGET} || echo ""
36+
done;
37+
# Build the current builds
38+
REPO="ghcr.io/${{ github.repository_owner }}/php" \
39+
ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
40+
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
41+
docker buildx bake \
42+
--set "*.platform=linux/${{ matrix.builder.arch }}" \
43+
--set "*.output=type=registry" \
44+
--progress=quiet \
45+
--load \
46+
php${PHP_VERSION//.}-${{ matrix.variant }}-all
47+
- name: Display tags built
48+
run: |
49+
docker image ls --filter="reference=ghcr.io/${{ github.repository_owner }}/php" --format "{{.CreatedAt}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}"
50+
51+
merge-and-publish:
52+
needs:
53+
- build
854
runs-on: ubuntu-latest
9-
name: Publish ${{ matrix.php_version }}-${{ matrix.variant }} multi-arch to dockerhub
55+
name: Merge and publish ${{ matrix.php_version }}-${{ matrix.variant }}
1056
strategy:
1157
fail-fast: false
1258
matrix:
@@ -15,49 +61,67 @@ jobs:
1561
steps:
1662
- name: Checkout
1763
uses: actions/checkout@v4
18-
- name: Set up QEMU
19-
uses: docker/setup-qemu-action@v3
2064
- name: Set up Docker Buildx
2165
uses: docker/setup-buildx-action@v3
66+
- name: Login to GHCR
67+
uses: docker/login-action@v3
68+
with:
69+
registry: ghcr.io
70+
username: ${{ github.actor }}
71+
password: ${{ secrets.GITHUB_TOKEN }}
2272
- name: Login to DockerHub
2373
uses: docker/login-action@v3
74+
if: ${{ github.repository_owner == 'thecodingmachine' }}
2475
with:
2576
username: ${{ secrets.DOCKERHUB_USERNAME }}
2677
password: ${{ secrets.DOCKERHUB_TOKEN }}
78+
- name: Install regctl
79+
uses: regclient/actions/regctl-installer@main
80+
with:
81+
release: 'v0.8.1'
2782
- name: Fetch minor version of php
2883
run: |
29-
# Build slim one
30-
PHP_VERSION="${{ matrix.php_version }}"
31-
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
32-
docker buildx bake \
33-
--set "*.platform=linux/amd64" \
34-
--set "*.output=type=docker" \
35-
--load \
36-
php${PHP_VERSION//.}-slim-${{ matrix.variant }}
84+
# Pull amd64 slim image to get PHP version
85+
docker pull --quiet ghcr.io/${{ github.repository_owner }}/php:rc${GITHUB_RUN_ID}-${{ matrix.php_version }}-v5-slim-${{ matrix.variant }}-amd64
3786
# Retrieve minor
38-
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`
87+
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`
88+
echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}"
3989
echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV
40-
- name: Display tags to build
90+
- name: Get list of images for this variant
91+
id: get-images
4192
run: |
4293
PHP_VERSION="${{ matrix.php_version }}"
43-
PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \
94+
REPO="ghcr.io/${{ github.repository_owner }}/php" \
4495
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
45-
IS_RELEASE="1" \
46-
docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --print --progress plain | jq ".target[].tags | join(\" \")" -r > "/tmp/tags.log"
47-
cat "/tmp/tags.log"
48-
- name: Build and push ${{ matrix.php_version }}-${{ matrix.variant }}
96+
docker buildx bake \
97+
--print --progress=quiet \
98+
php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq '.target[].tags[]'
99+
- name: Create multiarch manifests
49100
run: |
50101
PHP_VERSION="${{ matrix.php_version }}"
51-
PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \
52-
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
53-
IS_RELEASE="1" \
54-
docker buildx bake \
55-
--set "*.platform=linux/amd64,linux/arm64" \
56-
--set "*.output=type=registry" \
57-
php${PHP_VERSION//.}-${{ matrix.variant }}-all
58-
- name: Push artifacts
59-
uses: actions/upload-artifact@v4
60-
with:
61-
name: ${{ matrix.php_version }}-${{ matrix.variant }}
62-
path: /tmp/tags.log
63-
retention-days: 60
102+
103+
# Get all targets from the bake group
104+
TARGETS=$(docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --progress=quiet --print | jq -r ".group[\"php${PHP_VERSION//.}-${{ matrix.variant }}-all\"].targets[]")
105+
106+
for TARGET in $TARGETS; do
107+
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]")
108+
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]")
109+
TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]")
110+
111+
# Create manifest for rc tag (always)
112+
echo "Creating manifest: ${TARGET} - ${TAG_ORI}"
113+
docker buildx imagetools create --progress=plain -t "${TAG_ORI}" "${TAG_ORI}-amd64" "${TAG_ORI}-arm64"
114+
115+
# Create manifest for PHP_PATCH
116+
regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_PATH}"
117+
# Create manifest for PHP_MINOR
118+
regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_MINOR}"
119+
120+
# SAME FOR DOCKERHUB (for the official repository)
121+
if [ "${{ github.repository_owner }}" == "thecodingmachine" ]; then
122+
# Create manifest for PHP_PATCH_MINOR
123+
regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_PATH}"
124+
# Create manifest for PHP_VERSION
125+
regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_MINOR}"
126+
fi
127+
done

.github/workflows/legacy.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ jobs:
1010
matrix:
1111
php_version: ['8.4', '8.3','8.2','8.1','8.0','7.4']
1212
variant: ['apache','cli','fpm']
13-
# builder: [ {arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "macos-latest"}]
14-
builder: [ {arch: "amd64", os: "ubuntu-latest"}, {arch: "arm64", os: "ubuntu-latest"}]
13+
builder: [ {arch: "amd64", os: "ubuntu-24.04"}, {arch: "arm64", os: "ubuntu-24.04-arm"}]
1514
runs-on: ${{ matrix.builder.os }}
1615
name: Test ${{ matrix.php_version }}-${{ matrix.variant }} ${{ matrix.builder.arch }} only
1716
steps:

.github/workflows/workflow.yml

Lines changed: 85 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,78 @@ on:
1212
workflow_dispatch:
1313

1414
jobs:
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&test ${{ 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+
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[]')
42+
for TAG in $TAGS; do
43+
docker pull --quiet ${TAG} || 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 }}" \
4351
--set "*.output=type=docker" \
44-
--load \
52+
--load --progress=quiet \
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}}"
4957
- name: Test
5058
run: |
59+
REPO="ghcr.io/${{ github.repository_owner }}/php" \
5160
TAG_PREFIX="rc${GITHUB_RUN_ID}-" \
5261
PHP_VERSION="${{ matrix.php_version }}" \
62+
ARCH_SUFFIX="-${{ matrix.builder.arch }}" \
5363
BRANCH="v5" \
5464
VARIANT="${{ matrix.variant }}" \
5565
PLATFORM="linux/${{ matrix.builder.arch }}" \
5666
./tests-suite/bash_unit -f tap ./tests-suite/*.sh
67+
- name: Publish specific arch version
68+
if: > # Only from the main repo
69+
github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' ||
70+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
71+
run: |
72+
PHP_VERSION="${{ matrix.php_version }}"
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 --progress=quiet \
78+
php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq -r '.target[].tags[]');
79+
for TAG in $TAGS; do docker push --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:
62-
- test
84+
- build
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,67 @@ 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 --quiet 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`
119+
echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}"
94120
echo "PHP_PATCH_MINOR=${PHP_PATCH_MINOR}" >> $GITHUB_ENV
95-
- name: Display tags to build
121+
- name: Get list of images for this variant
122+
id: get-images
96123
run: |
97124
PHP_VERSION="${{ matrix.php_version }}"
98-
PHP_PATCH_MINOR="${{ env.PHP_PATCH_MINOR }}" \
125+
REPO="ghcr.io/${{ github.repository_owner }}/php" \
99126
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 }}
127+
docker buildx bake \
128+
--print --progress=quiet \
129+
php${PHP_VERSION//.}-${{ matrix.variant }}-all | jq '.target[].tags[]'
130+
- name: Create multiarch manifests
104131
run: |
105132
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
133+
134+
# Get all targets from the bake group
135+
TARGETS=$(docker buildx bake php${PHP_VERSION//.}-${{ matrix.variant }}-all --progress=quiet --print | jq -r ".group[\"php${PHP_VERSION//.}-${{ matrix.variant }}-all\"].targets[]")
136+
137+
for TARGET in $TARGETS; do
138+
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]")
139+
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]")
140+
TAG_MINOR=$(REPO="php" docker buildx bake ${TARGET} --progress=quiet --print | jq -r ".target | to_entries[] | select(.key == \"${TARGET}\") | .value.tags[0]")
141+
142+
# Create manifest for rc tag (always)
143+
echo "Creating manifest: ${TARGET} - ${TAG_ORI}"
144+
docker buildx imagetools create --progress=plain -t "${TAG_ORI}" "${TAG_ORI}-amd64" "${TAG_ORI}-arm64"
145+
146+
# Create manifest for PHP_PATCH
147+
regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_PATH}"
148+
# Create manifest for PHP_MINOR
149+
regctl image copy "${TAG_ORI}" "ghcr.io/${{ github.repository_owner }}/${TAG_MINOR}"
150+
151+
# SAME FOR DOCKERHUB (for the official repository)
152+
if [ "${{ github.repository_owner }}" == "thecodingmachine" ]; then
153+
# Create manifest for PHP_PATCH_MINOR
154+
regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_PATH}"
155+
# Create manifest for PHP_VERSION
156+
regctl image copy "${TAG_ORI}" "thecodingmachine/${TAG_MINOR}"
157+
fi
158+
done

Dockerfile.apache.node

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ ENV BLACKFIRE_VERSION=${BLACKFIRE_VERSION}
2121
RUN apt update && \
2222
apt install -y --no-install-recommends gnupg && \
2323
if [[ "${NODE_VERSION}" -lt "16" ]]; then \
24-
curl -sL https://deb.nodesource.com/setup_${NODE_VERSION}.x | sudo bash -; \
24+
curl -sL --retry 5 --retry-delay 2 https://deb.nodesource.com/setup_${NODE_VERSION}.x | sudo bash -; \
2525
else \
2626
sudo mkdir -p /etc/apt/keyrings && \
27-
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
27+
curl -fsSL --retry 5 --retry-delay 2 https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
2828
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_VERSION.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list; \
2929
fi && \
3030
apt update && \
3131
apt install -y --no-install-recommends nodejs && \
32-
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
32+
curl -sS --retry 5 --retry-delay 2 https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
3333
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
3434
apt update && \
3535
apt install -y --no-install-recommends yarn && \

0 commit comments

Comments
 (0)