File size: 2,157 Bytes
26a0c00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7a185b
0552469
 
 
d7a185b
 
 
 
 
 
 
 
 
26a0c00
 
d7a185b
 
26a0c00
0552469
 
26a0c00
 
 
 
0552469
 
 
26a0c00
 
 
 
d7a185b
0552469
 
 
 
 
 
26a0c00
 
d7a185b
0552469
 
26a0c00
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
58
59
60
61
62
63
64
# ════════════════════════════════════════════════════════
# Stage 1: Build Next.js Frontend
# ════════════════════════════════════════════════════════
FROM node:20-alpine AS frontend-builder

WORKDIR /app/frontend

# Install dependencies
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci --no-audit

# Copy frontend source and build
COPY frontend/ ./
RUN npm run build

# ════════════════════════════════════════════════════════
# Stage 2: Python Backend + Serve Frontend
# ════════════════════════════════════════════════════════
FROM python:3.11-slim

# HuggingFace Spaces runs as user 1000
RUN useradd -m -u 1000 appuser

WORKDIR /app

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

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

# Copy backend code
COPY backend/app ./backend/app
COPY backend/__init__.py ./backend/__init__.py

# Copy frontend build from stage 1
COPY --from=frontend-builder /app/frontend/out ./frontend/out

# Create data directories with proper permissions
RUN mkdir -p /app/data/uploads /app/data/chroma_db && \
    chown -R appuser:appuser /app

# Copy entrypoint
COPY start.sh ./start.sh
RUN chmod +x start.sh

# Switch to non-root user
USER appuser

# Pre-download models during build for faster startup
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')" 2>/dev/null || true

# HuggingFace Spaces requires port 7860
EXPOSE 7860

ENV PYTHONUNBUFFERED=1

CMD ["./start.sh"]