From d5617fa646a62b5a8b730d2e3f6ddd3e943946a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 22 Nov 2017 08:52:31 +0100 Subject: [PATCH] Use multi-stage build --- Dockerfile | 29 +++++++++++------------------ docker/app/install-composer.sh | 21 --------------------- 2 files changed, 11 insertions(+), 39 deletions(-) delete mode 100755 docker/app/install-composer.sh diff --git a/Dockerfile b/Dockerfile index c009a8e..42a51d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,6 @@ +FROM composer:1.5 FROM php:7.1-fpm-alpine -WORKDIR /srv/app - RUN apk add --no-cache --virtual .persistent-deps \ git \ icu-libs \ @@ -22,17 +21,14 @@ RUN set -xe \ && docker-php-ext-enable --ini-name 05-opcache.ini opcache \ && apk del .build-deps -###> recipes ### -###< recipes ### - COPY docker/app/php.ini /usr/local/etc/php/php.ini +COPY --from=0 /usr/bin/composer /usr/bin/composer +COPY docker/app/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint +RUN chmod +x /usr/local/bin/docker-app-entrypoint -COPY docker/app/install-composer.sh /usr/local/bin/docker-app-install-composer -RUN chmod +x /usr/local/bin/docker-app-install-composer - -RUN set -xe \ - && docker-app-install-composer \ - && mv composer.phar /usr/local/bin/composer +WORKDIR /srv/app +ENTRYPOINT ["docker-app-entrypoint"] +CMD ["php-fpm"] # https://getcomposer.org/doc/03-cli.md#composer-allow-superuser ENV COMPOSER_ALLOW_SUPERUSER 1 @@ -40,9 +36,6 @@ ENV COMPOSER_ALLOW_SUPERUSER 1 # Use prestissimo to speed up builds RUN composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --no-interaction -COPY docker/app/docker-entrypoint.sh /usr/local/bin/docker-app-entrypoint -RUN chmod +x /usr/local/bin/docker-app-entrypoint - # Allow to use development versions of Symfony ARG STABILITY=stable ENV STABILITY ${STABILITY} @@ -50,12 +43,12 @@ ENV STABILITY ${STABILITY} # Download the Symfony skeleton and leverage Docker cache layers RUN composer create-project "symfony/skeleton" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-scripts --no-plugins --no-interaction +###> recipes ### +###< recipes ### + COPY . . RUN mkdir -p var/cache var/logs var/sessions \ && composer install --prefer-dist --no-dev --no-progress --no-suggest --classmap-authoritative --no-interaction \ && composer clear-cache \ - && chown -R www-data var # Permissions hack because setfacl does not work on Mac and Windows - -ENTRYPOINT ["docker-app-entrypoint"] -CMD ["php-fpm"] + && chown -R www-data var diff --git a/docker/app/install-composer.sh b/docker/app/install-composer.sh deleted file mode 100755 index 63c525e..0000000 --- a/docker/app/install-composer.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -# Copyright (c) Nils Adermann, Jordi Boggiano -# Origin: https://github.com/composer/composer/blob/master/doc/faqs/how-to-install-composer-programmatically.md -# Licence: MIT - -EXPECTED_SIGNATURE=$(php -r "echo trim(file_get_contents('https://composer.github.io/installer.sig'));") -php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" -ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');") - -if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] -then - >&2 echo 'ERROR: Invalid installer signature' - rm composer-setup.php - exit 1 -fi - -php composer-setup.php --quiet -RESULT=$? -rm composer-setup.php -exit $RESULT