Skip to content

Commit 20f1758

Browse files
committed
Add FrankenPHP build
1 parent b825da3 commit 20f1758

21 files changed

+1749
-0
lines changed
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
name: PHP Docker Image CI for Sylius
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ frankenphp ]
7+
paths:
8+
- 'frankenphp/**'
9+
- 'WORKSPACE'
10+
schedule:
11+
- cron: '0 20 * * 5'
12+
13+
concurrency:
14+
group: sylius_frankenphp_build
15+
cancel-in-progress: false
16+
17+
jobs:
18+
19+
build:
20+
21+
name: "Sylius FrankenPHP - ${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}"
22+
23+
runs-on: ubuntu-latest
24+
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
frankenphp: [ "1.5-php" ]
29+
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
30+
distro: [ "", "-alpine" ]
31+
32+
steps:
33+
34+
- uses: actions/checkout@v4.1.0
35+
36+
- name: Generate UUID
37+
id: generate-uuid
38+
run: |
39+
UUID=$(cat /proc/sys/kernel/random/uuid)
40+
echo "UUID=${UUID}" >> $GITHUB_OUTPUT
41+
42+
- name: Set up QEMU
43+
uses: docker/setup-qemu-action@v3
44+
45+
- name: Docker meta
46+
id: meta
47+
uses: docker/metadata-action@v5.0.0
48+
with:
49+
images: ${{ vars.DOCKER_FRANKENPHP_REPOSITORY_NAME }}
50+
tags: |
51+
type=raw,value=${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}
52+
labels: |
53+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
54+
org.opencontainers.image.description=Sylius FrankenPHP ${{ matrix.frankenphp }}${{ matrix.php }} Docker image
55+
org.opencontainers.image.licenses=MIT
56+
57+
- name: Set up Docker Buildx
58+
uses: docker/setup-buildx-action@v3.0.0
59+
60+
- name: Cache Docker layers
61+
uses: actions/cache@v4.0.0
62+
with:
63+
path: /tmp/.buildx-cache
64+
key: "${{ runner.os }}-frankenphp-${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
65+
# https://github.com/actions/cache/issues/109#issuecomment-558771281
66+
# https://github.community/t/always-save-new-cache-for-incremental-builds/172791
67+
restore-keys: "${{ runner.os }}-frankenphp-${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-"
68+
69+
- name: Docker Login
70+
uses: docker/login-action@v3.0.0
71+
with:
72+
registry: ${{ secrets.DOCKER_REGISTRY }}
73+
username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }}
74+
password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }}
75+
logout: true
76+
77+
- name: Build multiplatform
78+
uses: docker/build-push-action@v5.0.0
79+
with:
80+
file: ./frankenphp/Dockerfile
81+
context: ./frankenphp
82+
build-args: "FRANKENPHP_VERSION=${{ matrix.frankenphp }}${{ matrix.php }}"
83+
platforms: linux/amd64,linux/arm64
84+
push: false
85+
pull: true
86+
tags: ${{ steps.meta.outputs.tags }}
87+
cache-from: type=local,src=/tmp/.buildx-cache
88+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
89+
90+
- name: Build linux/amd64 to tar
91+
uses: docker/build-push-action@v5.0.0
92+
with:
93+
file: ./frankenphp/Dockerfile
94+
context: ./frankenphp
95+
build-args: "FRANKENPHP_VERSION=${{ matrix.frankenphp }}${{ matrix.php }}"
96+
platforms: linux/amd64
97+
push: false
98+
pull: false
99+
tags: ${{ steps.meta.outputs.tags }}
100+
cache-from: type=local,src=/tmp/.buildx-cache-new
101+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new-amd64
102+
outputs: type=docker,dest=./external/image-amd64.tar
103+
104+
- name: Build linux/arm64 to tar
105+
uses: docker/build-push-action@v5.0.0
106+
with:
107+
file: ./frankenphp/Dockerfile
108+
context: ./frankenphp
109+
build-args: "FRANKENPHP_VERSION=${{ matrix.frankenphp }}${{ matrix.php }}"
110+
platforms: linux/arm64
111+
push: false
112+
pull: false
113+
tags: ${{ steps.meta.outputs.tags }}
114+
cache-from: type=local,src=/tmp/.buildx-cache-new
115+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new-arm64
116+
outputs: type=docker,dest=./external/image-arm64.tar
117+
118+
- name: Mount Bazel cache
119+
uses: actions/cache@v4.0.0
120+
with:
121+
path: "~/.cache/bazel"
122+
key: "${{ runner.os }}-frankenphp-${{ matrix.frankenphp }}${{ matrix.php }}-${{ matrix.distro }}-bazel-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
123+
restore-keys: "${{ runner.os }}-frankenphp-${{ matrix.frankenphp }}${{ matrix.php }}-${{ matrix.distro }}-bazel-cache-${{ vars.CACHE_VERSION }}-"
124+
125+
- name: Setup PHP for Bazel
126+
run: |
127+
set -ex
128+
cat > frankenphp/frankenphp-version.bzl <<EOF
129+
FRANKENPHP_VERSION = "${{ matrix.frankenphp }}${{ matrix.php }}"
130+
EOF
131+
cat > frankenphp/frankenphp-arch.bzl <<EOF
132+
ARCHITECTURES = ["amd64", "arm64"]
133+
EOF
134+
135+
- name: Bazel build and test
136+
run: |
137+
set -ex
138+
targets=$(bazel query 'attr(visibility, "//visibility:public", //frankenphp:*)' | sort)
139+
bazel build --curses=no ${targets}
140+
bazel test --curses=no --test_output=errors ${targets}
141+
142+
- name: Push
143+
uses: docker/build-push-action@v5.0.0
144+
with:
145+
file: ./frankenphp/Dockerfile
146+
context: ./frankenphp
147+
build-args: "FRANKENPHP_VERSION=${{ matrix.frankenphp }}${{ matrix.php }}"
148+
platforms: linux/amd64,linux/arm64
149+
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
150+
pull: false
151+
tags: ${{ steps.meta.outputs.tags }}
152+
labels: ${{ steps.meta.outputs.labels }}
153+
cache-from: type=local,src=/tmp/.buildx-cache-new
154+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
155+
156+
- name: Move cache
157+
run: |
158+
rm -rf /tmp/.buildx-cache
159+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
160+
161+
build-xdebug:
162+
needs: build
163+
164+
name: "Sylius PHP with Xdebug - ${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}"
165+
166+
runs-on: ubuntu-latest
167+
168+
strategy:
169+
fail-fast: false
170+
matrix:
171+
frankenphp: [ "1.5-php" ]
172+
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
173+
distro: [ "", "-alpine" ]
174+
175+
steps:
176+
177+
- uses: actions/checkout@v4.1.0
178+
179+
- name: Generate UUID
180+
id: generate-uuid
181+
run: |
182+
UUID=$(cat /proc/sys/kernel/random/uuid)
183+
echo "UUID=${UUID}" >> $GITHUB_OUTPUT
184+
185+
- name: Set up QEMU
186+
id: qemu
187+
uses: docker/setup-qemu-action@v3
188+
189+
- name: Available platforms
190+
run: echo ${{ steps.qemu.outputs.platforms }}
191+
192+
- name: Docker meta
193+
id: meta
194+
uses: docker/metadata-action@v5.0.0
195+
with:
196+
images: ${{ vars.DOCKER_FRANKENPHP_REPOSITORY_NAME }}
197+
tags: |
198+
type=raw,value=${{ matrix.frankenphp }}${{ matrix.php }}-xdebug${{ matrix.distro }}
199+
200+
- name: Set up Docker Buildx
201+
uses: docker/setup-buildx-action@v3.0.0
202+
203+
- name: Cache Docker layers
204+
uses: actions/cache@v4.0.0
205+
with:
206+
path: /tmp/.buildx-cache
207+
key: "${{ runner.os }}-frankenphp-xdebug-${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
208+
# https://github.com/actions/cache/issues/109#issuecomment-558771281
209+
# https://github.community/t/always-save-new-cache-for-incremental-builds/172791
210+
restore-keys: "${{ runner.os }}-frankenphp-xdebug-${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-"
211+
212+
- name: Docker Login
213+
uses: docker/login-action@v3.0.0
214+
with:
215+
registry: ${{ secrets.DOCKER_REGISTRY }}
216+
username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }}
217+
password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }}
218+
logout: true
219+
220+
- name: Prepare variable names for Docker build
221+
id: docker-build-variable-names
222+
run: |
223+
PHP_VERSION="${{ matrix.php }}"
224+
PHP_XDEBUG_VERSION_VARIABLE=XDEBUG_VERSION_PHP_${PHP_VERSION//./_}
225+
echo "XDEBUG_VERSION=$(jq -r --arg PHP_XDEBUG_VERSION_VARIABLE "$PHP_XDEBUG_VERSION_VARIABLE" '.[$PHP_XDEBUG_VERSION_VARIABLE]' <<< '${{ toJSON(vars) }}')" >> $GITHUB_ENV
226+
227+
- name: Build and push
228+
uses: docker/build-push-action@v5.0.0
229+
with:
230+
file: ./frankenphp/xdebug.Dockerfile
231+
context: ./frankenphp
232+
build-args: |
233+
"IMAGE_NAME=${{ vars.DOCKER_FRANKENPHP_REPOSITORY_NAME }}"
234+
"IMAGE_TAG=${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}"
235+
"XDEBUG_VERSION=${{ env.XDEBUG_VERSION }}"
236+
platforms: linux/amd64,linux/arm64
237+
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
238+
pull: true
239+
tags: ${{ steps.meta.outputs.tags }}
240+
cache-from: type=local,src=/tmp/.buildx-cache
241+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
242+
243+
- name: Move cache
244+
run: |
245+
rm -rf /tmp/.buildx-cache
246+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

frankenphp/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("@io_bazel_rules_docker//container:import.bzl", "container_import")
2+
load("@io_bazel_rules_docker//contrib:test.bzl", "container_test")
3+
load(":php-arch.bzl", "ARCHITECTURES")
4+
load(":php-version.bzl", "FRANKENPHP_VERSION")
5+
6+
package(default_visibility = ["//visibility:public"])
7+
8+
[
9+
container_test(
10+
name = "frankenphp" + FRANKENPHP_VERSION + "_" + arch + "_test",
11+
size = "medium",
12+
configs = ["testdata/frankenphp" + FRANKENPHP_VERSION + "_" + arch + ".yaml"],
13+
image = "@image" + arch + "//image",
14+
)
15+
for arch in ARCHITECTURES
16+
]

frankenphp/Caddyfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
{$CADDY_GLOBAL_OPTIONS}
3+
4+
frankenphp {
5+
{$FRANKENPHP_CONFIG}
6+
}
7+
}
8+
9+
{$CADDY_EXTRA_CONFIG}
10+
11+
{$SERVER_NAME:localhost} {
12+
log {
13+
# Redact the authorization query parameter that can be set by Mercure
14+
format filter {
15+
request>uri query {
16+
replace authorization REDACTED
17+
}
18+
}
19+
}
20+
21+
root * /app/public
22+
encode zstd br gzip
23+
24+
mercure {
25+
# Transport to use (default to Bolt)
26+
transport_url {$MERCURE_TRANSPORT_URL:bolt:///data/mercure.db}
27+
# Publisher JWT key
28+
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
29+
# Subscriber JWT key
30+
subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG}
31+
# Allow anonymous subscribers (double-check that it's what you want)
32+
anonymous
33+
# Enable the subscription API (double-check that it's what you want)
34+
subscriptions
35+
# Extra directives
36+
{$MERCURE_EXTRA_DIRECTIVES}
37+
}
38+
39+
vulcain
40+
41+
# Add links to the API docs and to the Mercure Hub if not set explicitly (e.g. the PWA)
42+
header ?Link `</docs.jsonld>; rel="http://www.w3.org/ns/hydra/core#apiDocumentation", </.well-known/mercure>; rel="mercure"`
43+
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
44+
header ?Permissions-Policy "browsing-topics=()"
45+
46+
# Matches requests for HTML documents, for static files and for Next.js files,
47+
# except for known API paths and paths with extensions handled by API Platform
48+
@pwa expression `(
49+
header({'Accept': '*text/html*'})
50+
&& !path(
51+
'/docs*', '/graphql*', '/bundles*', '/contexts*', '/_profiler*', '/_wdt*',
52+
'*.json*', '*.html', '*.csv', '*.yml', '*.yaml', '*.xml'
53+
)
54+
)
55+
|| path('/favicon.ico', '/manifest.json', '/robots.txt', '/sitemap*', '/_next*', '/__next*')
56+
|| query({'_rsc': '*'})`
57+
58+
# Comment the following line if you don't want Next.js to catch requests for HTML documents.
59+
# In this case, they will be handled by the PHP app.
60+
reverse_proxy @pwa http://{$PWA_UPSTREAM}
61+
62+
php_server
63+
}

0 commit comments

Comments
 (0)