Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +23 -11
Dockerfile
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
# Install system dependencies
|
|
@@ -9,25 +10,36 @@ RUN apt-get update && apt-get install -y \
|
|
| 9 |
poppler-utils \
|
| 10 |
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
RUN mkdir -p /tmp/matplotlib /tmp/ultralytics /tmp/fontconfig
|
| 19 |
# Set working directory
|
| 20 |
WORKDIR /app
|
| 21 |
|
| 22 |
# Copy project files
|
| 23 |
COPY . .
|
| 24 |
|
| 25 |
-
# Install Python dependencies
|
| 26 |
-
RUN pip install --upgrade pip
|
| 27 |
-
|
|
|
|
| 28 |
|
| 29 |
# Expose Hugging Face Spaces default port
|
| 30 |
EXPOSE 7860
|
| 31 |
|
| 32 |
-
# Run FastAPI app with Uvicorn
|
| 33 |
-
CMD ["uvicorn", "app:app", "--
|
|
|
|
| 1 |
+
# Use a minimal Python base image
|
| 2 |
FROM python:3.9-slim
|
| 3 |
|
| 4 |
# Install system dependencies
|
|
|
|
| 10 |
poppler-utils \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# Create a non-root user (Hugging Face Spaces requirement for security)
|
| 14 |
+
RUN useradd -m -u 1000 user
|
| 15 |
+
USER user
|
| 16 |
+
|
| 17 |
+
# Set environment variables to avoid permission issues and optimize performance
|
| 18 |
+
ENV HOME=/home/user \
|
| 19 |
+
MPLCONFIGDIR=/tmp/matplotlib \
|
| 20 |
+
YOLO_CONFIG_DIR=/tmp/ultralytics \
|
| 21 |
+
XDG_CACHE_HOME=/tmp \
|
| 22 |
+
FONTCONFIG_PATH=/tmp \
|
| 23 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 24 |
+
PYTHONUNBUFFERED=1 # Ensure logs are not buffered for debugging \
|
| 25 |
+
NUM_WORKERS=2 # Default number of workers (adjustable via Hugging Face settings)
|
| 26 |
+
|
| 27 |
+
# Create necessary directories
|
| 28 |
+
RUN mkdir -p /tmp/matplotlib /tmp/ultralytics /tmp/fontconfig /tmp/uploads
|
| 29 |
|
|
|
|
| 30 |
# Set working directory
|
| 31 |
WORKDIR /app
|
| 32 |
|
| 33 |
# Copy project files
|
| 34 |
COPY . .
|
| 35 |
|
| 36 |
+
# Install Python dependencies with performance optimizations
|
| 37 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 38 |
+
pip install --no-cache-dir -r requirements.txt && \
|
| 39 |
+
pip install gunicorn==21.2.0
|
| 40 |
|
| 41 |
# Expose Hugging Face Spaces default port
|
| 42 |
EXPOSE 7860
|
| 43 |
|
| 44 |
+
# Run FastAPI app with Uvicorn workers via gunicorn
|
| 45 |
+
CMD ["gunicorn", "-w", "${NUM_WORKERS}", "-k", "uvicorn.workers.UvicornWorker", "app:app", "--bind", "0.0.0.0:7860", "--log-level", "info"]
|