Skip to content

feat: add separate phpfpm container dedicated to xdebug #1355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 3 additions & 62 deletions compose/bin/debug-cli
Original file line number Diff line number Diff line change
@@ -1,62 +1,3 @@
#!/bin/bash
S=$(bin/clinotty cat /usr/local/etc/php/php.ini | grep -iGc 'xdebug.mode = off');
R=$(grep -c 'XDEBUG_CONFIG=idekey' ./env/phpfpm.env)

if [[ -z "$2" ]]
then
platform="PHPSTORM"
else
platform=$2
fi

local_debug_status(){
if [[ $R != 0 ]]; then
echo "Cli debug enabled"
else
echo "Cli debug disabled"
fi
}

local_debug_toggle() {
if [[ $R != 0 ]]; then
local_debug_disable
else
local_debug_enable
fi
}

local_debug_enable() {
if [[ $S == 1 ]]; then
bin/xdebug enable
fi

if [[ $R != 0 ]]; then
echo "Already enabled"
exit 0
fi

echo "XDEBUG_CONFIG=idekey=$platform" >> ./env/phpfpm.env
sleep 1
bin/restart phpfpm
echo "Cli debug enabled"
}

local_debug_disable() {
sed -i '' '/XDEBUG_CONFIG=idekey/d' ./env/phpfpm.env
sleep 1
bin/restart phpfpm
echo "Cli debug disabled"
}

firstArgLetter="$(echo "$1" | head -c 1)"
if [[ $firstArgLetter == "d" ]]; then
local_debug_disable
elif [[ $firstArgLetter == "e" ]]; then
local_debug_enable
elif [[ $firstArgLetter == "t" ]]; then
local_debug_toggle
elif [[ $firstArgLetter == "s" ]]; then
local_debug_status
else
printf "Please specify either 'disable', 'enable', 'status' or 'toggle' as mandatory argument.\nSpecify as an optional second argument the platform. Default is PHPSTORM\nEx: bin/debug-cli enable [PHPSTORM]\n"
fi
#!/usr/bin/env bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
bin/docker-compose exec phpfpm-xdebug "$@"
53 changes: 0 additions & 53 deletions compose/bin/xdebug

This file was deleted.

5 changes: 4 additions & 1 deletion compose/compose.dev-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ services:
- ./src:/var/www/html:cached

phpfpm:
volumes: *appvolumes
volumes: *appvolumes

phpfpm-xdebug:
volumes: *appvolumes

phpmyadmin:
image: linuxserver/phpmyadmin
Expand Down
3 changes: 3 additions & 0 deletions compose/compose.dev-ssh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ services:
phpfpm:
volumes: *appvolumes

phpfpm-xdebug:
volumes: *appvolumes

ssh:
image: markoshust/ssh
ports:
Expand Down
3 changes: 3 additions & 0 deletions compose/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ services:
phpfpm:
volumes: *appvolumes

phpfpm-xdebug:
volumes: *appvolumes

phpmyadmin:
image: linuxserver/phpmyadmin
env_file: env/db.env
Expand Down
13 changes: 13 additions & 0 deletions compose/compose.healthcheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ services:
#elasticsearch:
# condition: service_healthy

phpfpm-xdebug:
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
opensearch:
condition: service_healthy
rabbitmq:
condition: service_healthy
#elasticsearch:
# condition: service_healthy

db:
healthcheck:
test: "mysqladmin ping -h localhost -u root -pmagento || mariadb-admin ping -h localhost -u root -pmagento"
Expand Down
21 changes: 19 additions & 2 deletions compose/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

services:
app:
image: markoshust/magento-nginx:1.24-0
# image: markoshust/magento-nginx:1.24-0
build:
context: ./images/nginx/1.24
dockerfile: Dockerfile
Comment on lines +15 to +18
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markshust This should be replaced with dedicated image build

ports:
- "80:8000"
- "443:8443"
Expand All @@ -30,11 +33,25 @@ services:
#- "host.docker.internal:host-gateway"

phpfpm:
image: markoshust/magento-php:8.3-fpm-4
# image: markoshust/magento-php:8.3-fpm-4
build:
context: ./images/php/8.3
dockerfile: Dockerfile
Comment on lines +36 to +39
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markshust This should be replaced with dedicated image build

volumes: *appvolumes
env_file: env/phpfpm.env
#extra_hosts: *appextrahosts

phpfpm-xdebug:
# image: markoshust/magento-php:8.3-fpm-4
build:
context: ./images/php/8.3-xdebug
dockerfile: Dockerfile
Comment on lines +45 to +48
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markshust This should be replaced with dedicated image build

volumes: *appvolumes
env_file:
- env/phpfpm.env
- env/phpfpm-xdebug.env
#extra_hosts: *appextrahosts

db:
image: mariadb:11.4
command:
Expand Down
2 changes: 2 additions & 0 deletions compose/env/phpfpm-xdebug.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PHP_IDE_CONFIG="serverName=docker-magento"
XDEBUG_MODE=develop,debug
2 changes: 1 addition & 1 deletion compose/env/phpfpm.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=
COMPOSER_DISABLE_XDEBUG_WARN=1
PHP_CS_FIXER_IGNORE_ENV=1
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
13 changes: 11 additions & 2 deletions images/nginx/1.24/conf/default.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
upstream fastcgi_backend {
server unix:/sock/docker.sock;
upstream fastcgi_phpfpm {
server unix:/sock/phpfpm.sock;
}

upstream fastcgi_phpfpm_xdebug {
server unix:/sock/phpfpm-xdebug.sock;
}

map $cookie_XDEBUG_SESSION $fastcgi_backend {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I mentioned in the description is that mapping requires to put $ sign when assigned to variable. There is a logic which copies nginx.conf.sample to nginx.conf but this sample file has

fastcgi_pass   fastcgi_backend;

but it should be

fastcgi_pass   $fastcgi_backend;

The occurence is repeated 3 times - perhaps some post-script with sed that would replace it?

default fastcgi_phpfpm;
PHPSTORM fastcgi_phpfpm_xdebug;
}

server {
Expand Down
111 changes: 111 additions & 0 deletions images/php/8.3-xdebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
FROM php:8.3-fpm-bookworm
LABEL maintainer="Mark Shust <[email protected]>"

ARG APP_ID=1000
RUN groupadd -g "$APP_ID" app \
&& useradd -g "$APP_ID" -u "$APP_ID" -d /var/www -s /bin/bash app

RUN mkdir -p /etc/nginx/html /var/www/html /sock \
&& chown -R app:app /etc/nginx /var/www /usr/local/etc/php/conf.d /sock

RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash -

RUN apt-get update && apt-get install -y \
cron \
default-mysql-client \
git \
gnupg \
gzip \
libbz2-dev \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libmagickwand-dev \
libmcrypt-dev \
libonig-dev \
libpng-dev \
libsodium-dev \
libssh2-1-dev \
libwebp-dev \
libxslt1-dev \
libzip-dev \
lsof \
mailutils \
msmtp \
nodejs \
procps \
rsync \
strace \
vim \
zip \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

RUN pecl channel-update pecl.php.net && pecl install \
redis-6.2.0 \
ssh2-1.4.1 \
swoole-6.0.2 \
xdebug-3.4.2 \
imagick-3.8.0RC2 \
&& pecl clear-cache \
&& rm -rf /tmp/pear

RUN docker-php-ext-configure \
gd --with-freetype --with-jpeg --with-webp \
&& docker-php-ext-install \
bcmath \
bz2 \
calendar \
exif \
ftp \
gd \
gettext \
intl \
mbstring \
mysqli \
opcache \
pcntl \
pdo_mysql \
soap \
sockets \
sodium \
sysvmsg \
sysvsem \
sysvshm \
xsl \
zip \
&& docker-php-ext-enable \
imagick \
redis \
ssh2 \
xdebug

RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& architecture=$(uname -m) \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/$architecture/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz

RUN git clone --branch v0.4.18 --depth=1 https://github.com/NoiseByNorthwest/php-spx.git /usr/lib/php-spx \
&& cd /usr/lib/php-spx \
&& phpize \
&& ./configure \
&& make \
&& make install

RUN curl -sS https://getcomposer.org/installer | \
php -- --version=2.8.6 --install-dir=/usr/local/bin --filename=composer

COPY conf/blackfire.ini $PHP_INI_DIR/conf.d/blackfire.ini
COPY conf/spx.ini $PHP_INI_DIR/conf.d/spx.ini
COPY conf/msmtprc /etc/msmtprc
COPY conf/php.ini $PHP_INI_DIR
COPY conf/php-xdebug.ini $PHP_INI_DIR/conf.d/
COPY conf/php-fpm.conf /usr/local/etc/
COPY conf/www.conf /usr/local/etc/php-fpm.d/

USER app:app
VOLUME /var/www
WORKDIR /var/www/html
2 changes: 2 additions & 0 deletions images/php/8.3-xdebug/conf/blackfire.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extension=blackfire.so
blackfire.agent_socket=tcp://blackfire:8307
4 changes: 4 additions & 0 deletions images/php/8.3-xdebug/conf/msmtprc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
account default
host mailcatcher
port 1025
from "[email protected]"
34 changes: 34 additions & 0 deletions images/php/8.3-xdebug/conf/php-fpm.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; This file was initially adapted from the output of: (on PHP 5.6)
; grep -vE '^;|^ *$' /usr/local/etc/php-fpm.conf.default

[global]

error_log = /proc/self/fd/2
daemonize = no

[www]

; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2

;user = app
;group = app

listen = /sock/phpfpm-xdebug.sock
listen.owner = app
listen.group = app
listen.mode = 0660

pm = dynamic
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6

clear_env = no

; Ensure worker stdout and stderr are sent to the main error log.
catch_workers_output = yes

; This needed to make PHP-SPX work in fpm mode.
process.dumpable = yes
Loading