Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +14 -6
Dockerfile
CHANGED
|
@@ -2,44 +2,52 @@
|
|
| 2 |
FROM python:3.10-slim AS builder
|
| 3 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 4 |
|
|
|
|
| 5 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 6 |
build-essential cmake git curl \
|
| 7 |
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
|
| 9 |
WORKDIR /app
|
|
|
|
|
|
|
| 10 |
COPY requirements.txt .
|
| 11 |
RUN python -m venv /opt/venv && \
|
| 12 |
/opt/venv/bin/pip install --upgrade pip && \
|
| 13 |
/opt/venv/bin/pip install --no-cache-dir -r requirements.txt
|
| 14 |
|
| 15 |
-
# ✅ Pre-download YOLOv8n weights to Ultralytics
|
| 16 |
RUN mkdir -p /root/.cache/torch/hub/checkpoints && \
|
| 17 |
curl -L -o /root/.cache/torch/hub/checkpoints/yolov8n.pt \
|
| 18 |
https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov8n.pt
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Stage 2 - Final Image
|
| 21 |
FROM python:3.10-slim
|
| 22 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 23 |
ENV PATH="/opt/venv/bin:$PATH"
|
| 24 |
|
| 25 |
-
# ✅
|
| 26 |
ENV EASYOCR_MODULE_PATH=/app/.EasyOCR
|
| 27 |
ENV EASYOCR_CACHE_DIR=/app/.EasyOCR
|
| 28 |
-
|
| 29 |
-
# ✅ Force YOLO to use its cache folder, not cwd
|
| 30 |
ENV YOLO_CONFIG_DIR=/app/.yolo
|
| 31 |
|
|
|
|
| 32 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 33 |
libgl1 libglib2.0-0 \
|
| 34 |
&& rm -rf /var/lib/apt/lists/*
|
| 35 |
|
|
|
|
| 36 |
COPY --from=builder /opt/venv /opt/venv
|
| 37 |
COPY --from=builder /root/.cache /root/.cache
|
|
|
|
| 38 |
|
| 39 |
WORKDIR /app
|
| 40 |
|
| 41 |
-
# ✅ Create
|
| 42 |
-
RUN mkdir -p /app/.
|
| 43 |
chmod -R 777 /app && \
|
| 44 |
chmod -R 777 /root/.cache
|
| 45 |
|
|
|
|
| 2 |
FROM python:3.10-slim AS builder
|
| 3 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 4 |
|
| 5 |
+
# Install build dependencies
|
| 6 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
build-essential cmake git curl \
|
| 8 |
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
|
| 10 |
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
# Install Python dependencies in a venv
|
| 13 |
COPY requirements.txt .
|
| 14 |
RUN python -m venv /opt/venv && \
|
| 15 |
/opt/venv/bin/pip install --upgrade pip && \
|
| 16 |
/opt/venv/bin/pip install --no-cache-dir -r requirements.txt
|
| 17 |
|
| 18 |
+
# ✅ Pre-download YOLOv8n weights to Ultralytics cache
|
| 19 |
RUN mkdir -p /root/.cache/torch/hub/checkpoints && \
|
| 20 |
curl -L -o /root/.cache/torch/hub/checkpoints/yolov8n.pt \
|
| 21 |
https://github.com/ultralytics/assets/releases/download/v8.3.0/yolov8n.pt
|
| 22 |
|
| 23 |
+
# ✅ Pre-download EasyOCR model files
|
| 24 |
+
RUN mkdir -p /app/.EasyOCR && \
|
| 25 |
+
/opt/venv/bin/python -c "import easyocr; easyocr.Reader(['en'], model_storage_directory='/app/.EasyOCR')"
|
| 26 |
+
|
| 27 |
# Stage 2 - Final Image
|
| 28 |
FROM python:3.10-slim
|
| 29 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 30 |
ENV PATH="/opt/venv/bin:$PATH"
|
| 31 |
|
| 32 |
+
# ✅ Force writable cache dirs
|
| 33 |
ENV EASYOCR_MODULE_PATH=/app/.EasyOCR
|
| 34 |
ENV EASYOCR_CACHE_DIR=/app/.EasyOCR
|
|
|
|
|
|
|
| 35 |
ENV YOLO_CONFIG_DIR=/app/.yolo
|
| 36 |
|
| 37 |
+
# Runtime deps (OpenCV etc.)
|
| 38 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 39 |
libgl1 libglib2.0-0 \
|
| 40 |
&& rm -rf /var/lib/apt/lists/*
|
| 41 |
|
| 42 |
+
# Copy Python env + caches from builder
|
| 43 |
COPY --from=builder /opt/venv /opt/venv
|
| 44 |
COPY --from=builder /root/.cache /root/.cache
|
| 45 |
+
COPY --from=builder /app/.EasyOCR /app/.EasyOCR
|
| 46 |
|
| 47 |
WORKDIR /app
|
| 48 |
|
| 49 |
+
# ✅ Create cache dirs & fix permissions
|
| 50 |
+
RUN mkdir -p /app/.yolo && \
|
| 51 |
chmod -R 777 /app && \
|
| 52 |
chmod -R 777 /root/.cache
|
| 53 |
|