services:
  database:
    image: mariadb:11.4.12@sha256:a794d9eb009e20de605858a11f32f63b4075cbd197c650436f0e3b457e4caed7
    restart: unless-stopped
    environment:
      MARIADB_DATABASE: ${WP_LOCAL_DB_NAME}
      MARIADB_USER: ${WP_LOCAL_DB_USER}
      MARIADB_PASSWORD: ${WP_LOCAL_DB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${WP_LOCAL_DB_ROOT_PASSWORD}
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      timeout: 5s
      retries: 10
    volumes:
      - wordpress_database:/var/lib/mysql

  wordpress:
    image: wordpress:6.9.1-php8.3-apache@sha256:ffef0dca1f0fc4357bfef3856ebd1ba18f7b394378277122eaa4524ca2619d43
    restart: unless-stopped
    depends_on:
      database:
        condition: service_healthy
    environment:
      WORDPRESS_DB_HOST: database:3306
      WORDPRESS_DB_NAME: ${WP_LOCAL_DB_NAME}
      WORDPRESS_DB_USER: ${WP_LOCAL_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WP_LOCAL_DB_PASSWORD}
    ports:
      - "127.0.0.1:8080:80"
    volumes:
      - ./wp-content/mu-plugins/custom-mu-plugin.php:/var/www/html/wp-content/mu-plugins/custom-mu-plugin.php:ro
      - ./wp-content/themes/custom-theme:/var/www/html/wp-content/themes/custom-theme
      - ./wp-content/plugins/custom-plugin:/var/www/html/wp-content/plugins/custom-plugin
      - ./wp-content/mu-plugins/custom-mu-plugin:/var/www/html/wp-content/mu-plugins/custom-mu-plugin
    healthcheck:
      test: ["CMD", "php", "-r", "exit(@file_get_contents('http://127.0.0.1/wp-login.php') === false);"]
      interval: 10s
      timeout: 5s
      retries: 12
      start_period: 30s

volumes:
  wordpress_database:
