File size: 1,197 Bytes
9998702
 
 
 
 
 
 
 
 
 
fd6ef00
 
 
 
 
 
 
 
 
 
 
 
 
 
9998702
fd6ef00
 
9998702
 
 
 
653865f
 
 
 
 
 
 
 
 
fd6ef00
 
 
653865f
 
fd6ef00
d2570c2
fd6ef00
 
d2570c2
 
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
# --- Stage 1: Build Frontend ---
FROM node:18-alpine as frontend-builder

WORKDIR /app/web
COPY web/package*.json ./
RUN npm ci
COPY web/ .
RUN npm run build

# --- Stage 2: Final Backend Image ---
FROM python:3.10-slim

WORKDIR /app

# Install build dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements and install
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install "uvicorn[standard]"

# Copy backend code
COPY . .

# Copy built frontend assets from Stage 1
# We allow the copy to fail if web dir isn't perfect, but here we expect success
COPY --from=frontend-builder /app/web/dist /app/web/dist

# Create a non-root user (Standard for HF Spaces)
RUN useradd -m -u 1000 user

# Create data directory and set permissions
RUN mkdir -p /app/data && chown -R user:user /app

# Switch to non-root user
USER user

# Environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH=/app
ENV HOME=/home/user
ENV PATH=$HOME/.local/bin:$PATH

# Expose port for API
EXPOSE 8000

# Default command: Run FastAPI backend
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]