Dockerfile 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. # Set timezone to Asia/Shanghai
  12. ENV TZ=Asia/Shanghai
  13. RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  14. # Install system dependencies
  15. RUN apt-get update && apt-get install -y --no-install-recommends \
  16. libpq-dev \
  17. && rm -rf /var/lib/apt/lists/*
  18. # Install Python dependencies
  19. COPY backend/requirements.txt ./
  20. RUN pip install --no-cache-dir -r requirements.txt
  21. # Copy backend code
  22. COPY backend/ ./
  23. # Copy frontend build
  24. COPY --from=frontend-builder /app/frontend/dist ./static
  25. # Environment variables
  26. ENV FLASK_CONFIG=production
  27. ENV PYTHONUNBUFFERED=1
  28. # Expose port
  29. EXPOSE 5000
  30. # Run with gunicorn (production)
  31. CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "wsgi:app"]
  32. # Alternative: Flask dev server (not recommended for production)
  33. # CMD ["python", "run.py"]