File size: 1,159 Bytes
97a7477
80d2215
3b807c3
97a7477
 
 
 
 
 
 
 
 
 
 
 
3b807c3
97a7477
5e14f46
97a7477
 
4571d26
97a7477
 
 
3b807c3
97a7477
 
 
 
5e14f46
97a7477
 
3b807c3
97a7477
 
3b807c3
97a7477
 
 
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
# Use a slim Python base image
FROM python:3.9-slim

# Install system build deps (adjust if you know you don't need them)
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        build-essential \
        gcc \
        libgomp1 \
        git && \
    rm -rf /var/lib/apt/lists/*

# Prevent Python from writing .pyc files and enable unbuffered logging
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1

WORKDIR /app

# Copy only requirements first to leverage Docker cache
COPY requirements.txt /app/requirements.txt

# Install Python packages globally (as root)
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /app/requirements.txt

# Create a non-root user and switch to it
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Copy application code as the non-root user
COPY --chown=user:root . /app

# Expose the port expected by Hugging Face Spaces (7860)
EXPOSE 7860

# Run uvicorn pointing at your FastAPI app.
# Note: your FastAPI app instance is `app` in `backend.py`, so we use `backend:app`.
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]