refactor: improve image, uniformize with API Platform (#275)
* refactor: improve image, uniformize with API Platform * feat: remove the SKELETON arg
This commit is contained in:
parent
c8b13f29c7
commit
90d3f391db
125
Dockerfile
125
Dockerfile
@ -8,7 +8,19 @@ ARG PHP_VERSION=8.1
|
||||
ARG CADDY_VERSION=2
|
||||
|
||||
# Prod image
|
||||
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php
|
||||
FROM php:${PHP_VERSION}-fpm-alpine AS app_php
|
||||
|
||||
# Allow to use development versions of Symfony
|
||||
ARG STABILITY="stable"
|
||||
ENV STABILITY ${STABILITY}
|
||||
|
||||
# Allow to select Symfony version
|
||||
ARG SYMFONY_VERSION=""
|
||||
ENV SYMFONY_VERSION ${SYMFONY_VERSION}
|
||||
|
||||
ENV APP_ENV=prod
|
||||
|
||||
WORKDIR /srv/app
|
||||
|
||||
# persistent / runtime deps
|
||||
RUN apk add --no-cache \
|
||||
@ -48,70 +60,69 @@ RUN set -eux; \
|
||||
| sort -u \
|
||||
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
||||
)"; \
|
||||
apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
|
||||
apk add --no-cache --virtual .app-phpexts-rundeps $runDeps; \
|
||||
\
|
||||
apk del .build-deps
|
||||
|
||||
###> recipes ###
|
||||
###< recipes ###
|
||||
|
||||
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||
COPY docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
|
||||
COPY docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
|
||||
|
||||
COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
|
||||
RUN mkdir -p /var/run/php
|
||||
|
||||
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"]
|
||||
|
||||
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||
COPY docker/php/conf.d/symfony.ini $PHP_INI_DIR/conf.d/symfony.ini
|
||||
COPY docker/php/conf.d/symfony.prod.ini $PHP_INI_DIR/conf.d/symfony.prod.ini
|
||||
|
||||
COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
|
||||
|
||||
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint
|
||||
|
||||
VOLUME /var/run/php
|
||||
|
||||
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
|
||||
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||
|
||||
ENV PATH="${PATH}:/root/.composer/vendor/bin"
|
||||
|
||||
WORKDIR /srv/app
|
||||
|
||||
# Allow to choose skeleton
|
||||
ARG SKELETON="symfony/skeleton"
|
||||
ENV SKELETON ${SKELETON}
|
||||
|
||||
# Allow to use development versions of Symfony
|
||||
ARG STABILITY="stable"
|
||||
ENV STABILITY ${STABILITY}
|
||||
|
||||
# Allow to select skeleton version
|
||||
ARG SYMFONY_VERSION=""
|
||||
ENV SYMFONY_VERSION ${SYMFONY_VERSION}
|
||||
|
||||
# Download the Symfony skeleton and leverage Docker cache layers
|
||||
RUN composer create-project "${SKELETON} ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-interaction; \
|
||||
composer clear-cache
|
||||
|
||||
###> recipes ###
|
||||
###< recipes ###
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN set -eux; \
|
||||
mkdir -p var/cache var/log; \
|
||||
composer install --prefer-dist --no-dev --no-progress --no-scripts --no-interaction; \
|
||||
composer dump-autoload --classmap-authoritative --no-dev; \
|
||||
composer symfony:dump-env prod; \
|
||||
composer run-script --no-dev post-install-cmd; \
|
||||
chmod +x bin/console; sync
|
||||
VOLUME /srv/app/var
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint"]
|
||||
CMD ["php-fpm"]
|
||||
|
||||
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
|
||||
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||
ENV PATH="${PATH}:/root/.composer/vendor/bin"
|
||||
|
||||
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# prevent the reinstallation of vendors at every changes in the source code
|
||||
COPY composer.* symfony.* ./
|
||||
RUN set -eux; \
|
||||
if [ -f composer.json ]; then \
|
||||
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
|
||||
composer clear-cache; \
|
||||
fi
|
||||
|
||||
# copy sources
|
||||
COPY . .
|
||||
RUN rm -Rf docker/
|
||||
|
||||
RUN set -eux; \
|
||||
mkdir -p var/cache var/log; \
|
||||
if [ -f composer.json ]; then \
|
||||
composer dump-autoload --classmap-authoritative --no-dev; \
|
||||
composer dump-env prod; \
|
||||
composer run-script --no-dev post-install-cmd; \
|
||||
chmod +x bin/console; sync; \
|
||||
fi
|
||||
|
||||
# Dev image
|
||||
FROM symfony_php AS symfony_php_dev
|
||||
FROM app_php AS app_php_dev
|
||||
|
||||
ENV APP_ENV=dev
|
||||
VOLUME /srv/app/var/
|
||||
|
||||
RUN rm $PHP_INI_DIR/conf.d/app.prod.ini; \
|
||||
mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
|
||||
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
|
||||
|
||||
COPY docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
|
||||
|
||||
RUN set -eux; \
|
||||
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
|
||||
@ -119,16 +130,10 @@ RUN set -eux; \
|
||||
docker-php-ext-enable xdebug; \
|
||||
apk del .build-deps
|
||||
|
||||
RUN rm $PHP_INI_DIR/conf.d/symfony.prod.ini; \
|
||||
mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
|
||||
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
|
||||
|
||||
COPY docker/php/conf.d/symfony.dev.ini $PHP_INI_DIR/conf.d/symfony.dev.ini
|
||||
|
||||
RUN rm -f .env.local.php
|
||||
|
||||
# Build Caddy with the Mercure and Vulcain modules
|
||||
FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder
|
||||
FROM caddy:${CADDY_VERSION}-builder-alpine AS app_caddy_builder
|
||||
|
||||
RUN xcaddy build \
|
||||
--with github.com/dunglas/mercure \
|
||||
@ -137,10 +142,10 @@ RUN xcaddy build \
|
||||
--with github.com/dunglas/vulcain/caddy
|
||||
|
||||
# Caddy image
|
||||
FROM caddy:${CADDY_VERSION} AS symfony_caddy
|
||||
FROM caddy:${CADDY_VERSION} AS app_caddy
|
||||
|
||||
WORKDIR /srv/app
|
||||
|
||||
COPY --from=symfony_caddy_builder /usr/bin/caddy /usr/bin/caddy
|
||||
COPY --from=symfony_php /srv/app/public public/
|
||||
COPY --from=app_caddy_builder /usr/bin/caddy /usr/bin/caddy
|
||||
COPY --from=app_php /srv/app/public public/
|
||||
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile
|
||||
|
@ -4,10 +4,10 @@ version: "3.4"
|
||||
services:
|
||||
php:
|
||||
build:
|
||||
target: symfony_php_dev
|
||||
target: app_php_dev
|
||||
volumes:
|
||||
- ./:/srv/app
|
||||
- ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.dev.ini:ro
|
||||
- ./docker/php/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
|
||||
# If you develop on Mac or Windows you can remove the var/ and vendor/ directories
|
||||
# from the bind-mount for better performance by enabling the next 2 lines:
|
||||
#- /srv/app/var
|
||||
|
@ -4,10 +4,9 @@ services:
|
||||
php:
|
||||
build:
|
||||
context: .
|
||||
target: symfony_php
|
||||
target: app_php
|
||||
args:
|
||||
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
|
||||
SKELETON: ${SKELETON:-symfony/skeleton}
|
||||
STABILITY: ${STABILITY:-stable}
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
@ -28,7 +27,7 @@ services:
|
||||
caddy:
|
||||
build:
|
||||
context: .
|
||||
target: symfony_caddy
|
||||
target: app_caddy
|
||||
depends_on:
|
||||
- php
|
||||
environment:
|
||||
|
@ -9,10 +9,11 @@ fi
|
||||
if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
||||
mkdir -p var/cache var/log
|
||||
|
||||
# The first time volumes are mounted, the project needs to be created
|
||||
# Install the project the first time PHP is started
|
||||
# After the installation, the following block can be deleted
|
||||
if [ ! -f composer.json ]; then
|
||||
CREATION=1
|
||||
composer create-project "$SKELETON $SYMFONY_VERSION" tmp --stability="$STABILITY" --prefer-dist --no-progress --no-interaction --no-install
|
||||
composer create-project "symfony/skeleton $SYMFONY_VERSION" tmp --stability="$STABILITY" --prefer-dist --no-progress --no-interaction --no-install
|
||||
|
||||
cd tmp
|
||||
composer require "php:>=$PHP_VERSION"
|
||||
@ -28,6 +29,7 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
||||
fi
|
||||
|
||||
if grep -q ^DATABASE_URL= .env; then
|
||||
# After the installation, the following block can be deleted
|
||||
if [ "$CREATION" = "1" ]; then
|
||||
echo "To finish the installation please press Ctrl+C to stop Docker Compose and run: docker compose up --build"
|
||||
sleep infinity
|
||||
|
@ -1,26 +1,19 @@
|
||||
# Build Options
|
||||
|
||||
## Selecting a Symfony Skeleton
|
||||
|
||||
By default, Symfony Docker will install the minimalist skeleton.
|
||||
To install the ["website skeleton"](https://symfony.com/doc/current/setup.html#creating-symfony-applications), use the following command:
|
||||
|
||||
SKELETON=symfony/website-skeleton docker compose up --build
|
||||
|
||||
## Selecting a Specific Symfony Version
|
||||
|
||||
Use the `SYMFONY_VERSION` environment variable to select a specific Symfony version.
|
||||
|
||||
For instance, use the following command to install Symfony 4.4:
|
||||
For instance, use the following command to install Symfony 5.4:
|
||||
|
||||
SYMFONY_VERSION=4.4.* docker compose up --build
|
||||
SYMFONY_VERSION=5.4.* docker compose up --build
|
||||
|
||||
## Installing Development Versions of Symfony
|
||||
|
||||
To install a non-stable version of Symfony, use the `STABILITY` environment variable during the build.
|
||||
The value must be [a valid Composer stability option](https://getcomposer.org/doc/04-schema.md#minimum-stability)) .
|
||||
|
||||
For instance, use the following command to use the `master` branch of Symfony:
|
||||
For instance, use the following command to use the development branch of Symfony:
|
||||
|
||||
STABILITY=dev docker compose up --build
|
||||
|
||||
@ -28,7 +21,7 @@ For instance, use the following command to use the `master` branch of Symfony:
|
||||
|
||||
Use the `SERVER_NAME` environment variable to define your custom server name(s).
|
||||
|
||||
SERVER_NAME="symfony.localhost, caddy:80" docker compose up --build
|
||||
SERVER_NAME="app.localhost, caddy:80" docker compose up --build
|
||||
|
||||
If you use Mercure, keep `caddy:80` in the list to allow the PHP container to request the caddy service.
|
||||
|
||||
|
@ -48,7 +48,7 @@ SYMFONY = $(PHP_CONT) bin/console
|
||||
.DEFAULT_GOAL = help
|
||||
.PHONY = help build up start down logs sh composer vendor sf cc
|
||||
|
||||
## —— 🎵 🐳 The Symfony-docker Makefile 🐳 🎵 ——————————————————————————————————
|
||||
## —— 🎵 🐳 The Symfony Docker Makefile 🐳 🎵 ——————————————————————————————————
|
||||
help: ## Outputs this help screen
|
||||
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}{printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user