version: '3.8'

services:
  mini-dm:
    image: mini-dm:latest
    deploy:
      replicas: 2
      update_config:
        parallelism: 1
        delay: 10s
        order: start-first
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
      placement:
        max_replicas_per_node: 1
    networks:
      - mini-dm-network
    ports:
      - '8081:8081'
    environment:
      # LDAP Configuration - Pointant vers les 2 VM
      DM_LDAP_URL: 'ldap://192.168.1.10:389,ldap://192.168.1.11:389'
      DM_LDAP_BASE: 'dc=example,dc=com'
      DM_LDAP_DN: 'cn=admin,dc=example,dc=com'
      DM_LDAP_PWD: 'changeme'
      DM_LDAP_USER_ATTRIBUTE: 'uid'
      DM_MAIL_DOMAIN: 'example.com'

      # Caching LDAP
      DM_LDAP_CACHE_MAX: '1000'
      DM_LDAP_CACHE_TTL: '300'
      DM_LDAP_POOL_SIZE: '5'

      # Application
      DM_PORT: '8081'
      DM_LOG_LEVEL: 'info'
      DM_PLUGINS: 'core/static,core/helloworld'
      DM_API_PREFIX: '/api'

      # Optional: James integration
      # DM_JAMES_WEBADMIN_URL: "http://james:8000"
      # DM_JAMES_WEBADMIN_TOKEN: "secret"

      # Optional: Calendar integration
      # DM_CALENDAR_WEBADMIN_URL: "http://calendar:8080"
      # DM_CALENDAR_WEBADMIN_TOKEN: "secret"
    healthcheck:
      test:
        [
          'CMD',
          'wget',
          '--quiet',
          '--tries=1',
          '--spider',
          'http://localhost:8081/api/health',
        ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

networks:
  mini-dm-network:
    driver: overlay
    attachable: true
