Spaces:
Running
Running
fix error cache miss
Browse files- Dockerfile +59 -56
Dockerfile
CHANGED
|
@@ -1,56 +1,59 @@
|
|
| 1 |
-
# Use lighter Python image optimized for production
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
LABEL maintainer="Yuwarath Suktrakool <yuwarasu@scg.com>"
|
| 5 |
-
|
| 6 |
-
# Set environment variables for optimization and configuration paths
|
| 7 |
-
ENV PYTHONUNBUFFERED=1 \
|
| 8 |
-
PYTHONDONTWRITEBYTECODE=1 \
|
| 9 |
-
PIP_NO_CACHE_DIR=1 \
|
| 10 |
-
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 11 |
-
OMP_NUM_THREADS=1 \
|
| 12 |
-
MKL_NUM_THREADS=1 \
|
| 13 |
-
TORCH_NUM_THREADS=1 \
|
| 14 |
-
MPLCONFIGDIR=/home/appuser/.config/matplotlib \
|
| 15 |
-
YOLO_CONFIG_DIR=/home/appuser/.config/Ultralytics
|
| 16 |
-
|
| 17 |
-
# Create non-root user
|
| 18 |
-
RUN useradd -m appuser && \
|
| 19 |
-
mkdir -p /app
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
#
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use lighter Python image optimized for production
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
LABEL maintainer="Yuwarath Suktrakool <yuwarasu@scg.com>"
|
| 5 |
+
|
| 6 |
+
# Set environment variables for optimization and configuration paths
|
| 7 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 8 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 9 |
+
PIP_NO_CACHE_DIR=1 \
|
| 10 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 11 |
+
OMP_NUM_THREADS=1 \
|
| 12 |
+
MKL_NUM_THREADS=1 \
|
| 13 |
+
TORCH_NUM_THREADS=1 \
|
| 14 |
+
MPLCONFIGDIR=/home/appuser/.config/matplotlib \
|
| 15 |
+
YOLO_CONFIG_DIR=/home/appuser/.config/Ultralytics
|
| 16 |
+
|
| 17 |
+
# Create non-root user, /app directory, and config directories all at once
|
| 18 |
+
RUN useradd -m appuser && \
|
| 19 |
+
mkdir -p /app /home/appuser/.config/matplotlib \
|
| 20 |
+
/home/appuser/.config/Ultralytics \
|
| 21 |
+
/home/appuser/.local && \
|
| 22 |
+
chown -R appuser:appuser /app /home/appuser
|
| 23 |
+
|
| 24 |
+
# Set the working directory
|
| 25 |
+
WORKDIR /app
|
| 26 |
+
|
| 27 |
+
# Install system dependencies (as root)
|
| 28 |
+
RUN apt-get update && \
|
| 29 |
+
apt-get install -y --no-install-recommends \
|
| 30 |
+
ffmpeg libsm6 libxext6 git \
|
| 31 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 32 |
+
|
| 33 |
+
# Copy requirements first and set ownership to leverage Docker cache
|
| 34 |
+
COPY --chown=appuser:appuser requirements.txt .
|
| 35 |
+
|
| 36 |
+
# Install Python dependencies (as root)
|
| 37 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 38 |
+
|
| 39 |
+
# --- Switch to appuser to create files ---
|
| 40 |
+
# By running git clone as 'appuser', the files will already have the correct owner
|
| 41 |
+
USER appuser
|
| 42 |
+
|
| 43 |
+
# Clone YOLOv5 as appuser and remove .git to reduce size
|
| 44 |
+
RUN git clone --depth 1 https://github.com/ultralytics/yolov5.git && \
|
| 45 |
+
rm -rf yolov5/.git
|
| 46 |
+
|
| 47 |
+
# --- Switch back to root to copy remaining files ---
|
| 48 |
+
# This is necessary because the build context files (from your computer) are owned by root
|
| 49 |
+
USER root
|
| 50 |
+
|
| 51 |
+
# Copy application code and set ownership
|
| 52 |
+
# This REPLACES your old 'COPY . .' and the failing 'RUN chown...'
|
| 53 |
+
COPY --chown=appuser:appuser . .
|
| 54 |
+
|
| 55 |
+
# Switch to non-root user for runtime
|
| 56 |
+
USER appuser
|
| 57 |
+
|
| 58 |
+
# Run with workers optimized for CPU
|
| 59 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|