Use multi-stage build

This commit is contained in:
Kévin Dunglas 2017-11-22 08:52:31 +01:00
parent 92fc9622a3
commit d5617fa646
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
2 changed files with 11 additions and 39 deletions

View File

@ -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

View File

@ -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