File size: 1,213 Bytes
67c8aca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76eb481
67c8aca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Stage 1: Build React Frontend
FROM node:20-alpine AS build
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend .
RUN npm run build

# Stage 2: Serve with FastAPI (Hugging Face setup)
FROM python:3.11-slim

# Create a non-root user matching Hugging Face defaults (1000)
RUN useradd -m -u 1000 user
WORKDIR /app

# System dependencies for scientific packages
RUN apt-get update && apt-get install -y gcc g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy project metadata and backend source for package installation
COPY pyproject.toml README.md ./
COPY backend ./backend/
RUN pip install --no-cache-dir .

# Create necessary directories and set ownership
RUN mkdir -p /app/backend /data /app/frontend
RUN chown -R user:user /app /data

# Switch to the non-root user
USER user

# Copy pre-built frontend from stage 1
COPY --from=build --chown=user:user /app/frontend/dist /app/frontend/dist

# Copy legacy data for ML Engine
COPY --chown=user:user data ./data/

# Copy backend source
COPY --chown=user:user backend ./backend/

# Hugging Face deployment assumes we serve on 7860
EXPOSE 7860

# FastAPI startup
CMD ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "7860"]