# ============================================
# 玩玩云 Docker Compose 配置
# ============================================
# 使用方法:
#   1. 复制 backend/.env.example 为 backend/.env 并修改配置
#   2. 运行: docker-compose up -d
#   3. 访问: http://localhost (或配置的域名)
# ============================================

version: '3.8'

services:
  # ============================================
  # 后端服务
  # ============================================
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: wanwanyun-backend
    restart: unless-stopped
    environment:
      - NODE_ENV=production
      - PORT=40001
      # 以下配置建议通过 .env 文件或环境变量设置
      # - JWT_SECRET=your-secret-key
      # - ADMIN_USERNAME=admin
      # - ADMIN_PASSWORD=admin123
    env_file:
      - ./backend/.env
    volumes:
      # 数据持久化
      - ./backend/data:/app/data
      - ./backend/storage:/app/storage
    networks:
      - wanwanyun-network
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://localhost:40001/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  # ============================================
  # Nginx 前端服务
  # ============================================
  nginx:
    image: nginx:alpine
    container_name: wanwanyun-nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      # 前端静态文件
      - ./frontend:/usr/share/nginx/html:ro
      # Nginx 配置
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
      # SSL 证书（如有）
      - ./nginx/ssl:/etc/nginx/ssl:ro
      # Let's Encrypt 证书目录（可选）
      # - /etc/letsencrypt:/etc/letsencrypt:ro
      # - ./certbot/www:/var/www/certbot:ro
    depends_on:
      - backend
    networks:
      - wanwanyun-network
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://localhost/"]
      interval: 30s
      timeout: 10s
      retries: 3

networks:
  wanwanyun-network:
    driver: bridge

# ============================================
# 可选: 数据卷（用于更持久的数据存储）
# ============================================
# volumes:
#   wanwanyun-data:
#   wanwanyun-storage:
