File size: 1,027 Bytes
9e4bb05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b8e6434
9e4bb05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d4c0b3e
9e4bb05
1d5f736
9e4bb05
1d5f736
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
# Multi-stage build for efficiency
FROM python:3.11-slim as builder

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

WORKDIR /tmp
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt

# Final stage
FROM python:3.11-slim

# Create app user (required for HF Spaces security)
RUN useradd -m -u 1000 user

WORKDIR /app

# Copy Python packages from builder
COPY --from=builder /root/.local /home/user/.local

# Copy application code
COPY --chown=user:user . /app/

# Set environment
ENV PATH=/home/user/.local/bin:$PATH \
    PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1

# Switch to non-root user
USER user

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/').read()" || exit 1

EXPOSE 7860

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