File size: 1,363 Bytes
4851501
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372e870
4851501
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
# ==========================================
# Stage 1: Build Frontend (Next.js)
# ==========================================
FROM node:20-alpine AS frontend
WORKDIR /app

# Install dependencies
COPY frontend/package*.json ./
RUN npm ci

# Copy source code
COPY frontend/ ./

# Configure for static export
ENV NEXT_PUBLIC_API_URL=/api/v1
# Run build (creates /app/out)
RUN npm run build

# ==========================================
# Stage 2: Runtime (Python + FastAPI)
# ==========================================
FROM python:3.11-slim

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

WORKDIR /app

# Install system dependencies (as root before switching user)
USER root
RUN apt-get update && apt-get install -y \
    build-essential \
    libgeos-dev \
    && rm -rf /var/lib/apt/lists/*
USER user

# Install Python dependencies
COPY --chown=user backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt



# Copy Backend Code
COPY --chown=user backend/ backend/

# Copy Built Frontend to Backend Static Directory
# ensure strict permissions
COPY --from=frontend --chown=user /app/out /app/backend/static

# Expose port 7860 (Standard for HF Spaces)
EXPOSE 7860

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