# APP_URL : URL d'accès à l'application prise en compte dans le processus de déploiement.
# Pour le développement local : utiliser une url au format http
# Pour la production : utiliser l'URL complète en https
# Tester votre environnement localement en http sans configurer la variable "LETSENCRYPT_EMAIL" avant de générer vos certificats.
x-common-variables: &common-variables
  APP_URL: "http://localhost"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    restart: always
    volumes:
      - .github/logs/nginx/:/var/log/nginx/
    ports:
      - "80:80"
      - "443:443"
    depends_on:
      database:
        condition: service_healthy
    environment:
        APP_URL: "${APP_URL:-http://localhost}"
        APP_ENV: "${APP_ENV:-production}"
        APP_DEBUG: "${APP_DEBUG:-true}"
        APP_TIMEZONE: "${APP_TIMEZONE:-Europe/Paris}"
        # LETSENCRYPT_EMAIL : E-mail utilisé lors de la génération du certificat SSL.
        # À configurer uniquement pour une génération de certificat SSL public.
        LETSENCRYPT_EMAIL: "${LETSENCRYPT_EMAIL:-}"
        APP_ENVIRONMENT_ONLY: "${APP_ENVIRONMENT_ONLY:-false}"
        CACHE_DRIVER: "${CACHE_DRIVER:-file}"
        SESSION_DRIVER: "${SESSION_DRIVER:-file}"
        QUEUE_DRIVER: "${QUEUE_DRIVER:-database}"
        REDIS_HOST: "${REDIS_HOST:-127.0.0.1}"
        DB_HOST: "${DB_HOST:-database}"
        DB_PORT: "${DB_PORT:-3306}"
        DB_NAME: "${DB_NAME:-clientxcms}"
        DB_PASSWORD: "${DB_PASSWORD:-clientxcms}"
        MAIL_FROM: "${MAIL_FROM:-noreply@example.com}"
        MAIL_DRIVER: "${MAIL_DRIVER:-smtp}"
        MAIL_HOST: "${MAIL_HOST:-smtp.exemple.com}"
        MAIL_PORT: "${MAIL_PORT:-587}"
        MAIL_USERNAME: "${MAIL_USERNAME:-}"
        MAIL_PASSWORD: "${MAIL_PASSWORD:-}"
        MAIL_ENCRYPTION: "${MAIL_ENCRYPTION:-true}"
        DEFAULT_LOCALE: "${DEFAULT_LOCALE:-fr_FR}"
        OAUTH_CLIENT_ID: "${OAUTH_CLIENT_ID:-XXXX}"
        OAUTH_CLIENT_SECRET: "${OAUTH_CLIENT_SECRET:-XXXX}"
    networks:
        - clientxcms-network
  database:
    image: mariadb:10.5
    restart: always
    ports:
      -   3306:3306
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - mariadb-data:/var/lib/mysql
    environment:
      MYSQL_PASSWORD: "clientxcms"
      MYSQL_ROOT_PASSWORD: "clientxcms"
      MYSQL_DATABASE: "clientxcms"
      MYSQL_USER: "clientxcms"
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-pclientxcms"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - clientxcms-network

  # A conserver en cas de besoin mais déconseiller pour un déploiement en production.
  phpmyadmin:
    image: phpmyadmin:latest
    restart: always
    environment:
      PMA_ABSOLUTE_URI: "${APP_URL}/phpmyadmin/"
      PMA_HOSTS: ${PMA_HOSTS:-database}
      UPLOAD_LIMIT: ${UPLOAD_LIMIT:-1024M}
      HIDE_PHP_VERSION: ${HIDE_PHP_VERSION:-true}
      MAX_EXECUTION_TIME: ${MAX_EXECUTION_TIME:-600}
      MEMORY_LIMIT: ${MEMORY_LIMIT:-1024M}
    networks:
      - clientxcms-network

networks:
  clientxcms-network:
    driver: bridge

volumes:
  mariadb-data: