# Production override
# Usage : docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build
#
# Prérequis :
#   - .env.local configuré (APP_ENV=prod, APP_SECRET, DATABASE_URL, MAILER_DSN Brevo)
#   - Assets compilés : npm run build
#   - Après deploy : docker compose exec php php bin/console doctrine:migrations:migrate --no-interaction
#   - Après deploy : docker compose exec php php bin/console cache:clear --env=prod

services:
  php:
    build:
      context: ./docker/php
      dockerfile: Dockerfile
      target: prod
    environment:
      APP_ENV: prod
      APP_DEBUG: 0
    restart: always
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '1.0'
    healthcheck:
      test: ["CMD-SHELL", "php-fpm-healthcheck || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 10s
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  nginx:
    ports:
      - "80:80"
    restart: always
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  db:
    restart: always
    ports: []
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-changeme}
      MYSQL_DATABASE: ${DB_NAME:-blog_web}
      MYSQL_USER: ${DB_USER:-app}
      MYSQL_PASSWORD: ${DB_PASSWORD:-changeme}
    deploy:
      resources:
        limits:
          memory: 512M
          cpus: '1.0'
    command: >
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_unicode_ci
      --innodb-buffer-pool-size=256M
      --innodb-log-file-size=64M
      --max-connections=100
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 30s
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

  # Pas de Mailpit en prod — MAILER_DSN Brevo dans .env.local
  mailer:
    profiles:
      - disabled
