diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100755 index 0000000..83ba47b --- /dev/null +++ b/.docker/Dockerfile @@ -0,0 +1,26 @@ +FROM php:7.3-cli-alpine + +ENV PROJECT_ROOT="/code" + +WORKDIR ${PROJECT_ROOT} +ADD . ${PROJECT_ROOT} + +# Install additional packages +RUN apk update \ + && apk upgrade \ + && apk add --no-cache $PHPIZE_DEPS php7-dev bash composer + +# Install XDebug +RUN pecl install xdebug \ + && docker-php-ext-enable xdebug \ + && echo xdebug.remote_enable=1 >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo xdebug.remote_autostart=0 >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo xdebug.remote_connect_back=1 >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo xdebug.remote_port=9000 >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ + && echo xdebug.remote_log=/tmp/php7-xdebug.log >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + +# Composer +RUN composer self-update +RUN composer install + +ENTRYPOINT ["/code/.docker/bin/run"] diff --git a/.docker/bin/run b/.docker/bin/run new file mode 100755 index 0000000..20736eb --- /dev/null +++ b/.docker/bin/run @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +if [[ $# -eq 0 ]] + then + cd /code && composer install +fi + +INTERNAL_HOST_IP=$(ip route show default | awk '/default/ {print $3}') + +sed -i '/remote_host=/d' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini +echo "xdebug.remote_host=${INTERNAL_HOST_IP}" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini + +$@ diff --git a/README.md b/README.md index b53734c..7db1ad6 100644 --- a/README.md +++ b/README.md @@ -92,3 +92,30 @@ Now you can simply get `SlimApplicationFactory` class from your DI Container (or $factory = $container->getByType(SlimApplicationFactory::class); $factory->create()->run(); ``` + +## Development +### Docker :heart: +Because no one likes to install or change his own environment for someone else's code, you can use Docker and run tests inside Docker. + +To build and prepare the docker image, you can run the command bellow. +```bash +docker-compose build slim-nette-extension +``` + +You can run command bellow to run `composer install`. +```bash +docker-compose run slim-nette-extension +``` + +OR + +If you want to run `composer update` or one of the scripts defined inside `composer.json`, you can use one of these commands bellow. +```bash +docker-compose run slim-nette-extension composer update +docker-compose run slim-nette-extension composer lint +docker-compose run slim-nette-extension composer phpcs +docker-compose run slim-nette-extension composer phpcbf +docker-compose run slim-nette-extension composer phpstan +docker-compose run slim-nette-extension composer tests +docker-compose run slim-nette-extension composer tests-debug +``` diff --git a/composer.json b/composer.json index e3a4124..5721505 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "phpcs": "./vendor/bin/phpcs --ignore=\"tests/temp/*\" --standard=ruleset.xml src tests", "phpcbf": "./vendor/bin/phpcbf --standard=ruleset.xml src tests", "phpstan": "./vendor/bin/phpstan analyse src tests", - "test": "./vendor/bin/phpunit tests" + "tests": "./vendor/bin/phpunit tests", + "tests-debug": "XDEBUG_CONFIG='idekey=PHPSTORM remote_autostart=1' PHP_IDE_CONFIG='serverName=default' ./vendor/bin/phpunit tests --stop-on-failure" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b594dbf --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: "2" +services: + slim-nette-extension: + build: + context: . + dockerfile: .docker/Dockerfile + volumes: + - .:/code