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" ]
0 commit comments