# 生产形态（客户内网私有化单机部署）。
# 开发不需要它：make dev 用 SQLite + 进程内总线 + 本地目录，零外部依赖。
#
# 注意：Host Agent 不在这里。它跑在客户的测试主机上（Windows 服务 / systemd），
# 不进容器——它要碰真实设备、真实驱动、真实串口。

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: flashops
      POSTGRES_USER: flashops
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?必须设置}
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U flashops"]
      interval: 5s
      timeout: 3s
      retries: 10
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    command: redis-server --appendonly yes
    volumes:
      - redisdata:/data
    restart: unless-stopped

  minio:
    image: minio/minio:latest
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${MINIO_USER:-flashops}
      MINIO_ROOT_PASSWORD: ${MINIO_PASSWORD:?必须设置}
    volumes:
      - miniodata:/data
    ports:
      - "9001:9001"   # 控制台，仅内网暴露
    restart: unless-stopped

  control-plane:
    build:
      context: .
      dockerfile: services/control-plane/Dockerfile
    environment:
      FLASHOPS_DATABASE_URL: postgresql+asyncpg://flashops:${POSTGRES_PASSWORD}@postgres:5432/flashops
      FLASHOPS_BUS_URL: redis://redis:6379/0
      FLASHOPS_OBJECT_STORE_URL: s3://minio:9000/flashops
      FLASHOPS_OBJECT_STORE_KEY: ${MINIO_USER:-flashops}
      FLASHOPS_OBJECT_STORE_SECRET: ${MINIO_PASSWORD}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
      minio:
        condition: service_started
    ports:
      - "8000:8000"   # Agent 要能连上，所以对实验室网段开放
    restart: unless-stopped

  console:
    build:
      context: .
      dockerfile: apps/console/Dockerfile
    environment:
      FLASHOPS_API_BASE: http://control-plane:8000
    depends_on:
      - control-plane
    ports:
      - "3000:3000"
    restart: unless-stopped

volumes:
  pgdata:
  redisdata:
  miniodata:
