name: m3-v2
services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: m3
      POSTGRES_USER: m3
      POSTGRES_PASSWORD: ${M3_POSTGRES_PASSWORD:?Set M3_POSTGRES_PASSWORD}
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "m3", "-d", "m3"]
      interval: 3s
      timeout: 3s
      retries: 20

  community:
    image: ${M3_V2_COMMUNITY_IMAGE:?Set the Community release image}
    restart: unless-stopped
    environment:
      DB_URL: jdbc:postgresql://postgres:5432/m3
      DB_USER: m3
      DB_PASSWORD: ${M3_POSTGRES_PASSWORD:?Set M3_POSTGRES_PASSWORD}
      M3_SECRET_KEY: ${M3_SECRET_KEY:?Set a persistent Base64 32-byte M3_SECRET_KEY}
    volumes:
      - community-data:/app/data/messages
    depends_on:
      postgres:
        condition: service_healthy

  enterprise:
    image: ${M3_V2_ENTERPRISE_IMAGE:?Set the approved Enterprise release image}
    restart: unless-stopped
    environment:
      DB_URL: jdbc:postgresql://postgres:5432/m3
      DB_USER: m3
      DB_PASSWORD: ${M3_POSTGRES_PASSWORD:?Set M3_POSTGRES_PASSWORD}
      COMMUNITY_BASE_URL: http://community:8080
      M3_ENTERPRISE_AUTH_ENABLED: "true"
      M3_BOOTSTRAP_ADMIN_LOGIN: ${M3_BOOTSTRAP_ADMIN_LOGIN:?Set the administrator login}
      M3_BOOTSTRAP_ADMIN_PASSWORD: ${M3_BOOTSTRAP_ADMIN_PASSWORD:?Set the administrator password}
    ports:
      - "127.0.0.1:${M3_V2_PORT:-8090}:8090"
    depends_on:
      postgres:
        condition: service_healthy
      community:
        condition: service_started

volumes:
  postgres-data:
  community-data:
