Skip to content

Commit

Permalink
Upgrade Dockerfile to PHP 7.4 and sync with API Platform's setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Mar 31, 2020
1 parent a68c24c commit 1658a57
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 24 deletions.
42 changes: 34 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# the different stages of this Dockerfile are meant to be built into separate images
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
# https://docs.docker.com/compose/compose-file/#target

ARG PHP_VERSION=7.3

# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG PHP_VERSION=7.4
ARG NODE_VERSION=10
ARG NGINX_VERSION=1.16
ARG NGINX_VERSION=1.17

# "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS sylius_php

# persistent / runtime deps
RUN apk add --no-cache \
acl \
fcgi \
file \
gettext \
git \
mariadb-client \
;

ARG APCU_VERSION=5.1.17
ARG APCU_VERSION=5.1.18
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
Expand All @@ -32,8 +37,8 @@ RUN set -eux; \
zlib-dev \
; \
\
docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include --with-webp-dir=/usr/include --with-freetype-dir=/usr/include/; \
docker-php-ext-configure zip --with-libzip; \
docker-php-ext-configure gd --with-jpeg --with-webp --with-freetype; \
docker-php-ext-configure zip; \
docker-php-ext-install -j$(nproc) \
exif \
gd \
Expand Down Expand Up @@ -64,10 +69,18 @@ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY docker/php/php.ini /usr/local/etc/php/php.ini
COPY docker/php/php-cli.ini /usr/local/etc/php/php-cli.ini

RUN set -eux; \
{ \
echo '[www]'; \
echo 'ping.path = /ping'; \
} | tee /usr/local/etc/php-fpm.d/docker-healthcheck.conf

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV COMPOSER_ALLOW_SUPERUSER=1

This comment has been minimized.

Copy link
@sferey

sferey May 26, 2021

Duplicate line, It's normal ?

# install Symfony Flex globally to speed up download of Composer packages (parallelized prefetching)
RUN set -eux; \
composer global require "hirak/prestissimo:^0.3" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \
composer global require "symfony/flex" --prefer-dist --no-progress --no-suggest --classmap-authoritative; \
composer clear-cache
ENV PATH="${PATH}:/root/.composer/vendor/bin"

Expand All @@ -79,11 +92,15 @@ ARG APP_ENV=prod
# prevent the reinstallation of vendors at every changes in the source code
COPY composer.json composer.lock symfony.lock ./
RUN set -eux; \
composer install --prefer-dist --no-autoloader --no-scripts --no-progress --no-suggest; \
composer install --prefer-dist --no-dev --no-scripts --no-progress --no-suggest; \
composer clear-cache

# do not use .env files in production
COPY .env ./
RUN composer dump-env prod; \
rm .env

# copy only specifically what we need
COPY .env .env.prod .env.test .env.test_cached ./
COPY bin bin/
COPY config config/
COPY public public/
Expand All @@ -102,12 +119,19 @@ VOLUME /srv/sylius/var

VOLUME /srv/sylius/public/media

COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck

HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]

COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint

ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]

# "node" stage
# depends on the "php" stage above
FROM node:${NODE_VERSION}-alpine AS sylius_nodejs

WORKDIR /srv/sylius
Expand Down Expand Up @@ -144,6 +168,8 @@ RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]
CMD ["yarn", "watch"]

# "nginx" stage
# depends on the "php" and "node" stages above
FROM nginx:${NGINX_VERSION}-alpine AS sylius_nginx

COPY docker/nginx/conf.d/default.conf /etc/nginx/conf.d/
Expand Down
35 changes: 19 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
version: '3.4'

x-cache-from:
- &sylius-cache-from
cache_from:
- ${NGINX_IMAGE:-quay.io/sylius/nginx}
- ${PHP_IMAGE:-quay.io/sylius/php}
- ${NODEJS_IMAGE:-quay.io/sylius/nodejs}

services:
php:
build:
context: .
target: sylius_php
cache_from:
- quay.io/sylius/php:latest
- quay.io/sylius/nodejs:latest
- quay.io/sylius/nginx:latest
image: quay.io/sylius/php:latest
<<: *sylius-cache-from
image: ${PHP_IMAGE:-quay.io/sylius/php}
healthcheck:
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
depends_on:
- mysql
environment:
Expand Down Expand Up @@ -46,11 +55,8 @@ services:
build:
context: .
target: sylius_nodejs
cache_from:
- quay.io/sylius/php:latest
- quay.io/sylius/nodejs:latest
- quay.io/sylius/nginx:latest
image: quay.io/sylius/nodejs:latest
<<: *sylius-cache-from
image: ${NODEJS_IMAGE:-quay.io/sylius/nodejs}
depends_on:
- php
environment:
Expand All @@ -67,11 +73,8 @@ services:
build:
context: .
target: sylius_nginx
cache_from:
- quay.io/sylius/php:latest
- quay.io/sylius/nodejs:latest
- quay.io/sylius/nginx:latest
image: quay.io/sylius/nginx:latest
<<: *sylius-cache-from
image: ${NGINX_IMAGE:-quay.io/sylius/nginx}
depends_on:
- php
- nodejs # to ensure correct build order
Expand All @@ -85,7 +88,7 @@ services:

mailhog:
# do not use in production!
image: mailhog/mailhog:latest
image: mailhog/mailhog
environment:
- MH_STORAGE=maildir
# volumes:
Expand Down
12 changes: 12 additions & 0 deletions docker/php/docker-healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e

export SCRIPT_NAME=/ping
export SCRIPT_FILENAME=/ping
export REQUEST_METHOD=GET

if cgi-fcgi -bind -connect 127.0.0.1:9000; then
exit 0
fi

exit 1
6 changes: 6 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@
"ref": "e3868d2f4a5104f19f844fe551099a00c6562527"
}
},
"symfony/contracts": {
"version": "v1.1.8"
},
"symfony/css-selector": {
"version": "v4.1.3"
},
Expand Down Expand Up @@ -608,6 +611,9 @@
"symfony/dotenv": {
"version": "v4.1.3"
},
"symfony/error-handler": {
"version": "v4.4.4"
},
"symfony/event-dispatcher": {
"version": "v4.1.3"
},
Expand Down

0 comments on commit 1658a57

Please sign in to comment.