File size: 1,140 Bytes
9fbb3f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Build Stage: Frontend
FROM node:20-slim AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend/ .
RUN npm run build

# Final Stage: Backend + Static Frontend
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim

# Create a non-root user (HF Spaces requirement for some features/security)
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /app

# Install system dependencies (requires root)
USER root
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    && rm -rf /var/lib/apt/lists/*
USER user

# Copy backend dependency files
COPY --chown=user pyproject.toml uv.lock ./
# Install dependencies
RUN uv sync --frozen

# Copy the rest of the backend code
COPY --chown=user . .

# Copy built frontend from the builder stage
COPY --from=frontend-builder --chown=user /app/frontend/dist ./frontend/dist

# Expose the default HF Spaces port
EXPOSE 7860

# Set environment variables for HF
ENV HOST=0.0.0.0
ENV PORT=7860

# Run the application
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]