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

Commit

Permalink
ci(circle): Configure Docker layer cache
Browse files Browse the repository at this point in the history
  • Loading branch information
k911 committed Apr 1, 2019
1 parent 80bb0a8 commit 6ec5731
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 584 deletions.
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
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
41 changes: 15 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_TAG="7.2-cli-alpine3.8"
ARG PHP_TAG="7.3-cli-alpine3.9"

FROM php:$PHP_TAG as ext-builder
RUN docker-php-source extract && \
Expand All @@ -16,7 +16,7 @@ RUN pecl install xdebug && \
docker-php-ext-enable xdebug

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

Expand All @@ -25,40 +25,37 @@ 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
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
# 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-20170718/inotify.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/inotify.so
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-20170718/pcntl.so /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pcntl.so
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
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
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 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
ENV COVERAGE="1"
COPY --from=app-installer /usr/src/app ./

FROM base-with-xdebug as base-server-coverage
FROM base-coverage 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"]
Expand All @@ -74,16 +71,8 @@ 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"]
CMD ["unit-code-coverage"]

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"]
CMD ["tests/run-feature-tests-code-coverage.sh"]
53 changes: 25 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ec5731

Please sign in to comment.