bankba commited on
Commit
dd117cd
·
verified ·
1 Parent(s): e07dafb

fix error cache miss

Browse files
Files changed (1) hide show
  1. 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
- chown appuser:appuser /app
21
-
22
- # Set the working directory
23
- WORKDIR /app
24
-
25
- # Create and set permissions for config directories
26
- RUN mkdir -p /home/appuser/.config/matplotlib && \
27
- mkdir -p /home/appuser/.config/Ultralytics && \
28
- mkdir -p /home/appuser/.local && \
29
- chown -R appuser:appuser /home/appuser
30
-
31
- # Install system dependencies
32
- RUN apt-get update && \
33
- apt-get install -y --no-install-recommends \
34
- ffmpeg libsm6 libxext6 git \
35
- && rm -rf /var/lib/apt/lists/*
36
-
37
- # Clone YOLOv5 and remove .git to reduce size
38
- RUN git clone --depth 1 https://github.com/ultralytics/yolov5.git && \
39
- rm -rf yolov5/.git
40
-
41
- # Copy requirements first to leverage Docker cache
42
- COPY requirements.txt .
43
-
44
- # Install Python dependencies
45
- RUN pip install --no-cache-dir -r requirements.txt && \
46
- chown -R appuser:appuser /app
47
-
48
- # Copy application code
49
- COPY . .
50
- RUN chown -R appuser:appuser /app
51
-
52
- # Switch to non-root user
53
- USER appuser
54
-
55
- # Run with workers optimized for CPU
56
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
 
 
 
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"]