Skip to content

Commit 9d64267

Browse files
committed
Added docker environment for local development
1 parent cad4f75 commit 9d64267

File tree

5 files changed

+126
-15
lines changed

5 files changed

+126
-15
lines changed

Makefile

+36-15
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,55 @@ ifeq ($(XDEBUG),1)
66
XPHPARGS=-dzend_extension=xdebug.so -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1
77
endif
88

9+
# Run make with IN_DOCKER=1 to run yarn and php commands in a docker container
10+
DOCKER_PHP=
11+
DOCKER_NODE=
12+
IN_DOCKER=0
13+
ifeq ($(IN_DOCKER),1)
14+
DOCKER_PHP=docker-compose run --rm php
15+
DOCKER_NODE=docker-compose run --rm -w /app node
16+
endif
17+
918
all:
19+
@echo "the following commands are available:"
20+
@echo ""
21+
@echo "make check-style # check code style"
22+
@echo "make fix-style # fix code style"
23+
@echo "make install # install dependencies"
24+
@echo "make test # run PHPUnit tests"
25+
@echo "make lint # check validity of test data"
26+
@echo "make stan # check code with PHPStan"
27+
@echo ""
28+
@echo "You may add the IN_DOCKER parameter to run a command inside of docker container and not directly."
29+
@echo "make IN_DOCKER=1 ..."
30+
1031

1132
check-style: php-cs-fixer.phar
1233
PHP_CS_FIXER_IGNORE_ENV=1 ./php-cs-fixer.phar fix src/ --diff --dry-run
1334

1435
fix-style: php-cs-fixer.phar
15-
vendor/bin/indent --tabs composer.json
16-
vendor/bin/indent --spaces .php_cs.dist
17-
./php-cs-fixer.phar fix src/ --diff
36+
$(DOCKER_PHP) vendor/bin/indent --tabs composer.json
37+
$(DOCKER_PHP) vendor/bin/indent --spaces .php_cs.dist
38+
$(DOCKER_PHP) ./php-cs-fixer.phar fix src/ --diff
1839

19-
install:
20-
composer install --prefer-dist --no-interaction --no-progress --ansi
21-
yarn install
40+
install: composer.lock yarn.lock
41+
$(DOCKER_PHP) composer install --prefer-dist --no-interaction --no-progress --ansi
42+
$(DOCKER_NODE) yarn install
2243

2344
test:
24-
php $(PHPARGS) $(XPHPARGS) vendor/bin/phpunit --verbose --colors=always $(TESTCASE)
25-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
26-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
45+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) vendor/bin/phpunit --verbose --colors=always $(TESTCASE)
46+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
47+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
2748

2849
lint: install
29-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/reference/playlist.json
30-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
31-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
32-
yarn run speccy lint tests/spec/data/reference/playlist.json
33-
yarn run speccy lint tests/spec/data/recursion.json
50+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/reference/playlist.json
51+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
52+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
53+
$(DOCKER_NODE) yarn run speccy lint tests/spec/data/reference/playlist.json
54+
$(DOCKER_NODE) yarn run speccy lint tests/spec/data/recursion.json
3455

3556
stan:
36-
php $(PHPARGS) vendor/bin/phpstan analyse -l 5 src
57+
$(DOCKER_PHP) php $(PHPARGS) vendor/bin/phpstan analyse -l 5 src
3758

3859
# copy openapi3 json schema
3960
schemas/openapi-v3.0.json: vendor/oai/openapi-specification/schemas/v3.0/schema.json

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ This library is currently work in progress, the following list tracks completene
277277
- [x] OAuth Flow Object
278278
- [x] Security Requirement Object
279279

280+
# Development
281+
282+
You may use the docker environment for local development:
283+
284+
docker-compose build
285+
make IN_DOCKER=1 install
286+
make IN_DOCKER=1 test
287+
...
288+
289+
280290
# Support
281291

282292
**Need help with your API project?**

docker-compose.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3"
2+
services:
3+
php:
4+
build:
5+
dockerfile: tests/docker/Dockerfile
6+
context: .
7+
volumes:
8+
- ./tests/tmp/.composer:/root/.composer:rw
9+
- .:/app
10+
environment:
11+
- TZ=UTC
12+
- TIMEZONE=UTC
13+
- IN_DOCKER=docker
14+
- PHP_XDEBUG_ENABLED=1
15+
- XDEBUG_CONFIG="remote_host=host.docker.internal"
16+
- PHP_IDE_CONFIG="serverName=Docker"
17+
tty: true
18+
node:
19+
image: node:11
20+
volumes:
21+
# - ./tests/tmp/.composer:/root/.composer:rw
22+
- .:/app

tests/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/tmp

tests/docker/Dockerfile

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
FROM php:7.4-cli
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup && \
6+
echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache
7+
RUN apt-get update && \
8+
apt-get -y install \
9+
gnupg2 && \
10+
apt-key update && \
11+
apt-get update && \
12+
apt-get install -y --no-install-recommends \
13+
libzip-dev \
14+
libonig-dev \
15+
vim \
16+
git \
17+
unzip\
18+
libxml2-dev \
19+
curl \
20+
libcurl4-openssl-dev \
21+
libssl-dev \
22+
--no-install-recommends && \
23+
apt-get clean && \
24+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
25+
&& pecl install xdebug-2.9.6 \
26+
&& docker-php-ext-enable xdebug \
27+
&& docker-php-ext-install \
28+
zip \
29+
curl \
30+
mbstring
31+
32+
# Install composer
33+
ENV COMPOSER_ALLOW_SUPERUSER=1 \
34+
PHP_USER_ID=33 \
35+
PHP_ENABLE_XDEBUG=1 \
36+
COMPOSER_HOME=/root/.composer/ \
37+
PATH=/app:/app/vendor/bin:/root/.composer/vendor/bin:$PATH
38+
39+
RUN curl -o /tmp/composer-setup.php https://getcomposer.org/installer \
40+
&& curl -o /tmp/composer-setup.sig https://composer.github.io/installer.sig \
41+
# Make sure we're installing what we think we're installing!
42+
&& php -r "if (hash('SHA384', file_get_contents('/tmp/composer-setup.php')) !== trim(file_get_contents('/tmp/composer-setup.sig'))) { unlink('/tmp/composer-setup.php'); echo 'Invalid installer' . PHP_EOL; exit(1); }" \
43+
&& php /tmp/composer-setup.php --no-ansi --install-dir=/usr/local/bin --filename=composer \
44+
&& rm -f /tmp/composer-setup.*
45+
46+
# Enable Xdebug
47+
ENV XDEBUGINI_PATH=/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
48+
49+
RUN echo "xdebug.idekey=PHP_STORM" >> $XDEBUGINI_PATH && \
50+
echo "xdebug.default_enable=1" >> $XDEBUGINI_PATH && \
51+
echo "xdebug.remote_enable=1" >> $XDEBUGINI_PATH && \
52+
echo "xdebug.remote_connect_back=1" >> $XDEBUGINI_PATH && \
53+
echo "xdebug.remote_log=xdebug_remote.log" >> $XDEBUGINI_PATH && \
54+
echo "xdebug.remote_port=9000" >> $XDEBUGINI_PATH && \
55+
echo "xdebug.remote_autostart=1" >> $XDEBUGINI_PATH
56+
57+
WORKDIR /app

0 commit comments

Comments
 (0)