File size: 921 Bytes
8811f65
 
 
 
 
 
 
 
 
fd1d3cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8811f65
fd1d3cf
 
8811f65
 
 
fd1d3cf
 
 
8811f65
 
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
# Stage 1: Build the Next.js frontend
FROM node:20-alpine AS frontend_builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build

# Stage 2: Build the FastAPI backend
FROM python:3.10-slim
WORKDIR /app

# Create a non-root user (Hugging Face standard)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Copy requirements and install
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy backend files
COPY --chown=user . .

# Copy the built frontend static files from Stage 1 into the Python container
COPY --chown=user --from=frontend_builder /app/frontend/out ./frontend/out

# Hugging Face Spaces standard port
EXPOSE 7860

# Command to run the application (FastAPI on 0.0.0.0:7860)
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]