version: "3.9"

services:
  db_festival:
    image: mysql:8.0.37
    container_name: mysql_festival
    command:
      - --default-authentication-plugin=mysql_native_password
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-wordpress}
      MYSQL_USER: ${MYSQL_USER:-wordpress}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-wordpress}
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h localhost -u $$MYSQL_USER -p$$MYSQL_PASSWORD || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 6
    restart: unless-stopped
    networks:
      - backend

  wordpress:
    image: wordpress:6.8.2-php8.2-apache
    container_name: wordpress_festival
    depends_on:
      db_festival:
        condition: service_healthy
    environment:
      WORDPRESS_DB_HOST: db_festival:3306
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE:-wordpress}
      WORDPRESS_DB_USER: ${MYSQL_USER:-wordpress}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD:-wordpress}
      WORDPRESS_DEBUG: ${WORDPRESS_DEBUG:-0}
    volumes:
      - ./wp_data:/var/www/html
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini:ro
    # Bind uniquement en local : Apache fera le reverse proxy vers ces ports
    ports:
      - "127.0.0.1:8182:80"
    healthcheck:
      test: ["CMD-SHELL", "curl -fsS http://localhost/ || exit 1"]
      interval: 15s
      timeout: 5s
      retries: 6
    restart: unless-stopped
    networks:
      - backend

  phpmyadmin:
    image: phpmyadmin:5.2.1-apache
    container_name: phpmyadmin_festival
    depends_on:
      db_festival:
        condition: service_healthy
    environment:
      PMA_HOST: db_festival
      PMA_USER: ${MYSQL_USER:-wordpress}
      PMA_PASSWORD: ${MYSQL_PASSWORD:-wordpress}
    ports:
      - "127.0.0.1:8882:80"
    restart: unless-stopped
    networks:
      - backend

  wpcli:
    image: wordpress:cli-php8.2
    user: "www-data"
    depends_on:
      db_festival:
        condition: service_healthy
    environment:
      WORDPRESS_DB_HOST: db_festival:3306
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE:-wordpress}
      WORDPRESS_DB_USER: ${MYSQL_USER:-wordpress}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD:-wordpress}
    volumes:
      - ./wp_data:/var/www/html
    networks:
      - backend
    entrypoint: ["wp"]

volumes:
  db_data:
  wp_data:

networks:
  backend:
    driver: bridge
