Skip to content

Commit 19725e7

Browse files
authored
build: fix errors, always install xdebug, test php8.4, fixes #31, fixes #29 (#34)
1 parent 12e26c5 commit 19725e7

4 files changed

Lines changed: 67 additions & 36 deletions

File tree

docker-compose.frankenphp.yaml

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,7 @@ services:
55
hostname: ${DDEV_SITENAME}-frankenphp
66
image: ${FRANKENPHP_DOCKER_IMAGE:-dunglas/frankenphp:php8.3}-${DDEV_SITENAME}-built
77
build:
8-
dockerfile_inline: |
9-
ARG FRANKENPHP_DOCKER_IMAGE=scratch
10-
FROM $${FRANKENPHP_DOCKER_IMAGE}
11-
ARG FRANKENPHP_PHP_EXTENSIONS=""
12-
RUN [ -z "$${FRANKENPHP_PHP_EXTENSIONS}" ] || install-php-extensions $${FRANKENPHP_PHP_EXTENSIONS}
13-
ARG username
14-
ARG uid
15-
ARG gid
16-
RUN <<EOF
17-
set -eu -o pipefail
18-
getent group tty || groupadd tty
19-
(groupadd --gid $$gid "$$username" || groupadd "$$username" || true) && (useradd -G tty -l -m -s "/bin/bash" --gid "$$username" --comment '' --uid $$uid "$$username" || useradd -G tty -l -m -s "/bin/bash" --gid "$$username" --comment '' "$$username" || useradd -G tty -l -m -s "/bin/bash" --gid "$$gid" --comment '' "$$username" || useradd -G tty -l -m -s "/bin/bash" --comment '' $$username )
20-
setcap -r /usr/local/bin/frankenphp
21-
chown -R $${username}:$${username} /data/caddy /config/caddy
22-
EOF
23-
ARG FRANKENPHP_XDEBUG=false
24-
RUN <<EOF
25-
set -eu -o pipefail
26-
if [ "$${FRANKENPHP_XDEBUG}" = "true" ]; then
27-
install-php-extensions xdebug
28-
{
29-
echo "zend_extension=xdebug.so";
30-
echo "xdebug.client_host=host.docker.internal";
31-
echo "xdebug.discover_client_host=1";
32-
echo "xdebug.client_port=9003";
33-
echo "xdebug.mode=debug,develop";
34-
echo "xdebug.start_with_request=yes";
35-
echo "xdebug.max_nesting_level=1000";
36-
} > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;
37-
fi
38-
EOF
39-
USER $${username}
8+
context: frankenphp
409
args:
4110
FRANKENPHP_DOCKER_IMAGE: ${FRANKENPHP_DOCKER_IMAGE:-dunglas/frankenphp:php8.3}
4211
FRANKENPHP_PHP_EXTENSIONS: ${FRANKENPHP_PHP_EXTENSIONS:-}

frankenphp/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ddev-generated
2+
ARG FRANKENPHP_DOCKER_IMAGE=scratch
3+
FROM ${FRANKENPHP_DOCKER_IMAGE}
4+
5+
SHELL ["/bin/bash", "-eu", "-o", "pipefail", "-c"]
6+
7+
# Install PHP extensions provided by user
8+
# Always install xdebug, but disable it by default
9+
ARG FRANKENPHP_PHP_EXTENSIONS=""
10+
RUN install-php-extensions xdebug ${FRANKENPHP_PHP_EXTENSIONS} && rm -f /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
11+
12+
# Add a new user and give it ownership of frankenphp related files
13+
ARG username
14+
ARG uid
15+
ARG gid
16+
RUN <<EOF
17+
getent group tty || groupadd tty
18+
(groupadd --gid $gid "$username" || groupadd "$username" || true) && (useradd -G tty -l -m -s "/bin/bash" --gid "$username" --comment '' --uid $uid "$username" || useradd -G tty -l -m -s "/bin/bash" --gid "$username" --comment '' "$username" || useradd -G tty -l -m -s "/bin/bash" --gid "$gid" --comment '' "$username" || useradd -G tty -l -m -s "/bin/bash" --comment '' $username )
19+
setcap -r /usr/local/bin/frankenphp
20+
chown -R ${username}:${username} /data/caddy /config/caddy
21+
EOF
22+
23+
# Enable xdebug on demand with custom DDEV config
24+
ARG FRANKENPHP_XDEBUG=false
25+
RUN <<EOF
26+
if [ "${FRANKENPHP_XDEBUG}" = "true" ]; then
27+
{
28+
echo "zend_extension=xdebug.so";
29+
echo "xdebug.client_host=host.docker.internal";
30+
echo "xdebug.discover_client_host=1";
31+
echo "xdebug.client_port=9003";
32+
echo "xdebug.mode=debug,develop";
33+
echo "xdebug.start_with_request=yes";
34+
echo "xdebug.max_nesting_level=1000";
35+
} > /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini;
36+
fi
37+
EOF
38+
39+
# Run FrankenPHP under created user
40+
USER ${username}

install.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ project_files:
55
- commands/frankenphp/php
66
- commands/host/xdebug
77
- docker-compose.frankenphp.yaml
8+
- frankenphp/Dockerfile
89

910
pre_install_actions:
1011
- |

tests/test.bats

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ setup() {
4242
export INSTALL_REDIS=false
4343
export FRANKENPHP_WORKER=false
4444
export TEST_DDEV_XDEBUG=false
45+
export FRANKENPHP_PHP_VERSION="8.3"
4546
}
4647

4748
health_checks() {
@@ -57,7 +58,7 @@ health_checks() {
5758
assert_success
5859
assert_output --partial "HTTP/1.1 200"
5960
assert_output --partial "Server: Caddy"
60-
assert_output --partial "X-Powered-By: PHP/8.3"
61+
assert_output --partial "X-Powered-By: PHP/${FRANKENPHP_PHP_VERSION}"
6162

6263
if [[ "${FRANKENPHP_WORKER}" == "true" ]]; then
6364
assert_output --partial "X-Request-Count"
@@ -71,7 +72,7 @@ health_checks() {
7172
assert_success
7273
assert_output --partial "HTTP/1.1 200"
7374
assert_output --partial "Server: Caddy"
74-
assert_output --partial "X-Powered-By: PHP/8.3"
75+
assert_output --partial "X-Powered-By: PHP/${FRANKENPHP_PHP_VERSION}"
7576

7677
if [[ "${FRANKENPHP_WORKER}" == "true" ]]; then
7778
assert_output --partial "X-Request-Count"
@@ -85,7 +86,7 @@ health_checks() {
8586
assert_success
8687
assert_output --partial "HTTP/2 200"
8788
assert_output --partial "server: Caddy"
88-
assert_output --partial "x-powered-by: PHP/8.3"
89+
assert_output --partial "x-powered-by: PHP/${FRANKENPHP_PHP_VERSION}"
8990

9091
if [[ "${FRANKENPHP_WORKER}" == "true" ]]; then
9192
assert_output --partial "x-request-count"
@@ -138,7 +139,7 @@ health_checks() {
138139

139140
run ddev php -v
140141
assert_success
141-
assert_output --partial "PHP 8.3"
142+
assert_output --partial "PHP ${FRANKENPHP_PHP_VERSION}"
142143

143144
run ddev php --ini
144145
assert_success
@@ -194,6 +195,26 @@ teardown() {
194195
health_checks
195196
}
196197

198+
@test "install from directory php8.4" {
199+
set -eu -o pipefail
200+
201+
export FRANKENPHP_PHP_VERSION="8.4"
202+
203+
cp "${DIR}"/tests/testdata/index-no-worker.php index.php
204+
assert_file_exist index.php
205+
206+
run ddev dotenv set .ddev/.env.frankenphp --frankenphp-docker-image="dunglas/frankenphp:php${FRANKENPHP_PHP_VERSION}"
207+
assert_success
208+
assert_file_exist .ddev/.env.frankenphp
209+
210+
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
211+
run ddev add-on get "${DIR}"
212+
assert_success
213+
run ddev restart -y
214+
assert_success
215+
health_checks
216+
}
217+
197218
@test "worker" {
198219
set -eu -o pipefail
199220

0 commit comments

Comments
 (0)