services:
  db:
    image: mysql:8.0
    # MySQL 8.0 multi-arch (ARM64)
    restart: always
    env_file:
      - .env
    environment:
      MYSQL_DATABASE: ${WORDPRESS_DB_NAME}
      MYSQL_USER: ${WORDPRESS_DB_USER}
      MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: rootpassword
    # WordPress requires mysql_native_password
    command: --default-authentication-plugin=mysql_native_password

  wordpress:
    depends_on:
      - db
    links:
      - db
    image: wordpress:latest
    ports:
      - "8000:80"
    restart: always
    volumes:
      # Monte uniquement le dossier des contenus (thèmes, plugins, uploads)
      - ./wordpress/wp-content:/var/www/html/wp-content
      # Persiste le reste du core dans un volume Docker
      - wordpress_core:/var/www/html
      - ./php-config/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
    env_file:
      - .env
    environment:
      WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
      WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}

  wpcli:
    image: wordpress:cli
    depends_on:
      - db
      - wordpress
    links:
      - db
    volumes:
      - ./wordpress/wp-content:/var/www/html/wp-content
      - wordpress_core:/var/www/html
    entrypoint: ["sleep", "infinity"]
    env_file:
      - .env
    environment:
      WORDPRESS_DB_HOST: ${WORDPRESS_DB_HOST}
      WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - "8080:80"
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
    env_file:
      - .env

volumes:
  db_data:
  wordpress_core: