# 查价中台 — 宝塔宿主机 MySQL + Docker 内 Redis（无容器 MySQL）
# 服务器：192.168.2.14  代码目录：/home/project/chajia  对外端口：30325
#
# 用法（在项目根目录 /home/project/chajia）：
#   cp deploy/.env.bt-host-mysql.example .env   # 若根目录尚无 .env
#   bash deploy/install-bt-host-mysql.sh

name: chajia-bt

services:
  redis:
    image: redis:7-alpine
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 10
    networks:
      - internal

  next-app:
    build:
      context: ..
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_EMBED_DEMO_SERVICE_TOKEN: ${NEXT_PUBLIC_EMBED_DEMO_SERVICE_TOKEN:-chajia-neibu-2026}
        NEXT_PUBLIC_EMBED_DEMO_CUSTOMER_ID: ${NEXT_PUBLIC_EMBED_DEMO_CUSTOMER_ID:-CUST_001}
    restart: unless-stopped
    env_file:
      - ../.env
    environment:
      NODE_ENV: production
      REDIS_URL: redis://redis:6379
      RPA_AUTO_BOOTSTRAP_STORAGE: "false"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - rpa_state:/app/.rpa
    ports:
      - "0.0.0.0:30325:3000"
    depends_on:
      redis:
        condition: service_healthy
    healthcheck:
      test:
        [
          "CMD-SHELL",
          "node -e \"require('http').get('http://127.0.0.1:3000',(r)=>process.exit(r.statusCode<500?0:1)).on('error',()=>process.exit(1))\"",
        ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 90s
    networks:
      - internal

  rpa-worker:
    build:
      context: ..
      dockerfile: Dockerfile.worker
    restart: unless-stopped
    env_file:
      - ../.env
    environment:
      NODE_ENV: production
      REDIS_URL: redis://redis:6379
      PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - rpa_state:/app/.rpa
    depends_on:
      redis:
        condition: service_healthy
      next-app:
        condition: service_started
    shm_size: "2gb"
    networks:
      - internal

  scheduler:
    build:
      context: ..
      dockerfile: Dockerfile.worker
    restart: unless-stopped
    command: ["npm", "run", "worker:scheduler"]
    env_file:
      - ../.env
    environment:
      NODE_ENV: production
      REDIS_URL: redis://redis:6379
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      redis:
        condition: service_healthy
    networks:
      - internal

volumes:
  redis_data:
  rpa_state:

networks:
  internal:
    driver: bridge
