Spaces:
Sleeping
Sleeping
# Root-level Dockerfile | |
# Stage 1: Build React frontend | |
FROM node:18-alpine AS frontend-build | |
WORKDIR /app/frontend | |
COPY frontend/package.json frontend/package-lock.json ./ | |
RUN npm install | |
COPY frontend/ ./ | |
RUN npm run build | |
# Stage 2: Build Python backend + serve frontend with Nginx | |
FROM python:3.9-slim | |
WORKDIR /app | |
# Install Python dependencies | |
COPY backend/requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
# Copy backend code | |
COPY backend/ /app/backend | |
# Copy built frontend from previous stage | |
COPY --from=frontend-build /app/frontend/build /app/frontend_build | |
# Install nginx | |
RUN apt-get update && apt-get install -y nginx && rm -rf /var/lib/apt/lists/* | |
# Copy nginx config | |
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf | |
# Link built frontend to nginx root | |
RUN rm -rf /usr/share/nginx/html && \ | |
ln -s /app/frontend_build /usr/share/nginx/html | |
# Copy script to run both frontend and backend | |
COPY start.sh /start.sh | |
RUN chmod +x /start.sh | |
# Expose Hugging Face compatible port | |
EXPOSE 7860 | |
CMD ["/start.sh"] | |