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

Dockerize #39

Merged
merged 3 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,134 @@
version: 2.1

aliases:
# Steps
- &dump-env-vars
run:
name: Dump env for hash
command: |-
echo "PHP_VERSION=$PHP_VERSION" >> dumped.env;
echo "ALPINE_VERSION=$ALPINE_VERSION" >> dumped.env;
echo "PHP_API_VERSION=$PHP_API_VERSION" >> dumped.env;
echo "COMPOSER_ARGS=$COMPOSER_ARGS" >> dumped.env;
echo "SWOOLE_VERSION=$SWOOLE_VERSION" >> dumped.env;
cat dumped.env;

- &restore-docker-cache
restore_cache:
keys:
- docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}-{{ checksum "dumped.env" }}-{{ checksum "composer.lock" }}
- docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}-{{ checksum "dumped.env" }}
- docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}
- docker-{{ checksum "Dockerfile" }}
- docker

- &load-docker-cache
run:
name: Load Docker layer cache
command: |-
# credits to: https://blog.jondh.me.uk/2018/04/strategies-for-docker-layer-caching-in-circleci/
set +o pipefail
if [ -f /home/circleci/caches/${CIRCLE_PROJECT_REPONAME}.tar.gz ]; then
gunzip -c /home/circleci/caches/${CIRCLE_PROJECT_REPONAME}.tar.gz | docker load;
docker images;
fi

- &docker-compose-build
run:
name: Docker-Compose Build
command: docker-compose build composer

- &code-style-analysis
run:
name: Code style analysis
command: docker-compose run composer cs-analyse

- &static-src-analysis
run:
name: Sources static analysis
command: docker-compose run composer static-analyse-src

- &static-tests-analysis
run:
name: Test sources static analysis
command: docker-compose run composer static-analyse-tests

- &run-unit-tests
run:
name: Run unit tests
command: docker-compose run composer unit-tests

- &run-feature-tests
run:
name: Run feature tests
command: docker-compose run composer feature-tests

- &export-docker-cache
run:
name: Export Docker image layer cache
command: |
mkdir -p /home/circleci/caches
docker-compose build composer | grep '\-\-\->' | grep -v 'Using cache' | sed -e 's/[ >-]//g' > /tmp/layers.txt
docker save $(cat /tmp/layers.txt) | gzip > /home/circleci/caches/${CIRCLE_PROJECT_REPONAME}.tar.gz

- &save-docker-cache
save_cache:
key: docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}-{{ checksum "dumped.env" }}-{{ checksum "composer.lock" }}
paths:
- /home/circleci/caches

# Build environments
- &docker-env
working_directory: ~/workdir
machine:
enabled: true
# Ubuntu 16.04, docker 18.09.3, docker-compose 1.23.1
image: ubuntu-1604:201903-01

# Steps
- &docker-default
steps:
- checkout
- *dump-env-vars
- *restore-docker-cache
- *load-docker-cache
- *docker-compose-build
- *code-style-analysis
- *static-src-analysis
- *static-tests-analysis
- *run-unit-tests
- *run-feature-tests
- *export-docker-cache
- *save-docker-cache

jobs:
php-73:
<<: *docker-env
<<: *docker-default

php-73-latest:
<<: *docker-env
<<: *docker-default
environment:
COMPOSER_ARGS: update

php-72:
<<: *docker-env
<<: *docker-default
environment:
PHP_VERSION: 7.2
ALPINE_VERSION: 3.8
PHP_API_VERSION: "20170718"

php-72-lowest:
<<: *docker-env
<<: *docker-default
environment:
PHP_VERSION: 7.2
ALPINE_VERSION: 3.8
PHP_API_VERSION: "20170718"
COMPOSER_ARGS: update --prefer-lowest

check-composer-config:
docker:
- image: composer:1
Expand Down Expand Up @@ -28,3 +156,7 @@ workflows:
jobs:
- check-composer-config
- validate-commit-message
- php-73
- php-73-latest
- php-72
- php-72-lowest
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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ indent_size = 2
[.circleci/config.yml]
indent_size = 2

[docker-compose.yml]
indent_size = 2

[*.md]
trim_trailing_whitespace = false
78 changes: 78 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
ARG PHP_TAG="7.3-cli-alpine3.9"

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.3.1"
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
# php -i | grep 'PHP API' | sed -e 's/PHP API => //'
ARG PHP_API_VERSION="20180731"
COPY --from=ext-swoole /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/swoole.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/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-${PHP_API_VERSION}/inotify.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/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-${PHP_API_VERSION}/pcntl.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/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
ARG PHP_API_VERSION="20180731"
COPY --from=ext-xdebug /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/xdebug.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/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-with-xdebug as base-coverage
ENV COVERAGE="1"
COPY --from=app-installer /usr/src/app ./

FROM base-coverage as base-server-coverage
RUN apk add --no-cache bash

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 ["unit-code-coverage"]

FROM base-server-coverage as ServerCoverage
ENTRYPOINT ["/bin/bash"]
CMD ["tests/run-feature-tests-code-coverage.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