diff --git a/.gitignore b/.gitignore index f03762d1..3ad22315 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ src-tmp/ ./qit _tests/**/*.zip _tests/**/*.txt -dev/ \ No newline at end of file +dev/ +_build/docker/php83/xdebug/* +!_build/docker/php83/xdebug/.gitkeep +!_build/docker/php83/xdebug/README.md \ No newline at end of file diff --git a/Makefile b/Makefile index 7aee60c3..14c813da 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ # ROOT Set this to 1 to run the command as root. ## ROOT ?= 0 +DEBUG ?= 0 ARGS ?= ifeq (1, $(ROOT)) @@ -12,17 +13,20 @@ else DOCKER_USER ?= "$(shell id -u):$(shell id -g)" endif -## Run a command inside an alpine PHP 7 CLI image. +## Run a command inside an alpine PHP 8 CLI image. ## 1. Command to execute, eg: "./vendor/bin/phpcs" 2. Working dir (optional) define execPhpAlpine - @docker images -q | grep qit-cli-php || docker build -t qit-cli-php ./_build/docker/php74 - docker run --rm \ - --user $(DOCKER_USER) \ - -v "${PWD}:/app" \ - --env QIT_HOME=/tmp \ - --workdir "$(2:=/)" \ - qit-cli-php \ - bash -c "php -d memory_limit=1G $(1)" + @docker image inspect qit-cli-php-xdebug > /dev/null 2>&1 || docker build --build-arg CI=${CI} -t qit-cli-php-xdebug ./_build/docker/php83 + docker run --rm \ + --user $(DOCKER_USER) \ + -v "${PWD}:/app" \ + -v "${PWD}/_build/docker/php83/ini:/usr/local/etc/php/conf.d/" \ + --env QIT_HOME=/tmp \ + --env PHP_IDE_CONFIG=serverName=qit_cli \ + --workdir "$(2:=/)" \ + --add-host host.docker.internal:host-gateway \ + qit-cli-php-xdebug \ + bash -c "php -d xdebug.start_with_request=$(if $(filter 1,$(DEBUG)),yes,no) -d memory_limit=1G $(1)" endef watch: diff --git a/_build/docker/php74/Dockerfile b/_build/docker/php74/Dockerfile deleted file mode 100644 index 2ffaff5b..00000000 --- a/_build/docker/php74/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM php:7.4-cli - -RUN apt-get update \ - && apt-get install -y libzip-dev \ - && docker-php-ext-install zip diff --git a/_build/docker/php83/Dockerfile b/_build/docker/php83/Dockerfile new file mode 100644 index 00000000..c433f4be --- /dev/null +++ b/_build/docker/php83/Dockerfile @@ -0,0 +1,12 @@ +FROM php:8.3-cli + +ARG CI + +RUN apt-get update \ + && apt-get install -y libzip-dev \ + && docker-php-ext-install zip + +# Install Xdebug only if not in CI environment +RUN if [ "$CI" != "true" ]; then \ + pecl install xdebug && docker-php-ext-enable xdebug; \ + fi \ No newline at end of file diff --git a/_build/docker/php83/ini/xdebug.ini b/_build/docker/php83/ini/xdebug.ini new file mode 100644 index 00000000..d71956be --- /dev/null +++ b/_build/docker/php83/ini/xdebug.ini @@ -0,0 +1,19 @@ +zend_extension=xdebug.so +xdebug.client_host = host.docker.internal +xdebug.client_port = 9003 +xdebug.output_dir = /app/_build/docker/php83/xdebug/output +xdebug.log = /app/_build/docker/php83/xdebug/xdebug.log +# Enabled at runtime with DEBUG=1 +xdebug.start_with_request = no + +# https://xdebug.org/docs/all_settings#trace_output_name +xdebug.profiler_output_name = cachegrind.out.%R.%s + +# Having issues? Set this to 7 and check the xdebug.log +xdebug.log_level = 0 + +; Choose between debug or profile. +; If choosing "profile", the cachegrind files will be saved in the "www" directory. +; You can analyze them with PHPStorm, KCacheGrind, QCachegrind, WinCacheGrind, Webgrind, etc. +xdebug.mode = debug +;xdebug.mode=profile \ No newline at end of file diff --git a/_build/docker/php83/ini/zip.ini b/_build/docker/php83/ini/zip.ini new file mode 100644 index 00000000..b3df5138 --- /dev/null +++ b/_build/docker/php83/ini/zip.ini @@ -0,0 +1,2 @@ +# Enable zip extension +extension=zip.so \ No newline at end of file diff --git a/_build/docker/php83/xdebug/.gitkeep b/_build/docker/php83/xdebug/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/_build/docker/php83/xdebug/README.md b/_build/docker/php83/xdebug/README.md new file mode 100644 index 00000000..64f50575 --- /dev/null +++ b/_build/docker/php83/xdebug/README.md @@ -0,0 +1,10 @@ +## Xdebug instructions + +### PHPStorm + +- Settings -> Servers -> + (Add) + - Name: `qit_cli` + - Host: `-` (Any value) + - [X] Use path mappings + - File/Directory: The root dir of this project + - Absolute path on the server: `/app` \ No newline at end of file