Skip to content

Commit

Permalink
ci: Configure xdebug (ankitpokhrel#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel authored Aug 16, 2020
1 parent f361297 commit bcb4119
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ infection.json.dist
infection-log.txt
.DS_Store
composer.lock
*.cache

/coverage/
/vendor/
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ We also have some utility scripts to re-create docker images.
Please note that `bin/rebuild.sh` will delete tus-php related docker containers and images.
It will also delete `uploads` folder and re-create it. So that when you use `bin/docker.sh`
it will be like a fresh start. This command is useful when you start to make changes
to docker configurations, server configrations.
to docker configurations, server configurations.

```shell
$ bin/rebuild.sh
Expand Down Expand Up @@ -479,11 +479,11 @@ Since the server supports tus expiration extension, a cron job is set to run onc
```
3. Run tests with phpunit
```shell
$ ./vendor/bin/phpunit
# or
$ composer test
# or
$ ./vendor/bin/phpunit
```
4. Validate changes against [PSR2 Coding Standards](http://www.php-fig.org/psr/psr-2/)
```shell
Expand All @@ -502,6 +502,8 @@ at project root. You can open `coverage/index.html` to checkout coverage report.
$ docker exec tus-php-server composer test-coverage
```

You can use `xdebug enable` and `xdebug disable` to enable and disable [Xdebug](https://xdebug.org/) inside the container.

### Questions about this project?
Please feel free to report any bug found. Pull requests, issues, and project recommendations are more than welcome!

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"sort-packages": true
},
"scripts": {
"test": "phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html ./coverage",
"test": "xdebug disable && vendor/bin/phpunit",
"test-coverage": "xdebug enable && vendor/bin/phpunit --coverage-html ./coverage",
"cs-fixer": "vendor/bin/php-cs-fixer fix",
"lint": "vendor/bin/php-cs-fixer fix --diff --dry-run"
},
Expand Down
14 changes: 7 additions & 7 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ LABEL maintainer="[email protected],[email protected]" \

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PHP_INI_DIR /etc/php/7.3
ENV COMPOSER_ALLOW_SUPERUSER 1

ADD https://repos.php.earth/alpine/phpearth.rsa.pub /etc/apk/keys/phpearth.rsa.pub

Expand All @@ -22,17 +24,15 @@ RUN apk update && apk add --no-cache \
php7.3-pear \
composer

# Install APCu extension
RUN pecl upgrade apcu
# Install APCu and Xdebug extension.
RUN pecl upgrade apcu xdebug

## Xdebug Installation, Currently Alpine repo is missing Php7.4-xdebug,
# RUN apk add --no-cache php7.4-xdebug
COPY ./bin/xdebug.sh /bin/xdebug
RUN chmod +x /bin/xdebug

COPY ./configs/nginx.conf /etc/nginx/nginx.conf

ENV PHP_INI_DIR /etc/php/7.3

COPY ./configs/php.ini $PHP_INI_DIR/php.ini
COPY ./configs/xdebug.ini $PHP_INI_DIR/conf.d/00_xdebug.disable
COPY ./configs/www.conf $PHP_INI_DIR/php-fpm.d/www.conf

ENTRYPOINT [ "sh" ]
34 changes: 34 additions & 0 deletions docker/base/bin/xdebug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

XDEBUG_CONFIG=/etc/php/7.3/conf.d/00_xdebug

enable()
{
if [[ -f ${XDEBUG_CONFIG}.disable ]]; then
mv ${XDEBUG_CONFIG}.disable ${XDEBUG_CONFIG}.ini;
echo "Xdebug enabled";
fi
}

disable()
{
if [[ -f ${XDEBUG_CONFIG}.ini ]]; then
mv ${XDEBUG_CONFIG}.ini ${XDEBUG_CONFIG}.disable;
echo "Xdebug disabled";
fi
}

case "$1" in
(enable)
enable
exit 0
;;
(disable)
disable
exit 0
;;
(*)
echo "Usage: $0 {enable|disable}"
exit 2
;;
esac
4 changes: 2 additions & 2 deletions docker/base/configs/php.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
serialize_precision = -1
disable_functions = exec,passthru,shell_exec,system,popen,parse_ini_file,show_source
disable_functions = exec,passthru,shell_exec,system,popen,show_source
zend.enable_gc = On
expose_php = Off
max_execution_time = 300
Expand Down Expand Up @@ -60,7 +60,7 @@ session.use_trans_sid = 0
session.sid_length = 26
session.trans_sid_tags = "a=href,area=href,frame=src,form="
session.sid_bits_per_character = 5
extension=apcu.so
[APCu Cache]
extension = apcu.so
apc.enabled = 1
apc.enable_cli = 1
7 changes: 7 additions & 0 deletions docker/base/configs/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
zend_extension = xdebug.so
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.remote_host = host.docker.internal
xdebug.remote_port = 9999
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = /var/log/xdebug
14 changes: 8 additions & 6 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ services:
ports:
- 8081:80
volumes:
- ../:/var/www/
- ../example:/var/www/html
- ./.data/server/logs:/var/log/nginx
- ../:/var/www:delegated
- ../example:/var/www/html:delegated
- ./.data/server/logs:/var/log/nginx:delegated
- ./.data/server/xdebug:/var/log/xdebug:delegated
entrypoint: entrypoint.sh
labels:
tag: tus-php-server
Expand All @@ -22,9 +23,10 @@ services:
ports:
- 8080:80
volumes:
- ../:/var/www
- ../example:/var/www/html
- ./.data/client/logs:/var/log/nginx
- ../:/var/www:delegated
- ../example:/var/www/html:delegated
- ./.data/client/logs:/var/log/nginx:delegated
- ./.data/server/xdebug:/var/log/xdebug:delegated
labels:
tag: tus-php-client
group: tus-php
Expand Down

0 comments on commit bcb4119

Please sign in to comment.