Symfony Docker - Updated template.
This commit is contained in:
@@ -27,6 +27,7 @@ public/bundles/
|
|||||||
tests/
|
tests/
|
||||||
var/
|
var/
|
||||||
vendor/
|
vendor/
|
||||||
|
node_modules/
|
||||||
.editorconfig
|
.editorconfig
|
||||||
.env.*.local
|
.env.*.local
|
||||||
.env.local
|
.env.local
|
||||||
|
|||||||
+5
-6
@@ -27,7 +27,7 @@ trim_trailing_whitespace = false
|
|||||||
[*.sh]
|
[*.sh]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
|
||||||
[*.xml{,.dist}]
|
[*.xml.dist]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
@@ -40,19 +40,18 @@ indent_size = 2
|
|||||||
[.gitmodules]
|
[.gitmodules]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
|
||||||
[.php_cs{,.dist}]
|
[.php_cs.dist]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[composer.json]
|
[composer.json]
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[{,docker-}compose{,.*}.{yaml,yml}]
|
[{compose,docker-compose}.*.{yaml,yml}]
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
[{,*.*}Dockerfile]
|
[*.*Dockerfile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
|
||||||
[{,*.*}Caddyfile]
|
[*.*Caddyfile]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
@@ -12,6 +12,9 @@
|
|||||||
# Draw.io backup file.
|
# Draw.io backup file.
|
||||||
*bkp
|
*bkp
|
||||||
|
|
||||||
|
# JS files
|
||||||
|
/node_modules/
|
||||||
|
|
||||||
###> symfony/asset-mapper ###
|
###> symfony/asset-mapper ###
|
||||||
/public/assets/
|
/public/assets/
|
||||||
/assets/vendor/
|
/assets/vendor/
|
||||||
|
|||||||
+17
-16
@@ -13,6 +13,8 @@ FROM frankenphp_upstream AS frankenphp_base
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
VOLUME /app/var/
|
||||||
|
|
||||||
# persistent / runtime deps
|
# persistent / runtime deps
|
||||||
# hadolint ignore=DL3008
|
# hadolint ignore=DL3008
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
@@ -24,11 +26,11 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
|
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
install-php-extensions \
|
install-php-extensions \
|
||||||
@composer \
|
@composer \
|
||||||
apcu \
|
apcu \
|
||||||
intl \
|
intl \
|
||||||
opcache \
|
opcache \
|
||||||
zip \
|
zip \
|
||||||
;
|
;
|
||||||
|
|
||||||
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
|
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
|
||||||
@@ -40,42 +42,41 @@ RUN install-php-extensions pdo_pgsql
|
|||||||
###< doctrine/doctrine-bundle ###
|
###< doctrine/doctrine-bundle ###
|
||||||
###< recipes ###
|
###< recipes ###
|
||||||
|
|
||||||
COPY --link frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/
|
COPY --link frankenphp/conf.d/10-app.ini $PHP_INI_DIR/app.conf.d/
|
||||||
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
|
||||||
COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile
|
COPY --link frankenphp/Caddyfile /etc/frankenphp/Caddyfile
|
||||||
|
|
||||||
ENTRYPOINT ["docker-entrypoint"]
|
ENTRYPOINT ["docker-entrypoint"]
|
||||||
|
|
||||||
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1
|
HEALTHCHECK --start-period=60s CMD curl -f http://localhost:2019/metrics || exit 1
|
||||||
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ]
|
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile" ]
|
||||||
|
|
||||||
# Dev FrankenPHP image
|
# Dev FrankenPHP image
|
||||||
FROM frankenphp_base AS frankenphp_dev
|
FROM frankenphp_base AS frankenphp_dev
|
||||||
|
|
||||||
ENV APP_ENV=dev XDEBUG_MODE=off
|
ENV APP_ENV=dev
|
||||||
VOLUME /app/var/
|
ENV XDEBUG_MODE=off
|
||||||
|
ENV FRANKENPHP_WORKER_CONFIG=watch
|
||||||
|
|
||||||
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
|
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
|
||||||
|
|
||||||
RUN set -eux; \
|
RUN set -eux; \
|
||||||
install-php-extensions \
|
install-php-extensions \
|
||||||
xdebug \
|
xdebug \
|
||||||
;
|
;
|
||||||
|
|
||||||
COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
|
COPY --link frankenphp/conf.d/20-app.dev.ini $PHP_INI_DIR/app.conf.d/
|
||||||
|
|
||||||
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
|
CMD [ "frankenphp", "run", "--config", "/etc/frankenphp/Caddyfile", "--watch" ]
|
||||||
|
|
||||||
# Prod FrankenPHP image
|
# Prod FrankenPHP image
|
||||||
FROM frankenphp_base AS frankenphp_prod
|
FROM frankenphp_base AS frankenphp_prod
|
||||||
|
|
||||||
ENV APP_ENV=prod
|
ENV APP_ENV=prod
|
||||||
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"
|
|
||||||
|
|
||||||
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
|
||||||
|
|
||||||
COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
|
COPY --link frankenphp/conf.d/20-app.prod.ini $PHP_INI_DIR/app.conf.d/
|
||||||
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile
|
|
||||||
|
|
||||||
# prevent the reinstallation of vendors at every changes in the source code
|
# prevent the reinstallation of vendors at every changes in the source code
|
||||||
COPY --link composer.* symfony.* ./
|
COPY --link composer.* symfony.* ./
|
||||||
|
|||||||
@@ -6,17 +6,19 @@ services:
|
|||||||
target: frankenphp_dev
|
target: frankenphp_dev
|
||||||
volumes:
|
volumes:
|
||||||
- ./:/app
|
- ./:/app
|
||||||
- ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
|
- ./frankenphp/Caddyfile:/etc/frankenphp/Caddyfile:ro
|
||||||
- ./frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
|
- ./frankenphp/conf.d/20-app.dev.ini:/usr/local/etc/php/app.conf.d/20-app.dev.ini:ro
|
||||||
# If you develop on Mac or Windows you can remove the vendor/ directory
|
# If you develop on Mac or Windows you can remove the vendor/ directory
|
||||||
# from the bind-mount for better performance by enabling the next line:
|
# from the bind-mount for better performance by enabling the next line:
|
||||||
- /app/vendor
|
- /app/vendor
|
||||||
# On dev mount var to localfiles.
|
# On dev mount var to localfiles.
|
||||||
- ./var/log:/app/var/log
|
#- ./var/log:/app/var/log
|
||||||
environment:
|
environment:
|
||||||
|
FRANKENPHP_WORKER_CONFIG: watch
|
||||||
MERCURE_EXTRA_DIRECTIVES: demo
|
MERCURE_EXTRA_DIRECTIVES: demo
|
||||||
# See https://xdebug.org/docs/all_settings#mode
|
# See https://xdebug.org/docs/all_settings#mode
|
||||||
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
|
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
|
||||||
|
APP_ENV: "${APP_ENV:-dev}"
|
||||||
extra_hosts:
|
extra_hosts:
|
||||||
# Ensure that host.docker.internal is correctly defined on Linux
|
# Ensure that host.docker.internal is correctly defined on Linux
|
||||||
- host.docker.internal:host-gateway
|
- host.docker.internal:host-gateway
|
||||||
|
|||||||
+5
-4
@@ -9,11 +9,12 @@ services:
|
|||||||
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
|
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
|
||||||
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|php$$
|
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|php$$
|
||||||
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
|
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
|
||||||
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8}
|
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-16}&charset=${POSTGRES_CHARSET:-utf8}
|
||||||
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
|
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
|
||||||
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
|
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
|
||||||
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
|
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
|
||||||
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
|
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
|
||||||
|
FRANKENPHP_USEWORKER: none # <-- Disable FrankenPHP Workers as don't work well with current EasyAdmin version. This is fixed on newer versions.
|
||||||
# The two next lines can be removed after initial installation
|
# The two next lines can be removed after initial installation
|
||||||
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
|
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
|
||||||
STABILITY: ${STABILITY:-stable}
|
STABILITY: ${STABILITY:-stable}
|
||||||
@@ -48,12 +49,12 @@ services:
|
|||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
|
||||||
POSTGRES_USER: ${POSTGRES_USER:-app}
|
POSTGRES_USER: ${POSTGRES_USER:-app}
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "pg_isready"]
|
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER:-app}"]
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
start_period: 60s
|
start_period: 60s
|
||||||
volumes:
|
volumes:
|
||||||
- database_data:/var/lib/postgresql/data:rw
|
- somniaRooms_database:/var/lib/postgresql/data:rw
|
||||||
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
|
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
|
||||||
# - ./docker/db/data:/var/lib/postgresql/data:rw
|
# - ./docker/db/data:/var/lib/postgresql/data:rw
|
||||||
###< doctrine/doctrine-bundle ###
|
###< doctrine/doctrine-bundle ###
|
||||||
@@ -65,5 +66,5 @@ volumes:
|
|||||||
###< symfony/mercure-bundle ###
|
###< symfony/mercure-bundle ###
|
||||||
|
|
||||||
###> doctrine/doctrine-bundle ###
|
###> doctrine/doctrine-bundle ###
|
||||||
database_data:
|
somniaRooms_database:
|
||||||
###< doctrine/doctrine-bundle ###
|
###< doctrine/doctrine-bundle ###
|
||||||
|
|||||||
+32
-14
@@ -1,37 +1,44 @@
|
|||||||
|
# Snipets "none"/"worker" can be used to enable-disable frankenphp workers.
|
||||||
|
(none) {
|
||||||
|
|
||||||
|
}
|
||||||
|
(worker) {
|
||||||
|
worker {
|
||||||
|
file ./public/index.php
|
||||||
|
env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
|
||||||
|
{$FRANKENPHP_WORKER_CONFIG}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
skip_install_trust
|
||||||
|
|
||||||
{$CADDY_GLOBAL_OPTIONS}
|
{$CADDY_GLOBAL_OPTIONS}
|
||||||
|
|
||||||
frankenphp {
|
frankenphp {
|
||||||
{$FRANKENPHP_CONFIG}
|
{$FRANKENPHP_CONFIG}
|
||||||
}
|
|
||||||
|
|
||||||
# https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm
|
import {$FRANKENPHP_USEWORKER:worker}
|
||||||
order mercure after encode
|
}
|
||||||
order vulcain after reverse_proxy
|
|
||||||
order php_server before file_server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{$CADDY_EXTRA_CONFIG}
|
{$CADDY_EXTRA_CONFIG}
|
||||||
|
|
||||||
{$SERVER_NAME:localhost} {
|
{$SERVER_NAME:localhost} {
|
||||||
log {
|
log {
|
||||||
|
{$CADDY_SERVER_LOG_OPTIONS}
|
||||||
# Redact the authorization query parameter that can be set by Mercure
|
# Redact the authorization query parameter that can be set by Mercure
|
||||||
format filter {
|
format filter {
|
||||||
wrap console
|
request>uri query {
|
||||||
fields {
|
replace authorization REDACTED
|
||||||
uri query {
|
|
||||||
replace authorization REDACTED
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root * /app/public
|
root /app/public
|
||||||
encode zstd br gzip
|
encode zstd br gzip
|
||||||
|
|
||||||
mercure {
|
mercure {
|
||||||
# Transport to use (default to Bolt)
|
|
||||||
transport_url {$MERCURE_TRANSPORT_URL:bolt:///data/mercure.db}
|
|
||||||
# Publisher JWT key
|
# Publisher JWT key
|
||||||
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
|
publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG}
|
||||||
# Subscriber JWT key
|
# Subscriber JWT key
|
||||||
@@ -51,5 +58,16 @@
|
|||||||
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
|
# Disable Topics tracking if not enabled explicitly: https://github.com/jkarlin/topics
|
||||||
header ?Permissions-Policy "browsing-topics=()"
|
header ?Permissions-Policy "browsing-topics=()"
|
||||||
|
|
||||||
php_server
|
@phpRoute {
|
||||||
|
not path /.well-known/mercure*
|
||||||
|
not file {path}
|
||||||
|
}
|
||||||
|
rewrite @phpRoute index.php
|
||||||
|
|
||||||
|
@frontController path index.php
|
||||||
|
php @frontController
|
||||||
|
|
||||||
|
file_server {
|
||||||
|
hide *.php
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
; https://symfony.com/doc/current/performance.html#use-the-opcache-class-preloading
|
||||||
|
opcache.preload_user = root
|
||||||
|
opcache.preload = /app/config/preload.php
|
||||||
|
; https://symfony.com/doc/current/performance.html#don-t-check-php-files-timestamps
|
||||||
|
opcache.validate_timestamps = 0
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
opcache.preload_user = root
|
|
||||||
opcache.preload = /app/config/preload.php
|
|
||||||
@@ -17,7 +17,7 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
|||||||
composer config --json extra.symfony.docker 'true'
|
composer config --json extra.symfony.docker 'true'
|
||||||
|
|
||||||
if grep -q ^DATABASE_URL= .env; then
|
if grep -q ^DATABASE_URL= .env; then
|
||||||
echo "To finish the installation please press Ctrl+C to stop Docker Compose and run: docker compose up --build -d --wait"
|
echo 'To finish the installation please press Ctrl+C to stop Docker Compose and run: docker compose up --build --wait'
|
||||||
sleep infinity
|
sleep infinity
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -26,8 +26,12 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
|||||||
composer install --prefer-dist --no-progress --no-interaction
|
composer install --prefer-dist --no-progress --no-interaction
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Display information about the current project
|
||||||
|
# Or about an error in project initialization
|
||||||
|
php bin/console -V
|
||||||
|
|
||||||
if grep -q ^DATABASE_URL= .env; then
|
if grep -q ^DATABASE_URL= .env; then
|
||||||
echo "Waiting for database to be ready..."
|
echo 'Waiting for database to be ready...'
|
||||||
ATTEMPTS_LEFT_TO_REACH_DATABASE=60
|
ATTEMPTS_LEFT_TO_REACH_DATABASE=60
|
||||||
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(php bin/console dbal:run-sql -q "SELECT 1" 2>&1); do
|
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(php bin/console dbal:run-sql -q "SELECT 1" 2>&1); do
|
||||||
if [ $? -eq 255 ]; then
|
if [ $? -eq 255 ]; then
|
||||||
@@ -41,20 +45,22 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ]; then
|
if [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ]; then
|
||||||
echo "The database is not up or not reachable:"
|
echo 'The database is not up or not reachable:'
|
||||||
echo "$DATABASE_ERROR"
|
echo "$DATABASE_ERROR"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "The database is now ready and reachable"
|
echo 'The database is now ready and reachable'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then
|
if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then
|
||||||
php bin/console doctrine:migrations:migrate --no-interaction
|
php bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
||||||
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
|
||||||
|
|
||||||
|
echo 'PHP app ready!'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec docker-php-entrypoint "$@"
|
exec docker-php-entrypoint "$@"
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
worker {
|
|
||||||
file ./public/index.php
|
|
||||||
env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user