Configure xDebug on Docker
laceysanderson opened this issue ยท 8 comments
It would be nice to configure xdebug on our docker images.
I started work on this but ran out of time to finish... here is my current progress:
From c67e805434f7002aba0233b68b0b28c1d561bbff Mon Sep 17 00:00:00 2001
From: Lacey Sanderson <laceyannesanderson@gmail.com>
Date: Fri, 10 Dec 2021 12:41:04 -0600
Subject: [PATCH 1/2] Configure XDebug.
---
Dockerfile | 5 ++++-
tripaldocker/default_files/xdebug/xdebug.ini | 6 ++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 tripaldocker/default_files/xdebug/xdebug.ini
diff --git a/Dockerfile b/Dockerfile
index c5bc9f1ea..8b09cd3d8 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -53,7 +53,10 @@ RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
## Xdebug
RUN pecl install xdebug-3.0.1 \
&& docker-php-ext-enable xdebug \
- && echo "xdebug.mode = coverage" >> /usr/local/etc/php/php.ini
+ && echo "xdebug.mode = coverage" >> /usr/local/etc/php/php.ini \
+ && echo "error_reporting=E_ALL" >> /usr/local/etc/php/conf.d/error_reporting.ini \
+ && cp /app/tripaldocker/default_files/xdebug/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
+
## install the PHP extensions we need
RUN set -eux; \
\
diff --git a/tripaldocker/default_files/xdebug/xdebug.ini b/tripaldocker/default_files/xdebug/xdebug.ini
new file mode 100644
index 000000000..9c37b9c13
--- /dev/null
+++ b/tripaldocker/default_files/xdebug/xdebug.ini
@@ -0,0 +1,6 @@
+zend_extension=xdebug
+
+[xdebug]
+xdebug.mode=develop,debug
+xdebug.client_host=host.docker.internal
+xdebug.start_with_request=yes
From 0b795e99c39a453b29626cdb9cb9fca7e91d95dd Mon Sep 17 00:00:00 2001
From: Lacey Sanderson <laceyannesanderson@gmail.com>
Date: Fri, 10 Dec 2021 14:41:53 -0600
Subject: [PATCH 2/2] more work on xdebug
---
Dockerfile | 7 ++++---
tripaldocker/default_files/xdebug/xdebug.ini | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 8b09cd3d8..900aaf3d4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -50,12 +50,13 @@ RUN echo "listen_addresses='*'" >> /etc/postgresql/11/main/postgresql.conf \
########## PHP EXTENSIONS #####################################################
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
+
## Xdebug
RUN pecl install xdebug-3.0.1 \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.mode = coverage" >> /usr/local/etc/php/php.ini \
&& echo "error_reporting=E_ALL" >> /usr/local/etc/php/conf.d/error_reporting.ini \
- && cp /app/tripaldocker/default_files/xdebug/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
+ && cp /app/tripaldocker/default_files/xdebug/xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
## install the PHP extensions we need
RUN set -eux; \
@@ -200,7 +201,7 @@ RUN ln -s /var/www/drupal8/vendor/drupal/console/bin/drupal /usr/local/bin/ \
## Set the working directory to DRUPAL_ROOT
WORKDIR /var/www/drupal8/web
-## Expose http and psql port
-EXPOSE 80 5432
+## Expose http, xdebug and psql port
+EXPOSE 80 5432 9003
ENTRYPOINT ["init.sh"]
diff --git a/tripaldocker/default_files/xdebug/xdebug.ini b/tripaldocker/default_files/xdebug/xdebug.ini
index 9c37b9c13..333a80641 100644
--- a/tripaldocker/default_files/xdebug/xdebug.ini
+++ b/tripaldocker/default_files/xdebug/xdebug.ini
@@ -1,6 +1,6 @@
zend_extension=xdebug
[xdebug]
-xdebug.mode=develop,debug
+xdebug.mode=coverage,develop,debug,profile
xdebug.client_host=host.docker.internal
xdebug.start_with_request=yes
I'm going to be taking a look at this, I've used xdebug in the past.
My intention is to enable it so that an IDE with xdebug capability can open the t4d8 directory on the host and have the Dockerized Drupal/Tripal instance connect to it. This would cover the 'debug' mode which includes step debugging.
In addition to that, I also see 'coverage' as a desired xdebug mode. I can try to integrate that into the PHPUnit configuration. However, currently trying to run PHPUnit in the docker with the command from this page
docker exec --workdir=/var/www/drupal9/web/modules/contrib/tripal t4d8 phpunit
results in this message:
Drupal requires Prophecy PhpUnit when using PHPUnit 9 or greater. Please use 'composer require --dev phpspec/prophecy-phpunit:^2' to ensure that it is present.
I'm looking into Prophecy phpunit now
Edit: prophecy-phpunit should be installed per the Dockerfile but it is not, investigating currently. This may require an additional issue
The previous issues were fixed by altering the commands that I used to build and run the Docker.
Working on the coverage aspect of this, what utilities do we want to provide from this? Currently, we can generate a coverage report for the entire codebase when PHPUnit is run as well as generate coverage reports for individual page loads. Both options generate kcachegrind files, which aren't very human readable. Is there any recommended software that we can suggest or include with the configuration in order to read these?
I'm also going to add a function to disable xdebug in the docker. Running phpunit tests normally takes 15-20 minutes on modest hardware and over 4 hours with xdebug enabled on the same hardware.
Working on the coverage aspect of this, what utilities do we want to provide from this? Currently, we can generate a coverage report for the entire codebase when PHPUnit is run as well as generate coverage reports for individual page loads. Both options generate kcachegrind files, which aren't very human readable. Is there any recommended software that we can suggest or include with the configuration in order to read these?
For code coverage we were mostly focusing on Code Climate which does seem to already be working in the main branch: https://codeclimate.com/github/tripal/t4d8. So we just need to maintain that functionality. I don't think any additional functionality is needed.
OK. In that case, I will remove the coverage option from xdebug since it is handled by Code Climate.
I was a little mixed up in my earlier comments. It is the profiling option that generates the kcachegrind files, not coverage. Shall we proceed with profiling?
The PR configuring Xdebug + documenting it's use has been merged ๐ Thanks @Ferrisx4