Skip to content
This repository has been archived by the owner on Jan 17, 2022. It is now read-only.

Commit

Permalink
build(docker): Provide configuration for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
k911 committed Apr 1, 2019
1 parent 1d7a65c commit d4f630a
Show file tree
Hide file tree
Showing 6 changed files with 621 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*
!/src
!/tests
!composer.json
!composer.lock
!phpstan.neon.dist
!phpstan.tests.neon
!phpunit.xml
!.php_cs.dist
90 changes: 90 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
ARG ALPINE_TAG="3.8"
ARG PHP_TAG="7.2-cli-alpine3.8"

FROM php:$PHP_TAG as ext-builder
RUN docker-php-source extract && \
apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS

FROM ext-builder as ext-inotify
RUN pecl install inotify && \
docker-php-ext-enable inotify

FROM ext-builder as ext-pcntl
RUN docker-php-ext-install pcntl

FROM ext-builder as ext-xdebug
RUN pecl install xdebug && \
docker-php-ext-enable xdebug

FROM ext-builder as ext-swoole
ARG SWOOLE_VERSION=4.2.13
RUN pecl install swoole-$SWOOLE_VERSION && \
docker-php-ext-enable swoole

FROM composer:latest as app-installer
WORKDIR /usr/src/app
RUN composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative --ansi
COPY composer.json composer.lock ./
RUN composer validate
ARG COMPOSER_ARGS=install
RUN composer "$COMPOSER_ARGS" --prefer-dist --ignore-platform-reqs --no-progress --no-suggest --no-scripts --no-autoloader --ansi
COPY . ./
RUN composer dump-autoload --classmap-authoritative --ansi

FROM php:$PHP_TAG as base
RUN apk add --no-cache libstdc++
WORKDIR /usr/src/app
COPY --from=ext-swoole /usr/local/lib/php/extensions/no-debug-non-zts-20170718/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/swoole.so
COPY --from=ext-swoole /usr/local/etc/php/conf.d/docker-php-ext-swoole.ini /usr/local/etc/php/conf.d/docker-php-ext-swoole.ini
COPY --from=ext-inotify /usr/local/lib/php/extensions/no-debug-non-zts-20170718/inotify.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/inotify.so
COPY --from=ext-inotify /usr/local/etc/php/conf.d/docker-php-ext-inotify.ini /usr/local/etc/php/conf.d/docker-php-ext-inotify.ini
COPY --from=ext-pcntl /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pcntl.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pcntl.so
COPY --from=ext-pcntl /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini /usr/local/etc/php/conf.d/docker-php-ext-pcntl.ini

FROM base as base-with-xdebug
COPY --from=ext-xdebug /usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
COPY --from=ext-xdebug /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

FROM base as base-cli
COPY --from=app-installer /usr/src/app ./

FROM base as base-server
RUN apk add --no-cache bash
COPY --from=app-installer /usr/src/app ./

FROM base-with-xdebug as base-coverage
ENV COVERAGE=1
COPY --from=app-installer /usr/src/app ./

FROM base-with-xdebug as base-server-coverage
RUN apk add --no-cache bash
ENV COVERAGE=1
COPY --from=app-installer /usr/src/app ./

FROM base-cli as Cli
ENTRYPOINT ["./tests/Fixtures/Symfony/app/console"]
CMD ["swoole:server:run"]

FROM base-cli as Composer
ENV COMPOSER_ALLOW_SUPERUSER=1
COPY --from=app-installer /usr/bin/composer /usr/local/bin/composer
ENTRYPOINT ["composer"]
CMD ["test"]

FROM base-coverage as ComposerCoverage
ENV COMPOSER_ALLOW_SUPERUSER=1
COPY --from=app-installer /usr/bin/composer /usr/local/bin/composer
ENTRYPOINT ["composer"]
CMD ["code-coverage"]

FROM base-server as Server
WORKDIR /usr/src/app/tests/Server
ENTRYPOINT ["/bin/bash"]
CMD ["../run-server-tests.sh"]

FROM base-server-coverage as ServerCoverage
WORKDIR /usr/src/app/tests/Server
ENV APP_ENV=cov \
SWOOLE_ALLOW_XDEBUG=1
ENTRYPOINT ["/bin/bash"]
CMD ["../run-server-tests.sh"]
29 changes: 18 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
],
"license": "MIT",
"homepage": "https://github.com/k911/swoole-bundle",
"authors": [
{
"name": "Konrad Obal",
"email": "konrad.obal@gmail.com",
"homepage": "https://github.com/k911"
}
],
"authors": [{
"name": "Konrad Obal",
"email": "konrad.obal@gmail.com",
"homepage": "https://github.com/k911"
}],
"require": {
"php": "^7.2",
"ext-swoole": "^4",
Expand Down Expand Up @@ -72,12 +70,21 @@
"console": [
"php tests/Fixtures/Symfony/app/console --ansi"
],
"static-analyse-src": [
"phpstan analyze src -l 7 --ansi"
],
"static-analyse-tests": [
"phpstan analyze tests -l 4 -c phpstan.tests.neon --ansi"
],
"cs-analyse": [
"php-cs-fixer fix -v --dry-run --diff --stop-on-violation --ansi"
],
"analyse": [
"phpstan analyze src -l 7 --ansi",
"@static-analyse-src",
"",
"phpstan analyze tests -l 4 -c phpstan.tests.neon --ansi",
"@static-analyse-tests",
"",
"php-cs-fixer fix -v --dry-run --diff --stop-on-violation --ansi"
"@cs-analyse"
],
"test": [
"@analyse",
Expand All @@ -93,7 +100,7 @@
"COVERAGE=1 phpunit tests/Feature --coverage-php cov/feature-tests.cov --colors=always --process-isolation"
],
"merge-code-coverage": [
"phpcov merge cov --clover clover.xml"
"phpcov merge cov --clover=clover.xml"
],
"fix": "php-cs-fixer fix -v --ansi",
"unit-tests": [
Expand Down
Loading

0 comments on commit d4f630a

Please sign in to comment.