services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
      target: production
    container_name: 3tek_php_prod
    restart: unless-stopped
    volumes:
      - ./public/uploads:/var/www/html/public/uploads
      - ./var/log:/var/www/html/var/log
    environment:
      - APP_ENV=prod
      - APP_DEBUG=0
      - DATABASE_URL=${DATABASE_URL}
      - MAILER_DSN=${MAILER_DSN}
      - MAILER_FROM=${MAILER_FROM}
      - TZ=Europe/Paris
    depends_on:
      database:
        condition: service_healthy
    networks:
      - app_network

  nginx:
    image: nginx:alpine
    container_name: 3tek_nginx_prod
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./public:/var/www/html/public:ro
      - ./public/uploads:/var/www/html/public/uploads
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
      # Décommenter pour SSL
      # - ./ssl:/etc/nginx/ssl:ro
    depends_on:
      - php
    networks:
      - app_network

  database:
    image: mysql:${MYSQL_VERSION:-8.0}
    container_name: 3tek_db_prod
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${MYSQL_DATABASE:-3tek}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      TZ: Europe/Paris
    command: --default-time-zone='+01:00' --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
      timeout: 5s
      retries: 10
      start_period: 60s
      interval: 10s
    volumes:
      - database_data:/var/lib/mysql
    networks:
      - app_network

volumes:
  database_data:
    driver: local

networks:
  app_network:
    driver: bridge
