services:
  blog:
    build: .
    container_name: personal-blog
    ports:
      - "3000:3000"
    volumes:
      # SQLite 数据库文件持久化
      - blog-db:/app/data
      # 上传的封面图持久化
      - blog-uploads:/app/public/uploads
      # 备份文件持久化
      - blog-backups:/app/data/backups
      # 可选: 挂载自定义 .env 文件
      - ./.env:/app/.env:ro
    environment:
      - NODE_ENV=production
      - JWT_SECRET=${JWT_SECRET:-please-change-me-in-production-32-chars-min}
      - ADMIN_EMAIL=${ADMIN_EMAIL:-admin@blog.com}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123456}
      - DATABASE_URL=/app/data/blog.db
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "--spider", "-q", "http://localhost:3000/"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 30s

volumes:
  blog-db:
  blog-uploads:
  blog-backups:
