Skip to content

Commit a03e9f1

Browse files
Anthodevmxr576o-alquimistaduboissjzecca
authored
Rebase from dunglas main repo (#4)
* Typo fix * Remove iconv workaround * Replace unsupported wip tld by localhost (dunglas#254) * ICU 71.1 support * feat: remove deprecated flags * feat: improve PHP config (dunglas#266) * feat: improve PHP config Tweak PHP config according to Blackfire's recommendation. * Update docker/php/conf.d/symfony.prod.ini Co-authored-by: Jacob Dreesen <jacob@hdreesen.de> * fix * fix Co-authored-by: Jacob Dreesen <jacob@hdreesen.de> * feat: Promote Compose v2 * Windows performance hint (dunglas#270) * docs: trust certificate on Windows (dunglas#272) Added information about how to add the caddy cert to the trusted certificates on Windows as this info was only provided for Linux & Mac. * feat: add native Xdebug support (dunglas#271) * feat: add native Xdebug support * cleanup * fix review * fix review * Improve docs * some more improvements * remove useless env var * Update README.md * Update README.md * refactor: improve image, uniformize with API Platform (dunglas#275) * refactor: improve image, uniformize with API Platform * feat: remove the SKELETON arg * chore: minor improvements and sync with API Platform (dunglas#277) * chore: compatibility with the new ORM recipe (dunglas#278) * chore: add a default value for XDEBUG_MODE * fix: stop use obsolete experimental_http3 option * Feat/supercharged symfony docker (#1) * 📦 NEW: Makefile + modified ci / dockerfile /README * 🐛 FIX: added a way to restore permission for the files * 🐛 FIX: Removed --no-deps option for php command in Docker through Makefile * 👌 IMPROVE: Added user permissions to manage file permissions * 🐛 FIX: remove an instruction in Dockerfile * 🐛 FIX: fixing permissions on small part of the Dockerfile Co-authored-by: Dezső BICZÓ <mxr576@users.noreply.github.com> Co-authored-by: Douglas Silva <doug.hs@protonmail.ch> Co-authored-by: Steven DUBOIS <git@duboiss.fr> Co-authored-by: Jérôme Zecca <jerome.zecca@cpiglobal.com> Co-authored-by: Stéphane P <n3wborn@protonmail.com> Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> Co-authored-by: Jacob Dreesen <jacob@hdreesen.de> Co-authored-by: Maxime Hélias <maximehelias16@gmail.com> Co-authored-by: Robin Brisa <robin.brisa@gmail.com> Co-authored-by: Borislav Kosun <kosun.b@yandex.ua>
1 parent 50debbd commit a03e9f1

19 files changed

+186
-212
lines changed

.dockerignore

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
**/*.log
22
**/*.md
33
**/*.php~
4+
**/*.dist.php
5+
**/*.dist
6+
**/*.cache
47
**/._*
58
**/.dockerignore
69
**/.DS_Store
@@ -14,15 +17,14 @@
1417
**/docker-compose.yml
1518
**/Dockerfile
1619
**/Thumbs.db
20+
.github/
21+
docs/
22+
public/bundles/
23+
tests/
24+
var/
25+
vendor/
1726
.editorconfig
1827
.env.*.local
1928
.env.local
2029
.env.local.php
21-
.php_cs.cache
22-
bin/*
23-
!bin/console
24-
docker/db/data/
25-
helm/
26-
public/bundles/
27-
var/
28-
vendor/
30+
.env.test

.editorconfig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ charset = utf-8
1515
trim_trailing_whitespace = true
1616
insert_final_newline = true
1717

18-
[*.{js,html}]
18+
[*.{js,html,ts,tsx}]
1919
indent_style = space
2020
indent_size = 2
2121

@@ -43,10 +43,6 @@ indent_style = space
4343
indent_size = 4
4444
trim_trailing_whitespace = false
4545

46-
[api/helm/api/**.yaml]
47-
indent_style = space
48-
indent_size = 2
49-
5046
[.github/workflows/*.yml]
5147
indent_style = space
5248
indent_size = 2

Dockerfile

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@
77
ARG PHP_VERSION=8.1
88
ARG CADDY_VERSION=2
99

10-
# "php" stage
11-
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php
10+
# Prod image
11+
FROM php:${PHP_VERSION}-fpm-alpine AS app_php
12+
13+
# Allow to use development versions of Symfony
14+
ARG STABILITY="stable"
15+
ENV STABILITY ${STABILITY}
16+
17+
# Allow to select Symfony version
18+
ARG SYMFONY_VERSION=""
19+
ENV SYMFONY_VERSION ${SYMFONY_VERSION}
20+
21+
ENV UID=${USER_ID:-1000}
22+
ENV GID=${GROUP_ID:-1000}
23+
24+
ENV APP_ENV=prod
25+
26+
WORKDIR /srv/app
1227

1328
# persistent / runtime deps
1429
RUN apk add --no-cache \
@@ -21,18 +36,14 @@ RUN apk add --no-cache \
2136
bash \
2237
;
2338

24-
# install gnu-libiconv and set LD_PRELOAD env to make iconv work fully on Alpine image.
25-
# see https://github.com/docker-library/php/issues/240#issuecomment-763112749
26-
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
27-
2839
RUN set -xe \
2940
&& apk add --no-cache --virtual .php-deps \
3041
make
3142

32-
ARG APCU_VERSION=5.1.21
3343
RUN set -eux; \
3444
apk add --no-cache --virtual .build-deps \
3545
$PHPIZE_DEPS \
46+
icu-data-full \
3647
icu-dev \
3748
libzip-dev \
3849
zlib-dev \
@@ -44,7 +55,7 @@ RUN set -eux; \
4455
zip \
4556
; \
4657
pecl install \
47-
apcu-${APCU_VERSION} \
58+
apcu \
4859
; \
4960
pecl clear-cache; \
5061
docker-php-ext-enable \
@@ -58,85 +69,117 @@ RUN set -eux; \
5869
| sort -u \
5970
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
6071
)"; \
61-
apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
72+
apk add --no-cache --virtual .app-phpexts-rundeps $runDeps; \
6273
\
6374
apk del .build-deps
6475

76+
###> recipes ###
77+
###< recipes ###
78+
79+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
80+
COPY docker/php/conf.d/app.ini $PHP_INI_DIR/conf.d/
81+
COPY docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
82+
83+
COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
84+
RUN mkdir -p /var/run/php
85+
6586
COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
6687
RUN chmod +x /usr/local/bin/docker-healthcheck
6788

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

70-
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
71-
COPY docker/php/conf.d/symfony.prod.ini $PHP_INI_DIR/conf.d/symfony.ini
72-
73-
COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
74-
7591
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
7692
RUN chmod +x /usr/local/bin/docker-entrypoint
7793

78-
VOLUME /var/run/php
94+
RUN addgroup -S app_group --gid ${GID}
7995

80-
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
96+
RUN adduser \
97+
--disabled-password \
98+
--gecos "" \
99+
--home "$(pwd)" \
100+
--ingroup app_group \
101+
--no-create-home \
102+
--uid "$UID" \
103+
app_user
104+
105+
RUN rm -rf /srv/app/* && chown app_user:app_group -R /srv/app
106+
107+
USER app_user
108+
109+
RUN echo 'alias sf="php bin/console"' >> ~/.bashrc
110+
RUN echo 'alias phpunit="php vendor/bin/simple-phpunit"' >> ~/.bashrc
111+
RUN echo 'alias stan="php vendor/bin/phpstan"' >> ~/.bashrc
112+
113+
ENTRYPOINT ["docker-entrypoint"]
114+
CMD ["php-fpm"]
115+
RUN bash
81116

82117
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
83118
ENV COMPOSER_ALLOW_SUPERUSER=1
84-
85119
ENV PATH="${PATH}:/root/.composer/vendor/bin"
86120

87-
WORKDIR /srv/app
121+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
88122

89-
# Allow to choose skeleton
90-
ARG SKELETON="symfony/skeleton"
91-
ENV SKELETON ${SKELETON}
123+
# prevent the reinstallation of vendors at every changes in the source code
124+
COPY composer.* symfony.* ./
125+
RUN set -eux; \
126+
if [ -f composer.json ]; then \
127+
composer install --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress; \
128+
composer clear-cache; \
129+
fi
92130

93-
# Allow to use development versions of Symfony
94-
ARG STABILITY="stable"
95-
ENV STABILITY ${STABILITY}
131+
# copy sources
132+
COPY . .
96133

97-
# Allow to select skeleton version
98-
ARG SYMFONY_VERSION=""
99-
ENV SYMFONY_VERSION ${SYMFONY_VERSION}
134+
RUN set -eux; \
135+
mkdir -p var/cache var/log; \
136+
if [ -f composer.json ]; then \
137+
composer dump-autoload --classmap-authoritative --no-dev; \
138+
composer dump-env prod; \
139+
composer run-script --no-dev post-install-cmd; \
140+
chmod +x bin/console; sync; \
141+
fi
100142

101-
# Download the Symfony skeleton and leverage Docker cache layers
102-
RUN composer create-project "${SKELETON} ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-interaction; \
103-
composer clear-cache
143+
# Dev image
144+
FROM app_php AS app_php_dev
104145

105-
###> recipes ###
106-
###< recipes ###
146+
ENV APP_ENV=dev XDEBUG_MODE=off
147+
VOLUME /srv/app/var/
107148

108-
COPY . .
149+
USER root
150+
151+
RUN rm $PHP_INI_DIR/conf.d/app.prod.ini; \
152+
mv "$PHP_INI_DIR/php.ini" "$PHP_INI_DIR/php.ini-production"; \
153+
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
154+
155+
COPY docker/php/conf.d/app.dev.ini $PHP_INI_DIR/conf.d/
109156

110157
RUN set -eux; \
111-
mkdir -p var/cache var/log; \
112-
composer install --prefer-dist --no-dev --no-progress --no-scripts --no-interaction; \
113-
composer dump-autoload --classmap-authoritative --no-dev; \
114-
composer symfony:dump-env prod; \
115-
composer run-script --no-dev post-install-cmd; \
116-
chmod +x bin/console; sync
117-
VOLUME /srv/app/var
158+
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS; \
159+
pecl install xdebug; \
160+
docker-php-ext-enable xdebug; \
161+
apk del .build-deps
118162

119-
RUN echo 'alias sf="php bin/console"' >> ~/.bashrc
120-
RUN echo 'alias phpunit="php vendor/bin/simple-phpunit"' >> ~/.bashrc
121-
RUN echo 'alias stan="php vendor/bin/phpstan"' >> ~/.bashrc
163+
RUN rm -f .env.local.php
122164

123-
ENTRYPOINT ["docker-entrypoint"]
124-
CMD ["php-fpm"]
125-
RUN bash
165+
RUN chown app_user:app_group -R /srv/app
166+
167+
USER app_user
126168

127-
FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder
169+
# Build Caddy with the Mercure and Vulcain modules
170+
FROM caddy:${CADDY_VERSION}-builder-alpine AS app_caddy_builder
128171

129172
RUN xcaddy build \
130173
--with github.com/dunglas/mercure \
131174
--with github.com/dunglas/mercure/caddy \
132175
--with github.com/dunglas/vulcain \
133176
--with github.com/dunglas/vulcain/caddy
134177

135-
FROM caddy:${CADDY_VERSION} AS symfony_caddy
178+
# Caddy image
179+
FROM caddy:${CADDY_VERSION} AS app_caddy
136180

137181
WORKDIR /srv/app
138182

139-
COPY --from=dunglas/mercure:v0.11 /srv/public /srv/mercure-assets/
140-
COPY --from=symfony_caddy_builder /usr/bin/caddy /usr/bin/caddy
141-
COPY --from=symfony_php /srv/app/public public/
183+
COPY --from=app_caddy_builder /usr/bin/caddy /usr/bin/caddy
184+
COPY --from=app_php /srv/app/public public/
142185
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony
1919
## Getting Started
2020

2121
1. If not already done, [install Docker Compose](https://docs.docker.com/compose/install/)
22-
2. Run `docker-compose build --pull --no-cache` to build fresh images
23-
3. Run `docker-compose up` (the logs will be displayed in the current shell)
22+
2. Run `docker compose build --pull --no-cache` to build fresh images
23+
3. Run `docker compose up` (the logs will be displayed in the current shell)
2424
4. Open `https://localhost` in your favorite web browser and [accept the auto-generated TLS certificate](https://stackoverflow.com/a/15076602/1352334)
25-
5. Run `docker-compose down --remove-orphans` to stop the Docker containers.
25+
5. Run `docker compose down --remove-orphans` to stop the Docker containers.
2626

2727
## Features
2828

2929
* Production, development and CI ready
30+
* [Installation of extra Docker Compose services](docs/extra-services.md) with Symfony Flex
3031
* Automatic HTTPS (in dev and in prod!)
3132
* HTTP/2, HTTP/3 and [Preload](https://symfony.com/doc/current/web_link.html) support
3233
* Built-in [Mercure](https://symfony.com/doc/current/mercure.html) hub
3334
* [Vulcain](https://vulcain.rocks) support
35+
* Native [XDebug](docs/xdebug.md) integration
3436
* Just 2 services (PHP FPM and Caddy server)
3537
* Super-readable configuration
3638

@@ -42,7 +44,7 @@ A [Docker](https://www.docker.com/)-based installer and runtime for the [Symfony
4244
2. [Using Symfony Docker with an existing project](docs/existing-project.md)
4345
3. [Support for extra services](docs/extra-services.md)
4446
4. [Deploying in production](docs/production.md)
45-
5. [Installing Xdebug](docs/xdebug.md)
47+
5. [Debugging with Xdebug](docs/xdebug.md)
4648
6. [Using a Makefile](docs/makefile.md)
4749
7. [Troubleshooting](docs/troubleshooting.md)
4850

docker-compose.override.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,25 @@ version: "3.4"
33
# Development environment override
44
services:
55
php:
6+
build:
7+
target: app_php_dev
68
volumes:
7-
# The "cached" option has no effect on Linux but improves performance on Mac
8-
- ./:/srv/app:rw,cached
9-
- ./docker/php/conf.d/symfony.dev.ini:/usr/local/etc/php/conf.d/symfony.ini
10-
# If you develop on Mac you can remove the var/ directory from the bind-mount
11-
# for better performance by enabling the next line
12-
# - /srv/app/var
9+
- ./:/srv/app
10+
- ./docker/php/conf.d/app.dev.ini:/usr/local/etc/php/conf.d/app.dev.ini:ro
11+
# If you develop on Mac or Windows you can remove the vendor/ directory
12+
# from the bind-mount for better performance by enabling the next line:
13+
#- /srv/app/vendor
1314
environment:
14-
APP_ENV: dev
15+
# See https://xdebug.org/docs/all_settings#mode
16+
XDEBUG_MODE: "${XDEBUG_MODE:-off}"
17+
extra_hosts:
18+
# Ensure that host.docker.internal is correctly defined on Linux
19+
- host.docker.internal:host-gateway
1520

1621
caddy:
1722
volumes:
18-
- ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
1923
- ./public:/srv/app/public:ro
24+
- ./docker/caddy/Caddyfile:/etc/caddy/Caddyfile:ro
2025

2126
###> symfony/mercure-bundle ###
2227
###< symfony/mercure-bundle ###

docker-compose.prod.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version: "3.4"
44
services:
55
php:
66
environment:
7-
APP_ENV: prod
87
APP_SECRET: ${APP_SECRET}
98
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET}
109

docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ services:
55
container_name: symfony-php
66
build:
77
context: .
8-
target: symfony_php
8+
target: app_php
99
args:
1010
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
11-
SKELETON: ${SKELETON:-symfony/skeleton}
1211
STABILITY: ${STABILITY:-stable}
1312
USER_ID: ${USER_ID:-1000}
1413
GROUP_ID: ${GROUP_ID:-1000}
@@ -22,7 +21,7 @@ services:
2221
start_period: 30s
2322
environment:
2423
# Run "composer require symfony/orm-pack" to install and configure Doctrine ORM
25-
DATABASE_URL: postgresql://${POSTGRES_USER:-symfony}:${POSTGRES_PASSWORD:-ChangeMe}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-13}
24+
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-14}
2625
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
2726
MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
2827
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
@@ -31,7 +30,7 @@ services:
3130
caddy:
3231
build:
3332
context: .
34-
target: symfony_caddy
33+
target: app_caddy
3534
depends_on:
3635
- php
3736
environment:

docker/caddy/Caddyfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
{
22
# Debug
33
{$DEBUG}
4-
# HTTP/3 support
5-
servers {
6-
protocol {
7-
experimental_http3
8-
}
9-
}
104
}
115

126
{$SERVER_NAME}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
; See https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host
2+
; See https://github.com/docker/for-linux/issues/264
3+
; The `client_host` below may optionally be replaced with `discover_client_host=yes`
4+
; Add `start_with_request=yes` to start debug session on each request
5+
xdebug.client_host = 'host.docker.internal'

0 commit comments

Comments
 (0)