Skip to content

Commit e80f6c5

Browse files
committed
2 parents 2614f05 + 12a36a7 commit e80f6c5

20 files changed

+140
-189
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*.yaml text eol=lf
1212
*.yml text eol=lf
1313
bin/console text eol=lf
14+
composer.lock text eol=lf merge=ours
1415

1516
*.ico binary
1617
*.png binary

.github/workflows/ci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,5 @@ jobs:
6868
name: Checkout
6969
uses: actions/checkout@v3
7070
-
71-
name: Lint Dockerfiles
71+
name: Lint Dockerfile
7272
uses: hadolint/[email protected]
73-
with:
74-
recursive: true

Dockerfile

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
11
#syntax=docker/dockerfile:1.4
22

33
# Versions
4-
FROM php:8.2-fpm-alpine AS php_upstream
5-
FROM mlocati/php-extension-installer:2 AS php_extension_installer_upstream
4+
FROM dunglas/frankenphp:latest-alpine AS frankenphp_upstream
65
FROM composer/composer:2-bin AS composer_upstream
7-
FROM caddy:2-alpine AS caddy_upstream
86

97

108
# The different stages of this Dockerfile are meant to be built into separate images
119
# https://docs.docker.com/develop/develop-images/multistage-build/#stop-at-a-specific-build-stage
1210
# https://docs.docker.com/compose/compose-file/#target
1311

1412

15-
# Base PHP image
16-
FROM php_upstream AS php_base
13+
# Base FrankenPHP image
14+
FROM frankenphp_upstream AS frankenphp_base
1715

18-
WORKDIR /srv/app
16+
WORKDIR /app
1917

2018
# persistent / runtime deps
2119
# hadolint ignore=DL3018
2220
RUN apk add --no-cache \
2321
acl \
24-
fcgi \
2522
file \
2623
gettext \
2724
git \
2825
;
2926

30-
# php extensions installer: https://github.com/mlocati/docker-php-extension-installer
31-
COPY --from=php_extension_installer_upstream --link /usr/bin/install-php-extensions /usr/local/bin/
32-
3327
RUN set -eux; \
3428
install-php-extensions \
3529
apcu \
@@ -47,32 +41,26 @@ RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \
4741
###< doctrine/doctrine-bundle ###
4842
###< recipes ###
4943

50-
COPY --link docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
51-
52-
COPY --link docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
53-
RUN mkdir -p /var/run/php
54-
55-
COPY --link --chmod=755 docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
56-
57-
HEALTHCHECK --interval=10s --timeout=3s --retries=3 --start-period=40s CMD ["docker-healthcheck"]
58-
59-
COPY --link --chmod=755 docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
44+
COPY --link frankenphp/conf.d/app.ini $PHP_INI_DIR/conf.d/
45+
COPY --link --chmod=755 frankenphp/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
46+
COPY --link frankenphp/Caddyfile /etc/caddy/Caddyfile
6047

6148
ENTRYPOINT ["docker-entrypoint"]
62-
CMD ["php-fpm"]
6349

6450
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
6551
ENV COMPOSER_ALLOW_SUPERUSER=1
6652
ENV PATH="${PATH}:/root/.composer/vendor/bin"
6753

6854
COPY --from=composer_upstream --link /composer /usr/bin/composer
6955

56+
HEALTHCHECK CMD wget --no-verbose --tries=1 --spider http://localhost:2019/metrics || exit 1
57+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile" ]
7058

71-
# Dev PHP image
72-
FROM php_base AS php_dev
59+
# Dev FrankenPHP image
60+
FROM frankenphp_base AS frankenphp_dev
7361

7462
ENV APP_ENV=dev XDEBUG_MODE=off
75-
VOLUME /srv/app/var/
63+
VOLUME /app/var/
7664

7765
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
7866

@@ -81,15 +69,20 @@ RUN set -eux; \
8169
xdebug \
8270
;
8371

84-
COPY --link docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
72+
COPY --link frankenphp/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
73+
74+
CMD [ "frankenphp", "run", "--config", "/etc/caddy/Caddyfile", "--watch" ]
8575

86-
# Prod PHP image
87-
FROM php_base AS php_prod
76+
# Prod FrankenPHP image
77+
FROM frankenphp_base AS frankenphp_prod
8878

8979
ENV APP_ENV=prod
80+
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"
9081

9182
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
92-
COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
83+
84+
COPY --link frankenphp/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
85+
COPY --link frankenphp/worker.Caddyfile /etc/caddy/worker.Caddyfile
9386

9487
# prevent the reinstallation of vendors at every changes in the source code
9588
COPY --link composer.* symfony.* ./
@@ -98,29 +91,11 @@ RUN set -eux; \
9891

9992
# copy sources
10093
COPY --link . ./
101-
RUN rm -Rf docker/
94+
RUN rm -Rf frankenphp/
10295

10396
RUN set -eux; \
10497
mkdir -p var/cache var/log; \
10598
composer dump-autoload --classmap-authoritative --no-dev; \
10699
composer dump-env prod; \
107100
composer run-script --no-dev post-install-cmd; \
108101
chmod +x bin/console; sync;
109-
110-
111-
# Base Caddy image
112-
FROM caddy_upstream AS caddy_base
113-
114-
ARG TARGETARCH
115-
116-
WORKDIR /srv/app
117-
118-
# Download Caddy compiled with the Mercure and Vulcain modules
119-
ADD --chmod=500 https://caddyserver.com/api/download?os=linux&arch=$TARGETARCH&p=github.com/dunglas/mercure/caddy&p=github.com/dunglas/vulcain/caddy /usr/bin/caddy
120-
121-
COPY --link docker/caddy/Caddyfile /etc/caddy/Caddyfile
122-
123-
# Prod Caddy image
124-
FROM caddy_base AS caddy_prod
125-
126-
COPY --from=php_prod --link /srv/app/public public/

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Symfony Docker
22

3-
A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony](https://symfony.com) web framework, with full [HTTP/2](https://symfony.com/doc/current/weblink.html), HTTP/3 and HTTPS support.
3+
A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony](https://symfony.com) web framework,
4+
with [FrankenPHP](https://frankenphp.dev) and [Caddy](https://caddyserver.com/) inside!
45

56
![CI](https://github.com/dunglas/symfony-docker/workflows/CI/badge.svg)
67

@@ -15,13 +16,14 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony
1516
## Features
1617

1718
* Production, development and CI ready
19+
* Just 1 service by default
20+
* Blazing-fast performance thanks to [the worker mode of FrankenPHP](https://github.com/dunglas/frankenphp/blob/main/docs/worker.md) (automatically enabled in prod mode)
1821
* [Installation of extra Docker Compose services](docs/extra-services.md) with Symfony Flex
19-
* Automatic HTTPS (in dev and in prod!)
20-
* HTTP/2, HTTP/3 and [Preload](https://symfony.com/doc/current/web_link.html) support
21-
* Built-in [Mercure](https://symfony.com/doc/current/mercure.html) hub
22+
* Automatic HTTPS (in dev and prod)
23+
* HTTP/3 and [Early Hints](https://symfony.com/blog/new-in-symfony-6-3-early-hints) support
24+
* Real-time messaging thanks to a built-in [Mercure hub](https://symfony.com/doc/current/mercure.html)
2225
* [Vulcain](https://vulcain.rocks) support
2326
* Native [XDebug](docs/xdebug.md) integration
24-
* Just 2 services (PHP FPM and Caddy server)
2527
* Super-readable configuration
2628

2729
**Enjoy!**
@@ -43,4 +45,4 @@ Symfony Docker is available under the MIT License.
4345

4446
## Credits
4547

46-
Created by [Kévin Dunglas](https://dunglas.fr), co-maintained by [Maxime Helias](https://twitter.com/maxhelias) and sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop).
48+
Created by [Kévin Dunglas](https://dunglas.dev), co-maintained by [Maxime Helias](https://twitter.com/maxhelias) and sponsored by [Les-Tilleuls.coop](https://les-tilleuls.coop).

docker-compose.override.yml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,22 @@ services:
55
php:
66
build:
77
context: .
8-
target: php_dev
8+
target: frankenphp_dev
99
volumes:
10-
- ./:/srv/app
11-
- ./docker/php/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
10+
- ./:/app
11+
- ./frankenphp/Caddyfile:/etc/caddy/Caddyfile:ro
12+
- ./frankenphp/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
1213
# If you develop on Mac or Windows you can remove the vendor/ directory
1314
# from the bind-mount for better performance by enabling the next line:
14-
#- /srv/app/vendor
15+
#- /app/vendor
1516
environment:
17+
MERCURE_EXTRA_DIRECTIVES: demo
1618
# See https://xdebug.org/docs/all_settings#mode
1719
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
1820
extra_hosts:
1921
# Ensure that host.docker.internal is correctly defined on Linux
2022
- host.docker.internal:host-gateway
2123

22-
caddy:
23-
command: [ "caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile", "--watch" ]
24-
build:
25-
context: .
26-
target: caddy_base
27-
volumes:
28-
- ./public:/srv/app/public:ro
29-
- ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
30-
environment:
31-
MERCURE_EXTRA_DIRECTIVES: demo
32-
3324
###> symfony/mercure-bundle ###
3425
###< symfony/mercure-bundle ###
3526

docker-compose.prod.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@ services:
55
php:
66
build:
77
context: .
8-
target: php_prod
8+
target: frankenphp_prod
99
environment:
1010
APP_SECRET: ${APP_SECRET}
11-
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET}
12-
13-
caddy:
14-
build:
15-
context: .
16-
target: caddy_prod
17-
environment:
1811
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}
1912
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET}

docker-compose.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,22 @@ services:
44
php:
55
image: ${IMAGES_PREFIX:-}app-php
66
restart: unless-stopped
7-
volumes:
8-
- php_socket:/var/run/php
97
environment:
8+
SERVER_NAME: ${SERVER_NAME:-localhost}, php:80
9+
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
10+
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
1011
TRUSTED_PROXIES: ${TRUSTED_PROXIES:-127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
11-
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|caddy$$
12-
# The two next lines can be removed after initial installation
13-
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
14-
STABILITY: ${STABILITY:-stable}
12+
TRUSTED_HOSTS: ^${SERVER_NAME:-example\.com|localhost}|php$$
1513
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
1614
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8}
1715
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
18-
MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
16+
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
1917
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
2018
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
21-
22-
caddy:
23-
image: ${IMAGES_PREFIX:-}app-caddy
24-
depends_on:
25-
php:
26-
condition: service_healthy
27-
restart: true
28-
environment:
29-
SERVER_NAME: ${SERVER_NAME:-localhost}, caddy:80
30-
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
31-
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
32-
restart: unless-stopped
19+
# The two next lines can be removed after initial installation
20+
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
21+
STABILITY: ${STABILITY:-stable}
3322
volumes:
34-
- php_socket:/var/run/php
3523
- caddy_data:/data
3624
- caddy_config:/config
3725
ports:
@@ -67,7 +55,6 @@ services:
6755
###< doctrine/doctrine-bundle ###
6856

6957
volumes:
70-
php_socket:
7158
caddy_data:
7259
caddy_config:
7360
###> symfony/mercure-bundle ###

docker/caddy/Caddyfile

Lines changed: 0 additions & 32 deletions
This file was deleted.

docker/php/conf.d/app.prod.ini

Lines changed: 0 additions & 2 deletions
This file was deleted.

docker/php/docker-healthcheck.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

docker/php/php-fpm.d/zz-docker.conf

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/production.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,3 @@ docker compose -f docker-compose.yml -f docker-compose.prod.yml up --wait
8585
If you want to deploy your app on a cluster of machines, you can use [Docker Swarm](https://docs.docker.com/engine/swarm/stack-deploy/),
8686
which is compatible with the provided Compose files.
8787
To deploy on Kubernetes, take a look at [the Helm chart provided with API Platform](https://api-platform.com/docs/deployment/kubernetes/), which can be easily adapted for use with Symfony Docker.
88-
89-
## Configuring a Load Balancer or a Reverse Proxy
90-
91-
Since Caddy 2.5, XFF values of incoming requests will be ignored to prevent spoofing.
92-
So if Caddy is not the first server being connected to by your clients (for example when a CDN is in front of Caddy), you may configure `trusted_proxies` with a list of IP ranges (CIDRs) from which incoming requests are trusted to have sent good values for these headers.
93-
As a shortcut, `private_ranges` may be configured to trust all private IP ranges.
94-
95-
```diff
96-
-php_fastcgi unix//var/run/php/php-fpm.sock
97-
+php_fastcgi unix//var/run/php/php-fpm.sock {
98-
+ trusted_proxies private_ranges
99-
+}
100-
```

0 commit comments

Comments
 (0)