File size: 1,625 Bytes
91299cb 35454f8 91299cb 35454f8 91299cb 35454f8 91299cb 35454f8 91299cb 35454f8 91299cb 1b7e113 91299cb 35454f8 91299cb 35454f8 4540421 35454f8 4540421 35454f8 91299cb 4540421 35454f8 91299cb 35454f8 91299cb 18e5c97 91299cb 18e5c97 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# ----------------------------
# STAGE 1: Build React frontend
# ----------------------------
FROM node:20-alpine AS frontend-builder
WORKDIR /build
# Copy package.json first for dependency installation
COPY frontend/package*.json ./
RUN npm ci # Install devDependencies for build
# Copy rest of frontend source code
COPY frontend/ ./
# Copy .env if exists
COPY frontend/.env* ./
# Build React app
RUN npm run build
# Clean up node_modules to reduce image size
RUN rm -rf node_modules
# ----------------------------
# STAGE 2: Build FastAPI backend + embed frontend
# ----------------------------
FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential gcc && \
rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY backend/requirements.txt ./
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy backend source code
COPY backend/ ./
# Copy React build output into ./static for FastAPI
# FIX: The Vite/React build outputs to /build/build/client
COPY --from=frontend-builder /build/build/client ./static
# ----------------------------
# HF Spaces ENV
# ----------------------------
ENV PORT=7860
ENV HOST=0.0.0.0
ENV DEBUG=False
EXPOSE 7860
# ----------------------------
# Make startup script executable and set it as entrypoint
# ----------------------------
COPY backend/start.sh /app/start.sh
RUN chmod +x /app/start.sh
# ----------------------------
# Start FastAPI (runs migrations first)
# ----------------------------
CMD ["/app/start.sh"]
|