# Stack WordPress headless Covalba — VPS srv1255941 (cohabite avec le dashboard
# nginx/cinik-dash : pas de reverse proxy ici, nginx hôte + certbot terminent le TLS
# et proxifient covalba-admin.paf-studio.dev -> 127.0.0.1:8080).
name: covalba-wp

x-wp-env: &wp-env
  WORDPRESS_DB_HOST: db
  WORDPRESS_DB_NAME: covalba
  WORDPRESS_DB_USER: covalba
  WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
  COVALBA_REVALIDATE_SECRET: ${COVALBA_REVALIDATE_SECRET:-}
  COVALBA_FRONT_URLS: ${COVALBA_FRONT_URLS:-}
  COVALBA_CHATBOT_APP_URL: ${COVALBA_CHATBOT_APP_URL:-}
  COVALBA_CHATBOT_ADMIN_TOKEN: ${COVALBA_CHATBOT_ADMIN_TOKEN:-}
  ACF_PRO_LICENSE: ${ACF_PRO_LICENSE:-}
  # Évalué au runtime par wp-config.php (getenv_docker) : doit être présent
  # dans TOUS les conteneurs qui exécutent WordPress (wordpress ET wpcli).
  WORDPRESS_CONFIG_EXTRA: |
    define('WP_HOME', 'https://covalba-admin.paf-studio.dev');
    define('WP_SITEURL', 'https://covalba-admin.paf-studio.dev');
    define('DISABLE_WP_CRON', true);
    define('DISALLOW_FILE_EDIT', true);
    define('AUTOMATIC_UPDATER_DISABLED', true);
    define('WP_POST_REVISIONS', 5);
    define('WP_ENVIRONMENT_TYPE', 'production');
    define('FORCE_SSL_ADMIN', true);
    define('WP_REDIS_HOST', 'redis');
    define('WP_MEMORY_LIMIT', '256M');
    define('COVALBA_REVALIDATE_SECRET', getenv('COVALBA_REVALIDATE_SECRET') ?: '');
    define('COVALBA_FRONT_URLS', getenv('COVALBA_FRONT_URLS') ?: '');
    define('COVALBA_CHATBOT_APP_URL', getenv('COVALBA_CHATBOT_APP_URL') ?: '');
    define('COVALBA_CHATBOT_ADMIN_TOKEN', getenv('COVALBA_CHATBOT_ADMIN_TOKEN') ?: '');
    define('ACF_PRO_LICENSE', getenv('ACF_PRO_LICENSE') ?: '');

services:
  db:
    image: mariadb:11
    restart: unless-stopped
    environment:
      MARIADB_DATABASE: covalba
      MARIADB_USER: covalba
      MARIADB_PASSWORD: ${DB_PASSWORD}
      MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    # buffer modeste : le VPS est partagé avec un dashboard Next + Postgres.
    # max-connections relevé à 200 pour absorber le build statique Next (des
    # centaines de pages) ; le front borne aussi sa concurrence (WP_FETCH_CONCURRENCY).
    command: --innodb-buffer-pool-size=256M --max-connections=200
    volumes:
      - ./db-data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      interval: 10s
      retries: 6

  wordpress:
    image: wordpress:6.8-php8.3-apache
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "127.0.0.1:8080:80"
    environment:
      <<: *wp-env
    volumes:
      - wp-core:/var/www/html
      - ./wp-content:/var/www/html/wp-content
      - ./php-overrides.ini:/usr/local/etc/php/conf.d/zz-overrides.ini:ro

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: --maxmemory 128mb --maxmemory-policy allkeys-lru

  wpcli:
    image: wordpress:cli-php8.3
    profiles: ["tools"]
    user: "33:33"
    depends_on:
      db:
        condition: service_healthy
    environment:
      <<: *wp-env
    volumes:
      - wp-core:/var/www/html
      - ./wp-content:/var/www/html/wp-content

volumes:
  wp-core:
