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

Commit

Permalink
build(docker): Use "pcov" instead of "xdebug" as code coverage engine
Browse files Browse the repository at this point in the history
Xdebug is incompatible with swoole because it causes core dumps when using swoole coroutines.
  • Loading branch information
k911 committed Apr 25, 2019
1 parent 1e83b4c commit 4284ed3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 36 deletions.
20 changes: 13 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,23 @@ aliases:

- &run-unit-tests-with-coverage
run:
name: Run unit tests with coverage
command: docker-compose run composer-coverage
name: Run unit tests with coverage (pcov)
command: docker-compose run coverage-pcov

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

- &run-feature-tests-with-coverage
- &run-feature-tests-with-coverage-xdebug
run:
name: Run feature tests with coverage
command: docker-compose run feature-coverage
name: Run feature tests with coverage (xdebug) and retry
command: docker-compose run coverage-xdebug-feature-with-retry

- &run-feature-tests-with-coverage-pcov
run:
name: Run feature tests with coverage (pcov)
command: docker-compose run coverage-pcov feature-code-coverage

- &prepare-codeclimate-reporter
run:
Expand All @@ -129,7 +134,7 @@ aliases:
- &export-docker-cache
run:
name: Export Docker image layer cache
command: |
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
Expand Down Expand Up @@ -180,7 +185,8 @@ aliases:
- *static-src-analysis
- *static-tests-analysis
- *run-unit-tests-with-coverage
- *run-feature-tests-with-coverage
- *run-feature-tests-with-coverage-pcov
- *run-feature-tests-with-coverage-xdebug
- *merge-code-coverage
- *upload-codecov-report
- *upload-codeclimate-report
Expand Down
38 changes: 28 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ ARG SWOOLE_VERSION="4.3.1"
RUN pecl install swoole-${SWOOLE_VERSION} && \
docker-php-ext-enable swoole

FROM ext-builder as ext-pcov
RUN pecl install pcov && \
docker-php-ext-enable pcov
RUN echo "pcov.enabled=1" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini && \
echo "pcov.directory=/usr/src/app/src" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini

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
Expand All @@ -45,11 +51,7 @@ COPY --from=ext-inotify /usr/local/etc/php/conf.d/docker-php-ext-inotify.ini /us
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-cli
USER app:runner
COPY --chown=app:runner --from=app-installer /usr/src/app ./

FROM base as base-coverage
FROM base as base-coverage-xdebug
RUN apk add --no-cache bash lsof
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
Expand All @@ -60,20 +62,36 @@ ENV COVERAGE="1" \
COPY --chown=app:runner --from=app-installer /usr/bin/composer /usr/local/bin/composer
COPY --chown=app:runner --from=app-installer /usr/src/app ./

FROM base-cli as Cli
FROM base as base-coverage-pcov
ARG PHP_API_VERSION="20180731"
COPY --from=ext-pcov /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/pcov.so /usr/local/lib/php/extensions/no-debug-non-zts-${PHP_API_VERSION}/pcov.so
COPY --from=ext-pcov /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
USER app:runner
ENV COVERAGE="1" \
COMPOSER_ALLOW_SUPERUSER="1"
COPY --chown=app:runner --from=app-installer /usr/bin/composer /usr/local/bin/composer
COPY --chown=app:runner --from=app-installer /usr/src/app ./

FROM base as Cli
USER app:runner
COPY --chown=app:runner --from=app-installer /usr/src/app ./
ENTRYPOINT ["./tests/Fixtures/Symfony/app/console"]
CMD ["swoole:server:run"]

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

FROM base-coverage as ComposerCoverage
FROM base-coverage-xdebug as CoverageXdebug
ENTRYPOINT ["composer"]
CMD ["unit-code-coverage"]

FROM base-coverage-pcov as CoveragePcov
ENTRYPOINT ["composer"]
CMD ["unit-code-coverage"]

FROM base-coverage as FeatureCoverage
FROM base-coverage-xdebug as CoverageXdebugWithRetry
ENTRYPOINT ["/bin/bash"]
CMD ["tests/run-feature-tests-code-coverage.sh"]
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
.PHONY: clean-coverage
clean-coverage:
.PHONY: clean/coverage
clean/coverage:
@rm -rf cov/*
@rm -rf clover.xml

.PHONY: clean-test-resources
clean-test-resources:
.PHONY: clean/tests/resources
clean/tests/resources:
@rm -rf tests/Fixtures/resources/*.pid

.PHONY: clean-fixtures-cache
clean-fixtures-cache:
.PHONY: clean/fixtures/cache
clean/fixtures/cache:
@rm -rf tests/Fixtures/Symfony/app/var/cache/*

.PHONY: clean-fixtures-logs
clean-fixtures-logs:
.PHONY: clean/fixtures/logs
clean/fixtures/logs:
@rm -rf tests/Fixtures/Symfony/app/var/log/*

.PHONY: clean
clean: clean-coverage clean-fixtures-cache clean-fixtures-logs clean-test-resources

clean: clean/coverage clean/fixtures/cache clean/fixtures/logs clean/tests/resources
35 changes: 26 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ services:
COMPOSER_ARGS: "${COMPOSER_ARGS:-install}"
SWOOLE_VERSION: "${SWOOLE_VERSION:-4.3.1}"

composer-coverage:
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-composer-coverage}:${TAG:-latest}"
coverage-xdebug:
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-coverage-xdebug}:${TAG:-latest}"
build:
context: .
target: ComposerCoverage
target: CoverageXdebug
args:
PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}"
PHP_API_VERSION: "${PHP_API_VERSION:-20180731}"
Expand All @@ -37,11 +37,28 @@ services:
volumes:
- "./cov:/usr/src/app/cov"

feature-coverage:
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-feature-coverage}:${TAG:-latest}"
coverage-pcov:
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-coverage-pcov}:${TAG:-latest}"
build:
context: .
target: FeatureCoverage
target: CoveragePcov
args:
PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}"
PHP_API_VERSION: "${PHP_API_VERSION:-20180731}"
COMPOSER_ARGS: "${COMPOSER_ARGS:-install}"
SWOOLE_VERSION: "${SWOOLE_VERSION:-4.3.1}"
volumes:
- "./cov:/usr/src/app/cov"

coverage-xdebug-feature-with-retry:
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-coverage-xdebug}:${TAG:-latest}"
entrypoint:
- /bin/bash
command:
- tests/run-feature-tests-code-coverage.sh
build:
context: .
target: CoverageXdebug
args:
PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}"
PHP_API_VERSION: "${PHP_API_VERSION:-20180731}"
Expand All @@ -51,11 +68,11 @@ services:
- "./cov:/usr/src/app/cov"

merge-code-coverage:
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-composer-coverage}:${TAG:-latest}"
command: "merge-code-coverage"
image: "${REGISTRY:-docker.io}/${NAMESPACE:-k911}/${IMAGE:-swoole-bundle-composer-pcov}:${TAG:-latest}"
command: merge-code-coverage
build:
context: .
target: ComposerCoverage
target: CoveragePcov
args:
PHP_TAG: "${PHP_VERSION:-7.3}-cli-alpine${ALPINE_VERSION:-3.9}"
PHP_API_VERSION: "${PHP_API_VERSION:-20180731}"
Expand Down

0 comments on commit 4284ed3

Please sign in to comment.