Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +30 -10
Dockerfile
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a slim Python base image
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
+
# Install system build deps (adjust if you know you don't need them)
|
| 5 |
+
RUN apt-get update && \
|
| 6 |
+
apt-get install -y --no-install-recommends \
|
| 7 |
+
build-essential \
|
| 8 |
+
gcc \
|
| 9 |
+
libgomp1 \
|
| 10 |
+
git && \
|
| 11 |
+
rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Prevent Python from writing .pyc files and enable unbuffered logging
|
| 14 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 15 |
+
PYTHONUNBUFFERED=1
|
| 16 |
|
| 17 |
+
WORKDIR /app
|
| 18 |
|
| 19 |
+
# Copy only requirements first to leverage Docker cache
|
| 20 |
+
COPY requirements.txt /app/requirements.txt
|
| 21 |
|
| 22 |
+
# Install Python packages globally (as root)
|
| 23 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 24 |
+
pip install --no-cache-dir -r /app/requirements.txt
|
| 25 |
|
| 26 |
+
# Create a non-root user and switch to it
|
| 27 |
+
RUN useradd -m -u 1000 user
|
| 28 |
+
USER user
|
| 29 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 30 |
|
| 31 |
+
# Copy application code as the non-root user
|
| 32 |
+
COPY --chown=user:root . /app
|
| 33 |
|
| 34 |
+
# Expose the port expected by Hugging Face Spaces (7860)
|
| 35 |
+
EXPOSE 7860
|
| 36 |
|
| 37 |
+
# Run uvicorn pointing at your FastAPI app.
|
| 38 |
+
# Note: your FastAPI app instance is `app` in `backend.py`, so we use `backend:app`.
|
| 39 |
+
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
|