Update Dockerfile
Browse files- Dockerfile +31 -11
Dockerfile
CHANGED
|
@@ -1,19 +1,39 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
# Copy the
|
| 13 |
-
COPY .
|
| 14 |
|
| 15 |
-
# Expose the port expected by Hugging Face Spaces
|
| 16 |
EXPOSE 7860
|
| 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 the FastAPI app defined in `main.py` (module:main, variable:app)
|
| 38 |
+
# Use a reasonable timeout for long uploads and keep 1 worker (models are heavy)
|
| 39 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--timeout-keep-alive", "120"]
|