# 全量服务部署 (后端 + 游戏服 + 数据库)
# 使用方法: docker-compose -f docker-compose.all.yml up -d
services:
  # ----------------------------------------------------
  # 1. 业务后端 (Bindbox Game Backend)
  # ----------------------------------------------------
  bindbox-game:
    image: zfc931912343/bindbox-game:v1.12
    container_name: bindbox-game
    restart: always
    ports:
      - "9991:9991"
    volumes:
      - ../bindbox_game/logs:/app/logs
    #      - ../bindbox_game/configs:/app/configs # 指向 bindbox_game 目录下的配置
    environment:
      - ACTIVE_ENV=pro
      - TZ=Asia/Shanghai
    networks:
      - bindbox_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
  # ----------------------------------------------------
  # 2. 游戏数据库 (CockroachDB for Nakama)
  # ----------------------------------------------------
  nakama-db:
    image: cockroachdb/cockroach:latest-v23.1
    container_name: nakama-db
    command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/ --cache=.25 --max-sql-memory=.25
    restart: always
    volumes:
      - nakama-db-data:/var/lib/cockroach
    ports:
      - "26257:26257"
      - "8081:8080"
    healthcheck:
      test: [ "CMD", "curl", "-f", "http://localhost:8080/health?ready=1" ]
      interval: 3s
      timeout: 3s
      retries: 5
    environment:
      - TZ=Asia/Shanghai
    networks:
      - bindbox_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
  # ----------------------------------------------------
  # 3. 游戏服务器 (Nakama)
  # ----------------------------------------------------
  nakama:
    image: zfc931912343/bindbox-saolei:v1.5
    container_name: nakama-server
    environment:
      # 直接使用服务名访问后端
      - MINESWEEPER_BACKEND_URL=http://bindbox-game:9991/api/internal
      - TZ=Asia/Shanghai
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - "/nakama/nakama migrate up --database.address root@nakama-db:26257 && exec /nakama/nakama --name nakama1 --database.address root@nakama-db:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100 --runtime.path /nakama/modules --matchmaker.interval_sec 1 --matchmaker.max_intervals 5"
    restart: always
    depends_on:
      nakama-db:
        condition: service_healthy
      bindbox-game:
        condition: service_started
    volumes:
      - nakama-data:/nakama/data
    ports:
      - "7350:7350"
      - "7351:7351"
      - "9100:9100"
    healthcheck:
      test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://bindbox-game:9991/" ]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - bindbox_net
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"
volumes:
  nakama-db-data:
  nakama-data:
networks:
  bindbox_net:
    name: bindbox_net
    driver: bridge
