services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: investor-rpg-app
    restart: unless-stopped
    env_file:
      - .env
    environment:
      PORT: "3000"
      NODE_ENV: production
    volumes:
      # SQLite、SEC 快取、AI 設定（設定頁寫入）
      - investor-data:/app/docker-data
      # 設定頁會更新 /app/.env；掛回主機以免重建容器後遺失
      - ./.env:/app/.env
      # 線型教材 MD（專案上一層 content/；沒有此目錄可刪除此行）
      - ../content:/content:ro
    expose:
      - "3000"
    healthcheck:
      test:
        [
          "CMD",
          "node",
          "-e",
          "fetch('http://127.0.0.1:3000/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))",
        ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 45s

  nginx:
    image: nginx:1.27-alpine
    container_name: investor-rpg-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      app:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 10s

volumes:
  investor-data:
