# Harbor Desk 資料服務：Mongo + Redis + MinIO + Mailpit
# 只綁 127.0.0.1；gateway / vite 跑在宿主。
#
#   docker compose --env-file deploy/.env.dev -f deploy/docker-compose.infra.yml up -d
#   或：./deploy/scripts/up-infra.sh
name: haixun-infra

services:
  mongo:
    image: mongo:7
    restart: unless-stopped
    ports:
      - "127.0.0.1:${MONGO_PORT:-27017}:27017"
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USER:-haixun}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD:?MONGO_ROOT_PASSWORD is required}
      MONGO_INITDB_DATABASE: ${MONGO_DATABASE:-haixun}
    volumes:
      - mongo_data:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping')"]
      interval: 10s
      timeout: 5s
      retries: 8
      start_period: 25s
    networks:
      - haixun-infra

  redis:
    image: redis:7
    restart: unless-stopped
    command:
      [
        "redis-server",
        "--requirepass",
        "${REDIS_PASSWORD:?REDIS_PASSWORD is required}",
        "--appendonly",
        "yes",
      ]
    ports:
      - "127.0.0.1:${REDIS_PORT:-6379}:6379"
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "${REDIS_PASSWORD}", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    networks:
      - haixun-infra

  minio:
    image: minio/minio:RELEASE.2025-04-22T22-12-26Z
    restart: unless-stopped
    command: ["server", "/data", "--console-address", ":9001"]
    ports:
      - "127.0.0.1:${MINIO_API_PORT:-9000}:9000"
      - "127.0.0.1:${MINIO_CONSOLE_PORT:-9001}:9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_ROOT_USER:-haixun}
      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:?MINIO_ROOT_PASSWORD is required}
    volumes:
      - minio_data:/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:9000/minio/health/live"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s
    networks:
      - haixun-infra

  mailpit:
    image: axllent/mailpit:v1.27
    restart: unless-stopped
    environment:
      MP_SMTP_AUTH_ACCEPT_ANY: "true"
      MP_SMTP_AUTH_ALLOW_INSECURE: "true"
    ports:
      - "127.0.0.1:${MAILPIT_SMTP_PORT:-1025}:1025"
      - "${MAILPIT_UI_PORT:-8025}:8025"
    networks:
      - haixun-infra

volumes:
  mongo_data:
  redis_data:
  minio_data:

networks:
  haixun-infra:
    name: haixun-infra
