File size: 1,467 Bytes
6b27270
 
 
 
 
a4538e5
 
6b27270
a4538e5
 
 
 
 
 
 
 
 
 
6b27270
 
a4538e5
 
6b27270
a4538e5
6b27270
 
 
a4538e5
6b27270
a4538e5
 
 
 
 
6b27270
 
a4538e5
6b27270
 
 
a4538e5
6b27270
a4538e5
6b27270
 
a4538e5
6b27270
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
# Hugging Face Spaces - Docker SDK
# Docs: https://huggingface.co/docs/hub/spaces-sdks-docker

# ── Build stage ──────────────────────────────────────────────
FROM python:3.11-slim AS builder

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

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

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# ── Production stage ─────────────────────────────────────────
FROM python:3.11-slim AS production

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

# HF Spaces requires a user with UID 1000
RUN useradd -m -u 1000 user
ENV PATH="/home/user/.local/bin:$PATH"

# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
COPY --from=builder /usr/local/bin/ /usr/local/bin/

WORKDIR /app

# Copy application code (owned by user)
COPY --chown=user . /app

# Ensure necessary directories exist
RUN mkdir -p /app/faiss_store /app/Data && \
    chown -R user:user /app

USER user

# HF Spaces requires port 7860
EXPOSE 7860

CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]