Skip to content

Commit 925b736

Browse files
committed
Add FrankenPHP build
1 parent b825da3 commit 925b736

File tree

10 files changed

+542
-0
lines changed

10 files changed

+542
-0
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
name: PHP Docker Image CI for Sylius
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- 'php/**'
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 PHP - ${{ 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 > php/frankenphp-version.bzl <<EOF
129+
FRANKENPHP_VERSION = "${{ matrix.frankenphp }}${{ matrix.php }}"
130+
EOF
131+
132+
- name: Bazel build and test
133+
run: |
134+
set -ex
135+
targets=$(bazel query 'attr(visibility, "//visibility:public", //frankenphp:*)' | sort)
136+
bazel build --curses=no ${targets}
137+
bazel test --curses=no --test_output=errors ${targets}
138+
139+
- name: Push
140+
uses: docker/build-push-action@v5.0.0
141+
with:
142+
file: ./frankenphp/Dockerfile
143+
context: ./frankenphp
144+
build-args: "FRANKENPHP_VERSION=${{ matrix.frankenphp }}${{ matrix.php }}"
145+
platforms: linux/amd64,linux/arm64
146+
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
147+
pull: false
148+
tags: ${{ steps.meta.outputs.tags }}
149+
labels: ${{ steps.meta.outputs.labels }}
150+
cache-from: type=local,src=/tmp/.buildx-cache-new
151+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
152+
153+
- name: Move cache
154+
run: |
155+
rm -rf /tmp/.buildx-cache
156+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
157+
158+
build-xdebug:
159+
needs: build
160+
161+
name: "Sylius PHP with Xdebug - ${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}"
162+
163+
runs-on: ubuntu-latest
164+
165+
strategy:
166+
fail-fast: false
167+
matrix:
168+
frankenphp: [ "1.5-php" ]
169+
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
170+
distro: [ "", "-alpine" ]
171+
172+
steps:
173+
174+
- uses: actions/checkout@v4.1.0
175+
176+
- name: Generate UUID
177+
id: generate-uuid
178+
run: |
179+
UUID=$(cat /proc/sys/kernel/random/uuid)
180+
echo "UUID=${UUID}" >> $GITHUB_OUTPUT
181+
182+
- name: Set up QEMU
183+
id: qemu
184+
uses: docker/setup-qemu-action@v3
185+
186+
- name: Available platforms
187+
run: echo ${{ steps.qemu.outputs.platforms }}
188+
189+
- name: Docker meta
190+
id: meta
191+
uses: docker/metadata-action@v5.0.0
192+
with:
193+
images: ${{ vars.DOCKER_frankenphp_REPOSITORY_NAME }}
194+
tags: |
195+
type=raw,value=${{ matrix.frankenphp }}${{ matrix.php }}-xdebug${{ matrix.distro }}
196+
197+
- name: Set up Docker Buildx
198+
uses: docker/setup-buildx-action@v3.0.0
199+
200+
- name: Cache Docker layers
201+
uses: actions/cache@v4.0.0
202+
with:
203+
path: /tmp/.buildx-cache
204+
key: "${{ runner.os }}-frankenphp-xdebug-${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-${{ steps.generate-uuid.outputs.uuid }}"
205+
# https://github.com/actions/cache/issues/109#issuecomment-558771281
206+
# https://github.community/t/always-save-new-cache-for-incremental-builds/172791
207+
restore-keys: "${{ runner.os }}-frankenphp-xdebug-${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}-buildx-cache-${{ vars.CACHE_VERSION }}-"
208+
209+
- name: Docker Login
210+
uses: docker/login-action@v3.0.0
211+
with:
212+
registry: ${{ secrets.DOCKER_REGISTRY }}
213+
username: ${{ secrets.DOCKER_REPOSITORY_LOGIN }}
214+
password: ${{ secrets.DOCKER_REPOSITORY_PASSWORD }}
215+
logout: true
216+
217+
- name: Prepare variable names for Docker build
218+
id: docker-build-variable-names
219+
run: |
220+
PHP_VERSION="${{ matrix.php }}"
221+
PHP_XDEBUG_VERSION_VARIABLE=XDEBUG_VERSION_PHP_${PHP_VERSION//./_}
222+
echo "XDEBUG_VERSION=$(jq -r --arg PHP_XDEBUG_VERSION_VARIABLE "$PHP_XDEBUG_VERSION_VARIABLE" '.[$PHP_XDEBUG_VERSION_VARIABLE]' <<< '${{ toJSON(vars) }}')" >> $GITHUB_ENV
223+
224+
- name: Build and push
225+
uses: docker/build-push-action@v5.0.0
226+
with:
227+
file: ./frankenphp/xdebug.Dockerfile
228+
context: ./frankenphp
229+
build-args: |
230+
"IMAGE_NAME=${{ vars.DOCKER_FRANKENPHP_REPOSITORY_NAME }}"
231+
"IMAGE_TAG=${{ matrix.frankenphp }}${{ matrix.php }}${{ matrix.distro }}"
232+
"XDEBUG_VERSION=${{ env.XDEBUG_VERSION }}"
233+
platforms: linux/amd64,linux/arm64
234+
push: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
235+
pull: true
236+
tags: ${{ steps.meta.outputs.tags }}
237+
cache-from: type=local,src=/tmp/.buildx-cache
238+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
239+
240+
- name: Move cache
241+
run: |
242+
rm -rf /tmp/.buildx-cache
243+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

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)