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 e25c8dd commit dddf73d
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 583 deletions.
39 changes: 39 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,44 @@
version: 2.1

jobs:
docker-build:
# machine: true
steps:
- run:
name: Docker Version
command: docker --version
- checkout
- restore_cache:
keys:
- docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}-{{ checksum "composer.lock" }}
- docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}
- docker-{{ checksum "Dockerfile" }}
- setup_remote_docker:
version: 18.09.3
- 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 /caches/${CIRCLE_PROJECT_REPONAME}.tar.gz ]; then
gunzip -c /caches/${CIRCLE_PROJECT_REPONAME}.tar.gz | docker load;
docker images;
fi
- run:
name: Docker Compose Build
command: |-
docker-compose build
- run:
name: Save Docker image layer cache
command: |
mkdir -p /caches
docker-compose build | grep '\-\-\->' | grep -v 'Using cache' | sed -e 's/[ >-]//g' > /tmp/layers.txt
docker save $(cat /tmp/layers.txt) | gzip > /caches/${CIRCLE_PROJECT_REPONAME}.tar.gz
- save_cache:
key: docker-{{ checksum "Dockerfile" }}-{{ checksum "docker-compose.yml" }}-{{ checksum "composer.lock" }}
paths:
- /caches/

check-composer-config:
docker:
- image: composer:1
Expand Down Expand Up @@ -28,3 +66,4 @@ workflows:
jobs:
- check-composer-config
- validate-commit-message
- docker-build
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
39 changes: 14 additions & 25 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
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 dddf73d

Please sign in to comment.