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