version: '3.8'

services:
  # 即梦 API 服务
  jimeng-free-api:
    build:
      context: ./
      dockerfile: Dockerfile
    image: jimeng-free-api:latest
    container_name: jimeng-free-api
    restart: unless-stopped
    environment:
      - NODE_ENV=production
      - SERVICE_ID=${SERVICE_ID:-jimeng-free-api}
      - INSTANCE_ID=${INSTANCE_ID:-instance-1}
      - SERVICE_NAME=${SERVICE_NAME:-jimeng-free-api}
      - HOST=${HOST:-0.0.0.0}
      - PORT=${API_PORT:-3302}
      - TOS_ACCESS_KEY_ID=${TOS_ACCESS_KEY_ID}
      - TOS_ACCESS_KEY_SECRET=${TOS_ACCESS_KEY_SECRET}
      - TOS_BUCKET_NAME=${TOS_BUCKET_NAME}
      - TOS_SELF_DOMAIN=${TOS_SELF_DOMAIN}
      - TOS_REGION=${TOS_REGION:-cn-beijing}
      - TOS_ENDPOINT=${TOS_ENDPOINT:-tos-cn-beijing.volces.com}
      # 心跳配置已移除（使用 NeDB 本地存储）
      - USE_DATABASE_MODE=${USE_DATABASE_MODE:-false}
      - MAX_CONCURRENT_TASKS=${MAX_CONCURRENT_TASKS:-3}
      - TASK_POLL_INTERVAL=${TASK_POLL_INTERVAL:-5}
      - IMAGE_TASK_TIMEOUT=${IMAGE_TASK_TIMEOUT:-3600}
      - VIDEO_TASK_TIMEOUT=${VIDEO_TASK_TIMEOUT:-86400}
      - RESULT_EXPIRE_TIME=${RESULT_EXPIRE_TIME:-86400}
    ports:
      - "${API_PORT:-3302}:${API_PORT:-3302}"
    volumes:
      - ./logs:/app/logs
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:${API_PORT:-3302}/ping"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s