Skip to content

Commit 00a136a

Browse files
committed
Update with Caddy
1 parent 0bac93e commit 00a136a

File tree

8 files changed

+426
-21
lines changed

8 files changed

+426
-21
lines changed

Dockerfile

Lines changed: 178 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,185 @@
1-
FROM registry.realtoken.community/docker-symfony-php:8.4
1+
# FROM registry.realtoken.community/docker-symfony-php:8.4
2+
#
3+
# WORKDIR /var/www/html
4+
# COPY . ./
5+
#
6+
# ARG APP_ENV=prod
7+
# ARG DATABASE_URL
8+
# ENV APP_ENV=${APP_ENV}
9+
# ENV DATABASE_URL=${DATABASE_URL}
10+
#
11+
# RUN composer install --prefer-dist --no-interaction --optimize-autoloader --no-progress
12+
# RUN composer dump-env ${APP_ENV}
13+
# RUN composer run-script --no-dev post-install-cmd
14+
#
15+
# # HTTPS
16+
# ENV HTTPS=false
17+
#
18+
# # Nginx
19+
# COPY docker/nginx.conf /etc/nginx/nginx.conf
20+
#
21+
# RUN mkdir -p var/cache/${APP_ENV}
22+
# RUN chmod -R 777 var/cache/${APP_ENV}
23+
#
24+
# CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
225

3-
WORKDIR /var/www/html
4-
COPY . ./
526

6-
ARG APP_ENV=prod
7-
ARG DATABASE_URL
8-
ENV APP_ENV=${APP_ENV}
9-
ENV DATABASE_URL=${DATABASE_URL}
27+
ARG BASE_IMAGE=dunglas/frankenphp:1-php8.4
28+
# ===============================================
29+
# Stage 1: Dependencies
30+
# ===============================================
31+
FROM composer:2 AS dependencies
1032

11-
RUN composer install --prefer-dist --no-interaction --optimize-autoloader --no-progress
12-
RUN composer dump-env ${APP_ENV}
13-
RUN composer run-script --no-dev post-install-cmd
33+
WORKDIR /app
1434

15-
# HTTPS
16-
ENV HTTPS=false
35+
# Copie uniquement les fichiers de dépendances pour cache Docker
36+
COPY composer.json composer.lock symfony.lock ./
1737

18-
# Nginx
19-
COPY docker/nginx.conf /etc/nginx/nginx.conf
38+
# Installation des dépendances
39+
RUN composer install \
40+
--no-scripts \
41+
--no-autoloader \
42+
--no-interaction \
43+
--no-progress \
44+
--prefer-dist
2045

21-
RUN mkdir -p var/cache/${APP_ENV}
22-
RUN chmod -R 777 var/cache/${APP_ENV}
46+
# ===============================================
47+
# Stage 2: Development
48+
# ===============================================
49+
FROM ${BASE_IMAGE} AS development
2350

24-
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
51+
# Copier Composer depuis l'image officielle
52+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
53+
54+
# Installation des extensions PHP nécessaires
55+
# On nettoie le cache APT pour libérer de l'espace
56+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* && \
57+
install-php-extensions \
58+
pdo_mysql \
59+
redis \
60+
intl \
61+
sysvsem \
62+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
63+
64+
WORKDIR /app
65+
66+
# Copier les dépendances
67+
COPY --from=dependencies /app/vendor ./vendor
68+
69+
# Copier le code
70+
COPY --chown=www-data:www-data . .
71+
72+
# Installer avec dev dependencies
73+
RUN composer install \
74+
--optimize-autoloader \
75+
--no-interaction \
76+
--no-progress
77+
78+
# Permissions correctes
79+
RUN mkdir -p var/cache var/log \
80+
&& chown -R www-data:www-data var/ \
81+
&& chmod -R 775 var/
82+
83+
# Créer les répertoires nécessaires pour Caddy/FrankenPHP
84+
RUN mkdir -p /data/caddy /config/caddy \
85+
&& chown -R www-data:www-data /data/caddy /config/caddy \
86+
&& chmod -R 755 /data/caddy /config/caddy
87+
88+
# Copier la configuration Caddy
89+
COPY docker/Caddyfile /etc/caddy/Caddyfile
90+
91+
# Variables d'environnement dev
92+
ENV APP_ENV=dev
93+
ENV APP_DEBUG=1
94+
ENV FRANKENPHP_CONFIG="worker ./public/index.php"
95+
96+
USER www-data
97+
98+
EXPOSE 80
99+
100+
CMD ["frankenphp", "run", "--config", "/etc/caddy/Caddyfile"]
101+
102+
# ===============================================
103+
# Stage 3: Builder (préparation production)
104+
# ===============================================
105+
FROM dependencies AS builder
106+
107+
WORKDIR /app
108+
109+
# Copier tout le code source
110+
COPY . .
111+
112+
# Installation des dépendances SANS dev
113+
RUN composer install \
114+
--no-dev \
115+
--optimize-autoloader \
116+
--classmap-authoritative \
117+
--no-interaction \
118+
--no-progress \
119+
--prefer-dist
120+
121+
# Optimisations Symfony pour production
122+
RUN composer dump-autoload --no-dev --classmap-authoritative
123+
124+
# Suppression des fichiers inutiles en production
125+
RUN rm -rf tests/ .git/ .github/ docker/ \
126+
&& find . -name ".git*" -type f -delete
127+
128+
# ===============================================
129+
# Stage 4: Production
130+
# ===============================================
131+
FROM dunglas/frankenphp:1-php8.3 AS production
132+
133+
# Copier Composer depuis l'image officielle
134+
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
135+
136+
# Installation des extensions PHP
137+
RUN apt-get clean && rm -rf /var/lib/apt/lists/* && \
138+
install-php-extensions \
139+
pdo_mysql \
140+
redis \
141+
intl \
142+
apcu \
143+
sysvsem \
144+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
145+
146+
# Configuration PHP production
147+
COPY docker/php/php-prod.ini /usr/local/etc/php/conf.d/99-prod.ini
148+
149+
WORKDIR /app
150+
151+
# Copier depuis le builder (code optimisé)
152+
COPY --from=builder --chown=www-data:www-data /app /app
153+
154+
# Configuration Caddy production
155+
COPY docker/Caddyfile.prod /etc/caddy/Caddyfile
156+
157+
# Permissions strictes
158+
RUN chown -R www-data:www-data /app \
159+
&& chmod -R 755 /app \
160+
&& mkdir -p var/cache/prod var/log \
161+
&& chown -R www-data:www-data var/ \
162+
&& chmod -R 775 var/
163+
164+
# Créer les répertoires nécessaires pour Caddy/FrankenPHP
165+
RUN mkdir -p /data/caddy /config/caddy \
166+
&& chown -R www-data:www-data /data/caddy /config/caddy \
167+
&& chmod -R 755 /data/caddy /config/caddy
168+
169+
# Variables d'environnement production
170+
ENV APP_ENV=prod
171+
ENV APP_DEBUG=0
172+
ENV FRANKENPHP_CONFIG="worker ./public/index.php"
173+
174+
# Warmup du cache Symfony
175+
RUN php bin/console cache:clear --env=prod --no-debug || true \
176+
&& php bin/console cache:warmup --env=prod --no-debug || true
177+
178+
USER www-data
179+
180+
EXPOSE 80
181+
182+
HEALTHCHECK --interval=30s --timeout=3s --start-period=60s --retries=3 \
183+
CMD curl -f http://localhost/health || exit 1
184+
185+
CMD ["frankenphp", "run", "--config", "/etc/caddy/Caddyfile"]

docker-compose-branch.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ services:
22
symfony:
33
image: ${DOCKER_REGISTRY}/api-php:${DOCKER_BRANCH}
44
container_name: ${DOCKER_BRANCH}-api_php-sf
5+
# build:
6+
# context: ./
57
build:
6-
context: ./
7-
environment:
8-
APP_ENV: ${APP_ENV}
9-
DATABASE_URL: ${DATABASE_URL}
8+
context: .
9+
dockerfile: Dockerfile
10+
target: development
11+
# environment:
12+
# APP_ENV: ${APP_ENV}
13+
# DATABASE_URL: ${DATABASE_URL}
1014
networks:
1115
- api-php
1216
- traefik-realt

docker/Caddyfile.prod

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# ===============================================
2+
# Caddyfile Production - Optimisé
3+
# ===============================================
4+
5+
{
6+
# Mode FrankenPHP avec worker pour maximum de performance
7+
frankenphp {
8+
num_threads 4
9+
# Mode worker pour Symfony (garde l'app en mémoire)
10+
worker {
11+
file /app/public/index.php
12+
num 2
13+
env APP_RUNTIME App\Runtime\FrankenPhpRuntime
14+
}
15+
}
16+
17+
order php_server before file_server
18+
19+
# Logs minimaux en production
20+
log {
21+
output stdout
22+
level WARN
23+
}
24+
}
25+
26+
:80 {
27+
root * /app/public
28+
29+
# Compression optimisée
30+
encode {
31+
gzip 6
32+
zstd
33+
}
34+
35+
request_body {
36+
max_size 100MB
37+
}
38+
39+
trusted_proxies static 172.18.0.0/24
40+
41+
# Logs production (minimal)
42+
log {
43+
output discard
44+
}
45+
46+
# Cache statique agressif
47+
@static {
48+
path *.css *.js *.jpg *.jpeg *.png *.gif *.ico *.svg *.woff *.woff2 *.ttf *.eot
49+
}
50+
header @static {
51+
Cache-Control "public, max-age=31536000, immutable"
52+
}
53+
54+
# Symfony routing avec worker mode
55+
php_server {
56+
resolve_root_symlink
57+
}
58+
59+
file_server
60+
61+
# Headers de sécurité renforcés
62+
header {
63+
-Server
64+
X-Content-Type-Options "nosniff"
65+
X-Frame-Options "SAMEORIGIN"
66+
X-XSS-Protection "1; mode=block"
67+
Referrer-Policy "no-referrer-when-downgrade"
68+
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
69+
}
70+
71+
# Health check endpoint
72+
handle /health {
73+
respond "OK" 200
74+
}
75+
}

docker/php/php-common.ini

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; ===============================================
2+
; docker/php/php-common.ini
3+
; Configuration commune à tous les environnements
4+
; ===============================================
5+
6+
; Date et timezone
7+
date.timezone = Europe/Paris
8+
9+
; Upload de fichiers
10+
upload_max_filesize = 10M
11+
post_max_size = 10M
12+
max_file_uploads = 20
13+
14+
; Exécution
15+
max_execution_time = 30
16+
max_input_time = 60
17+
18+
; Session
19+
session.cookie_httponly = 1
20+
session.cookie_secure = 1
21+
session.use_strict_mode = 1
22+
23+
; Sécurité
24+
expose_php = Off
25+
allow_url_fopen = On
26+
allow_url_include = Off
27+
28+
; Performance
29+
realpath_cache_size = 4096K
30+
realpath_cache_ttl = 600

docker/php/php-dev.ini

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; ===============================================
2+
; docker/php/php-dev.ini
3+
; Configuration développement
4+
; ===============================================
5+
6+
; Mémoire (généreuse en dev)
7+
memory_limit = 512M
8+
9+
; Affichage des erreurs
10+
display_errors = On
11+
display_startup_errors = On
12+
error_reporting = E_ALL
13+
log_errors = On
14+
error_log = /var/www/html/var/log/php_errors.log
15+
16+
; OPcache (avec validation pour hot-reload)
17+
opcache.enable = 1
18+
opcache.enable_cli = 1
19+
opcache.memory_consumption = 128
20+
opcache.max_accelerated_files = 10000
21+
opcache.validate_timestamps = 1
22+
opcache.revalidate_freq = 0
23+
opcache.interned_strings_buffer = 8
24+
25+
; Xdebug (si installé)
26+
xdebug.mode = debug,coverage
27+
xdebug.start_with_request = yes
28+
xdebug.client_host = host.docker.internal
29+
xdebug.client_port = 9003
30+
xdebug.idekey = PHPSTORM
31+
xdebug.max_nesting_level = 512
32+
33+
; Upload (plus généreux en dev)
34+
upload_max_filesize = 20M
35+
post_max_size = 20M

0 commit comments

Comments
 (0)