Skip to content

Commit 1d936b5

Browse files
committed
Turbo build Docker image
1 parent e911cc9 commit 1d936b5

2 files changed

Lines changed: 162 additions & 0 deletions

File tree

‎.github/turbo-build/Dockerfile‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Prebuilt image for the turbo-compile gnu legs in phar.yml, published to
2+
# ghcr.io/phpstan/turbo-build by turbo-build-image.yml (tags gnu-php8.3,
3+
# gnu-php8.4, gnu-php8.5; each a linux/amd64 + linux/arm64 manifest).
4+
#
5+
# Baking the PHP toolchain in keeps apt and the ondrej/php PPA out of the
6+
# compile jobs entirely: ports.ubuntu.com (the only Ubuntu arm64 mirror,
7+
# no CDN in front of it) has repeated outages that failed the arm64 legs,
8+
# and the from-scratch PPA setup cost ~1 minute on every x86_64 leg.
9+
#
10+
# The ubuntu:22.04 base pins the built binaries' glibc symbol floor at
11+
# 2.34 (RHEL 9, Ubuntu 22.04+, Debian 12+) independently of the runner
12+
# image — same floor as the previous `container: ubuntu:22.04` legs.
13+
FROM ubuntu:22.04
14+
15+
ARG PHP_MINOR
16+
ENV DEBIAN_FRONTEND=noninteractive
17+
18+
# The source label links the GHCR package to this repository.
19+
LABEL org.opencontainers.image.source="https://github.com/phpstan/phpstan-src"
20+
LABEL org.opencontainers.image.description="PHP and build toolchain for compiling the phpstan_turbo extension (glibc floor 2.34)"
21+
22+
# apt mirrors 404 mid-sync (the fetched index can reference a superseded
23+
# .deb already pruned from the pool); only a fresh index fixes that, so
24+
# update+install retries as a unit
25+
RUN test -n "$PHP_MINOR"; \
26+
apt_install() { \
27+
for attempt in 1 2 3; do \
28+
if apt-get update && apt-get install -y "$@"; then \
29+
return 0; \
30+
fi; \
31+
echo "apt-get failed (attempt $attempt), retrying with a fresh index"; \
32+
sleep 15; \
33+
done; \
34+
return 1; \
35+
}; \
36+
apt_install software-properties-common gnupg ca-certificates curl git make g++ patch unzip zstd \
37+
&& add-apt-repository -y ppa:ondrej/php \
38+
&& apt_install "php$PHP_MINOR-cli" "php$PHP_MINOR-dev" "php$PHP_MINOR-curl" "php$PHP_MINOR-mbstring" "php$PHP_MINOR-xml" \
39+
&& rm -rf /var/lib/apt/lists/* \
40+
&& ln -sf "/usr/bin/php$PHP_MINOR" /usr/local/bin/php \
41+
&& ln -sf "/usr/bin/php-config$PHP_MINOR" /usr/local/bin/php-config
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
name: "Build Turbo compile images"
4+
5+
# Builds .github/turbo-build/Dockerfile natively on x86_64 and arm64
6+
# runners and publishes ghcr.io/phpstan/turbo-build:gnu-php{8.3,8.4,8.5}
7+
# as multi-arch manifests. The turbo-compile gnu legs in phar.yml run in
8+
# these images, so their only network dependency is a GHCR pull — no apt,
9+
# no ports.ubuntu.com, no PPA at compile time.
10+
11+
on:
12+
workflow_dispatch:
13+
pull_request:
14+
paths:
15+
- ".github/turbo-build/**"
16+
- ".github/workflows/turbo-build-image.yml"
17+
push:
18+
branches:
19+
- "2.2.x"
20+
paths:
21+
- ".github/turbo-build/**"
22+
- ".github/workflows/turbo-build-image.yml"
23+
schedule:
24+
# weekly rebuild so PHP patch releases and security updates flow into
25+
# the baked images — the compile jobs never run apt themselves
26+
- cron: '30 2 * * 1'
27+
28+
permissions:
29+
contents: read
30+
31+
concurrency:
32+
group: turbo-build-image-${{ github.ref }}
33+
cancel-in-progress: false
34+
35+
jobs:
36+
build:
37+
name: "Build image (php${{ matrix.php-version }}, ${{ matrix.platform.arch }})"
38+
if: github.repository == 'phpstan/phpstan-src'
39+
runs-on: ${{ matrix.platform.runs-on }}
40+
timeout-minutes: 30
41+
permissions:
42+
contents: read
43+
packages: write
44+
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
php-version: ["8.3", "8.4", "8.5"]
49+
platform:
50+
- arch: "amd64"
51+
runs-on: "ubuntu-latest"
52+
- arch: "arm64"
53+
runs-on: "ubuntu-24.04-arm"
54+
55+
env:
56+
IMAGE: "ghcr.io/phpstan/turbo-build:gnu-php${{ matrix.php-version }}-${{ matrix.platform.arch }}"
57+
58+
steps:
59+
- name: Harden the runner (Audit all outbound calls)
60+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
61+
with:
62+
egress-policy: audit
63+
64+
- name: "Checkout"
65+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
66+
with:
67+
persist-credentials: false
68+
69+
- name: "Build"
70+
run: docker build --build-arg "PHP_MINOR=${{ matrix.php-version }}" -t "$IMAGE" .github/turbo-build
71+
72+
- name: "Smoke test (interpreter matches the matrix, toolchain present)"
73+
run: |
74+
VERSION="$(docker run --rm "$IMAGE" php -r 'echo PHP_VERSION;')"
75+
echo "image reports PHP $VERSION, expected ${{ matrix.php-version }}.*"
76+
[ "${VERSION%.*}" = "${{ matrix.php-version }}" ]
77+
docker run --rm "$IMAGE" sh -c 'php-config --version && git --version && g++ --version && make --version && curl --version'
78+
79+
# PR runs stop here: build + smoke validate the Dockerfile change,
80+
# only pushes to 2.2.x (and the cron/manual runs) publish.
81+
- name: "Log in to GHCR"
82+
if: github.event_name != 'pull_request'
83+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
84+
85+
- name: "Push"
86+
if: github.event_name != 'pull_request'
87+
run: docker push "$IMAGE"
88+
89+
manifest:
90+
name: "Publish multi-arch manifest (php${{ matrix.php-version }})"
91+
if: github.repository == 'phpstan/phpstan-src' && github.event_name != 'pull_request'
92+
needs: build
93+
runs-on: "ubuntu-latest"
94+
timeout-minutes: 10
95+
permissions:
96+
packages: write
97+
98+
strategy:
99+
matrix:
100+
php-version: ["8.3", "8.4", "8.5"]
101+
102+
env:
103+
TAG: "ghcr.io/phpstan/turbo-build:gnu-php${{ matrix.php-version }}"
104+
105+
steps:
106+
- name: Harden the runner (Audit all outbound calls)
107+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
108+
with:
109+
egress-policy: audit
110+
111+
- name: "Log in to GHCR"
112+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
113+
114+
- name: "Create and push the manifest"
115+
run: docker buildx imagetools create -t "$TAG" "$TAG-amd64" "$TAG-arm64"
116+
117+
- name: "Verify both platforms are present"
118+
run: |
119+
docker buildx imagetools inspect "$TAG" | tee manifest.txt
120+
grep -q "linux/amd64" manifest.txt
121+
grep -q "linux/arm64" manifest.txt

0 commit comments

Comments
 (0)