Skip to content

Commit 2c0cf0a

Browse files
committed
build images on native arch, then merge later
1 parent 9a686f3 commit 2c0cf0a

5 files changed

Lines changed: 107 additions & 24 deletions

File tree

.github/workflows/build-images.yml

Lines changed: 83 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,57 +14,119 @@ permissions:
1414
contents: read
1515
packages: write
1616

17+
env:
18+
REGISTRY: ghcr.io
19+
OWNER: static-php
20+
1721
jobs:
1822
build:
19-
runs-on: ubuntu-24.04
23+
name: Build (${{ matrix.image.name }} ${{ matrix.platform.arch }})
2024
strategy:
2125
fail-fast: false
2226
matrix:
23-
include:
27+
image:
2428
- dockerfile: Dockerfile.debian
25-
image: packages-builder-debian
29+
name: packages-builder-debian
2630
build-args: ""
2731
- dockerfile: Dockerfile.alpine
28-
image: packages-builder-alpine
32+
name: packages-builder-alpine
2933
build-args: ""
3034
- dockerfile: Dockerfile.rhel
31-
image: packages-builder-rhel-8
35+
name: packages-builder-rhel-8
3236
build-args: "ALMA_VERSION=8"
3337
- dockerfile: Dockerfile.rhel
34-
image: packages-builder-rhel-9
38+
name: packages-builder-rhel-9
3539
build-args: "ALMA_VERSION=9"
3640
- dockerfile: Dockerfile.rhel
37-
image: packages-builder-rhel-10
41+
name: packages-builder-rhel-10
3842
build-args: "ALMA_VERSION=10"
43+
platform:
44+
- arch: amd64
45+
runs-on: ubuntu-24.04
46+
- arch: arm64
47+
runs-on: ubuntu-24.04-arm
48+
runs-on: ${{ matrix.platform.runs-on }}
3949
steps:
4050
- name: Checkout
4151
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
4252
with:
4353
persist-credentials: false
4454

45-
- name: Set up QEMU
46-
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3
47-
4855
- name: Set up Docker Buildx
4956
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
5057

5158
- name: Log in to GHCR
5259
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
5360
with:
54-
registry: ghcr.io
61+
registry: ${{ env.REGISTRY }}
5562
username: ${{ github.actor }}
5663
password: ${{ secrets.GITHUB_TOKEN }}
5764

58-
- name: Build and push ${{ matrix.image }}
65+
- name: Build and push by digest
66+
id: build
5967
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6
6068
with:
6169
context: .
62-
file: ${{ matrix.dockerfile }}
63-
platforms: linux/amd64,linux/arm64
64-
push: true
65-
tags: |
66-
ghcr.io/static-php/${{ matrix.image }}:latest
67-
ghcr.io/static-php/${{ matrix.image }}:${{ github.sha }}
68-
build-args: ${{ matrix.build-args }}
69-
cache-from: type=gha,scope=${{ matrix.image }}
70-
cache-to: type=gha,scope=${{ matrix.image }},mode=max
70+
file: ${{ matrix.image.dockerfile }}
71+
platforms: linux/${{ matrix.platform.arch }}
72+
build-args: ${{ matrix.image.build-args }}
73+
cache-from: type=gha,scope=${{ matrix.image.name }}-${{ matrix.platform.arch }}
74+
cache-to: type=gha,scope=${{ matrix.image.name }}-${{ matrix.platform.arch }},mode=max
75+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.OWNER }}/${{ matrix.image.name }},push-by-digest=true,name-canonical=true,push=true
76+
77+
- name: Export digest
78+
run: |
79+
mkdir -p /tmp/digests
80+
digest="${{ steps.build.outputs.digest }}"
81+
touch "/tmp/digests/${digest#sha256:}"
82+
83+
- name: Upload digest
84+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
85+
with:
86+
name: digests-${{ matrix.image.name }}-${{ matrix.platform.arch }}
87+
path: /tmp/digests/*
88+
if-no-files-found: error
89+
retention-days: 1
90+
91+
merge:
92+
name: Merge manifest (${{ matrix.image }})
93+
runs-on: ubuntu-24.04
94+
needs: build
95+
strategy:
96+
fail-fast: false
97+
matrix:
98+
image:
99+
- packages-builder-debian
100+
- packages-builder-alpine
101+
- packages-builder-rhel-8
102+
- packages-builder-rhel-9
103+
- packages-builder-rhel-10
104+
steps:
105+
- name: Download digests
106+
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
107+
with:
108+
pattern: digests-${{ matrix.image }}-*
109+
path: /tmp/digests
110+
merge-multiple: true
111+
112+
- name: Set up Docker Buildx
113+
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3
114+
115+
- name: Log in to GHCR
116+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3
117+
with:
118+
registry: ${{ env.REGISTRY }}
119+
username: ${{ github.actor }}
120+
password: ${{ secrets.GITHUB_TOKEN }}
121+
122+
- name: Create manifest list
123+
working-directory: /tmp/digests
124+
run: |
125+
docker buildx imagetools create \
126+
-t ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ matrix.image }}:latest \
127+
-t ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ matrix.image }}:${{ github.sha }} \
128+
$(printf '${{ env.REGISTRY }}/${{ env.OWNER }}/${{ matrix.image }}@sha256:%s ' *)
129+
130+
- name: Inspect manifest
131+
run: |
132+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.OWNER }}/${{ matrix.image }}:${{ github.sha }}

Dockerfile.alpine

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ FROM ubuntu:24.04
22

33
ARG TARGETARCH
44
ARG RPM_ARCH
5+
ARG UID=1000
6+
ARG GID=1000
57

68
ENV DEBIAN_FRONTEND=noninteractive
79

@@ -47,6 +49,7 @@ RUN cd /tmp/spc-bootstrap && \
4749
php vendor/bin/spc install-pkg go-xcaddy && \
4850
php vendor/bin/spc install-pkg zig && \
4951
SPC_TARGET=native-native-musl php vendor/bin/spc doctor --auto-fix --debug && \
50-
rm -rf /tmp/spc-bootstrap /root/.composer /root/.cache
52+
rm -rf /tmp/spc-bootstrap /root/.composer /root/.cache && \
53+
chown -R ${UID}:${GID} "$PKG_ROOT_PATH"
5154

5255
WORKDIR /build

Dockerfile.debian

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ FROM debian:11
22

33
ARG TARGETARCH
44
ARG RPM_ARCH
5+
ARG UID=1000
6+
ARG GID=1000
57

68
RUN if [ -z "${RPM_ARCH}" ]; then \
79
case "${TARGETARCH:-$(dpkg --print-architecture 2>/dev/null || uname -m)}" in \
@@ -44,6 +46,7 @@ RUN cd /tmp/spc-bootstrap && \
4446
php vendor/bin/spc install-pkg go-xcaddy && \
4547
php vendor/bin/spc install-pkg zig && \
4648
SPC_TARGET=native-native-musl php vendor/bin/spc doctor --auto-fix --debug && \
47-
rm -rf /tmp/spc-bootstrap /root/.composer /root/.cache
49+
rm -rf /tmp/spc-bootstrap /root/.composer /root/.cache && \
50+
chown -R ${UID}:${GID} "$PKG_ROOT_PATH"
4851

4952
WORKDIR /build

Dockerfile.rhel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ FROM almalinux:${ALMA_VERSION}
44
ARG ALMA_VERSION=10
55
ARG TARGETARCH
66
ARG RPM_ARCH
7+
ARG UID=1000
8+
ARG GID=1000
79

810
SHELL ["/bin/bash", "-c"]
911

@@ -78,6 +80,7 @@ RUN cd /tmp/spc-bootstrap && \
7880
php vendor/bin/spc install-pkg go-xcaddy && \
7981
php vendor/bin/spc install-pkg zig && \
8082
SPC_TARGET=native-native-musl php vendor/bin/spc doctor --auto-fix --debug && \
81-
rm -rf /tmp/spc-bootstrap /root/.composer /root/.cache
83+
rm -rf /tmp/spc-bootstrap /root/.composer /root/.cache && \
84+
chown -R ${UID}:${GID} "$PKG_ROOT_PATH"
8285

8386
WORKDIR /build

docker-compose.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ services:
1313
build:
1414
context: .
1515
dockerfile: Dockerfile.debian
16+
args:
17+
UID: "${UID:-1000}"
18+
GID: "${GID:-1000}"
1619
container_name: packages-debian
1720

1821
alpine:
1922
<<: *build-defaults
2023
build:
2124
context: .
2225
dockerfile: Dockerfile.alpine
26+
args:
27+
UID: "${UID:-1000}"
28+
GID: "${GID:-1000}"
2329
container_name: packages-alpine
2430

2531
rhel-8:
@@ -29,6 +35,8 @@ services:
2935
dockerfile: Dockerfile.rhel
3036
args:
3137
ALMA_VERSION: "8"
38+
UID: "${UID:-1000}"
39+
GID: "${GID:-1000}"
3240
container_name: packages-rhel-8
3341

3442
rhel-9:
@@ -38,6 +46,8 @@ services:
3846
dockerfile: Dockerfile.rhel
3947
args:
4048
ALMA_VERSION: "9"
49+
UID: "${UID:-1000}"
50+
GID: "${GID:-1000}"
4151
container_name: packages-rhel-9
4252

4353
rhel-10:
@@ -47,4 +57,6 @@ services:
4757
dockerfile: Dockerfile.rhel
4858
args:
4959
ALMA_VERSION: "10"
60+
UID: "${UID:-1000}"
61+
GID: "${GID:-1000}"
5062
container_name: packages-rhel-10

0 commit comments

Comments
 (0)