# 云端部署专用 - 扫雷游戏服务
# 使用方法: docker-compose -f docker-compose.cloud.yml up -d

services:
  nakama-db:
    image: cockroachdb/cockroach:latest-v23.1
    container_name: nakama-db
    command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/
    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

  nakama:
    image: zfc931912343/bindbox-saolei:v1.3
    container_name: nakama-server
    environment:
      # 使用 Docker 内部网络访问后端服务 (需确保在同一网络下)
      - MINESWEEPER_BACKEND_URL=http://blindbox-mms-api:9991/api/internal
    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"
    restart: always
    depends_on:
      nakama-db:
        condition: service_healthy
    volumes:
      - nakama-data:/nakama/data
    ports:
      - "7350:7350"
      - "7351:7351"
      - "9100:9100"
    healthcheck:
      test: [ "CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:7350/" ]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  nakama-db-data:
  nakama-data:

    # 必须加入后端服务所在的网络才能通过 service_name 访问
networks:
  default:
    name: ${DOCKER_NETWORK_NAME:-bindbox_default}
    external: true
