Dockerfile 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Stage 1: Build frontend
  2. FROM node:18-alpine AS frontend-builder
  3. WORKDIR /app/frontend
  4. COPY frontend/package*.json ./
  5. RUN npm ci
  6. COPY frontend/ ./
  7. RUN npm run build
  8. # Stage 2: Build backend
  9. FROM python:3.11-slim AS backend
  10. WORKDIR /app
  11. # Use Tsinghua mirror for apt (HTTPS)
  12. RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources \
  13. && sed -i 's/http:/https:/g' /etc/apt/sources.list.d/debian.sources
  14. # Set timezone to Asia/Shanghai
  15. ENV TZ=Asia/Shanghai
  16. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  17. # Install system dependencies
  18. RUN apt-get update && apt-get install -y --no-install-recommends \
  19. libpq-dev \
  20. && rm -rf /var/lib/apt/lists/*
  21. # Install Python dependencies
  22. COPY backend/requirements.txt ./
  23. RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir -r requirements.txt
  24. # Copy backend code
  25. COPY backend/ ./
  26. # Copy frontend build
  27. COPY --from=frontend-builder /app/frontend/dist ./static
  28. # Environment variables
  29. ENV FLASK_CONFIG=production
  30. ENV PYTHONUNBUFFERED=1
  31. # Expose port
  32. EXPOSE 5000
  33. # Run with gunicorn (production)
  34. CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "wsgi:app"]
  35. # Alternative: Flask dev server (not recommended for production)
  36. # CMD ["python", "run.py"]