refactor(infra) : align prod setup with Lesstime pattern
Some checks failed
Auto Tag Develop / tag (push) Has been cancelled

Single container with supervisord (Nginx + PHP-FPM), 3-stage
Dockerfile build, pre-built image from registry, port 8086.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-04-07 14:53:10 +02:00
parent 34adb01cbb
commit 389bfbef13
5 changed files with 115 additions and 122 deletions

View File

@@ -1,88 +1,81 @@
ARG DOCKER_PHP_VERSION=8.4.6
# --- Stage 1: Build backend ---
FROM php:8.4-cli AS backend-build
FROM php:${DOCKER_PHP_VERSION}-fpm-bullseye AS php-base
ARG DOCKER_NODE_VERSION=24.12.0
ENV DOCKER_NODE_VERSION="${DOCKER_NODE_VERSION}"
# Installer les dépendances et extensions PHP nécessaires
RUN apt-get update && apt-get install -y \
libicu-dev \
libpq-dev \
libpng-dev \
libzip-dev \
libxml2-dev \
ca-certificates \
gnupg \
libbz2-dev \
libgmp-dev \
libldap2-dev \
libonig-dev \
libsodium-dev \
libxslt1-dev \
zlib1g-dev \
libssl-dev \
wget \
git \
unzip \
&& docker-php-ext-install -j$(nproc) \
intl \
zip \
bcmath \
bz2 \
calendar \
exif \
gd \
gettext \
gmp \
ldap \
pcntl \
pdo_pgsql \
soap \
sockets \
sysvsem \
xsl \
&& docker-php-ext-enable opcache \
&& rm -rf /var/lib/apt/lists/* /tmp/*
libicu-dev libpq-dev libpng-dev libzip-dev libxml2-dev \
unzip curl git \
&& docker-php-ext-install -j$(nproc) intl pdo_pgsql zip gd opcache \
&& rm -rf /var/lib/apt/lists/*
# Installation de node
RUN wget -qO- "https://nodejs.org/dist/v${DOCKER_NODE_VERSION}/node-v${DOCKER_NODE_VERSION}-linux-x64.tar.xz" | tar xJC /tmp/ && \
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/bin /usr/ && \
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/include /usr/ && \
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/lib /usr/ && \
cp -r /tmp/node-v${DOCKER_NODE_VERSION}-linux-x64/share /usr/ && \
rm -rf /tmp/*
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# Installation de composer
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
WORKDIR /app
COPY composer.json composer.lock ./
RUN APP_ENV=prod APP_DEBUG=0 composer install --no-dev --no-scripts --no-interaction
WORKDIR /var/www/html
COPY bin bin/
COPY config config/
COPY migrations migrations/
COPY public public/
COPY src src/
ENV APP_ENV=prod
RUN composer dump-autoload --optimize --no-dev
# Copier les fichiers projet
COPY . /var/www/html
# --- Stage 2: Build frontend ---
FROM node:lts-alpine AS frontend-build
# Installation des dépendances PHP (prod)
RUN composer install --no-dev --optimize-autoloader --no-interaction
WORKDIR /app/frontend
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
# Génération des clés JWT si absentes
RUN php bin/console lexik:jwt:generate-keypair --skip-if-exists
COPY frontend/ ./
ENV CI=1 \
NUXT_TELEMETRY_DISABLED=1 \
NUXT_PUBLIC_API_BASE=/api \
NUXT_PUBLIC_APP_BASE=/
RUN npm run generate
# Build du frontend
RUN cd frontend && npm ci && npm run build:dist && rm -rf node_modules
# --- Stage 3: Production image ---
FROM php:8.4-fpm AS production
RUN apt-get update && apt-get install -y \
libicu-dev libpq-dev libpng-dev libzip-dev libxml2-dev \
nginx supervisor \
&& docker-php-ext-install -j$(nproc) intl pdo_pgsql zip gd opcache \
&& rm -rf /var/lib/apt/lists/*
# PHP production config
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# PHP-FPM: forward worker output to stderr for docker logs
RUN echo "catch_workers_output = yes" >> /usr/local/etc/php-fpm.d/www.conf \
&& echo "decorate_workers_output = no" >> /usr/local/etc/php-fpm.d/www.conf
# Nginx: log to stdout/stderr
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
# Remove default nginx site
RUN rm -f /etc/nginx/sites-enabled/default
# Configs
COPY infra/prod/supervisord.conf /etc/supervisor/conf.d/app.conf
COPY infra/prod/nginx.conf /etc/nginx/sites-enabled/coltura.conf
# Backend from stage 1
COPY --from=backend-build /app /var/www/html
# Frontend from stage 2
COPY --from=frontend-build /app/frontend/.output/public /var/www/html/frontend/.output/public
# Symfony needs a .env file to boot (variables are overridden by env_file in docker-compose)
RUN echo "APP_ENV=prod" > /var/www/html/.env
# Permissions
RUN chown -R www-data:www-data /var/www/html/var /var/www/html/frontend/dist
RUN mkdir -p /var/www/html/var /var/www/html/config/jwt \
&& chown -R www-data:www-data /var/www/html/var
# PHP prod config
COPY infra/prod/php-prod.ini /usr/local/etc/php/php.ini
WORKDIR /var/www/html
EXPOSE 80
EXPOSE 9000
# ── Nginx stage ──
FROM nginx:1.27-alpine AS nginx
COPY infra/prod/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=php-base /var/www/html/public /var/www/html/public
COPY --from=php-base /var/www/html/frontend/dist /var/www/html/frontend/dist
CMD ["supervisord", "-n", "-c", "/etc/supervisor/conf.d/app.conf"]