PrashanthB461 commited on
Commit
83a84c9
·
verified ·
1 Parent(s): 18ea0ae

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +76 -59
entrypoint.sh CHANGED
@@ -1,59 +1,76 @@
1
- #!/bin/sh
2
- echo "===== Entrypoint: Starting at $(date) ====="
3
- echo "Entrypoint: Current user: $(id)"
4
- echo "Entrypoint: Verifying directories exist"
5
- mkdir -p /app /model /tmp/Ultralytics /snapshots || { echo "Error: Failed to create directories"; exit 1; }
6
- chown appuser:appuser /app /model /tmp/Ultralytics /snapshots || { echo "Error: Failed to chown directories"; exit 1; }
7
- chmod 777 /app /model /tmp/Ultralytics /snapshots || { echo "Error: Failed to chmod directories"; exit 1; }
8
- echo "Entrypoint: Directory permissions:"
9
- ls -ld /app /model /tmp/Ultralytics /snapshots
10
-
11
- echo "Entrypoint: Copying yolov8n.pt to /app"
12
- if [ -f /model/yolov8n.pt ]; then
13
- cp /model/yolov8n.pt /app/yolov8n.pt || { echo "Error: Failed to copy yolov8n.pt"; exit 1; }
14
- chown appuser:appuser /app/yolov8n.pt
15
- chmod 644 /app/yolov8n.pt
16
- else
17
- echo "Error: /model/yolov8n.pt not found. Build may have failed."
18
- exit 1
19
- fi
20
-
21
- echo "Entrypoint: Copying app.py to /app (in case Hugging Face mount overwrites it)"
22
- if [ -f /source/app.py ]; then
23
- cp /source/app.py /app/app.py || { echo "Error: Failed to copy app.py"; exit 1; }
24
- chown appuser:appuser /app/app.py
25
- chmod 644 /app/app.py
26
- else
27
- echo "Error: /source/app.py not found. Build may have failed."
28
- exit 1
29
- fi
30
-
31
- echo "Entrypoint: Setting working directory to /app"
32
- cd /app || { echo "Error: Failed to change directory to /app"; exit 1; }
33
-
34
- echo "Entrypoint: Current working directory: $(pwd)"
35
- echo "Entrypoint: Contents of /app:"
36
- ls -l /app || echo "Error: Failed to list /app contents"
37
-
38
- echo "Entrypoint: Verifying yolov8n.pt exists in /app"
39
- if [ ! -f /app/yolov8n.pt ]; then
40
- echo "Error: yolov8n.pt not found in /app after copy. Directory contents:"
41
- ls -l /app
42
- exit 1
43
- fi
44
-
45
- echo "Entrypoint: Verifying app.py exists in /app"
46
- if [ ! -f /app/app.py ]; then
47
- echo "Error: app.py not found in /app after copy. Directory contents:"
48
- ls -l /app
49
- exit 1
50
- fi
51
-
52
- echo "Entrypoint: Contents of /home/user/app (Hugging Face mount point):"
53
- ls -l /home/user/app || echo "Directory /home/user/app does not exist"
54
-
55
- echo "Entrypoint: Contents of /source (persistent storage):"
56
- ls -l /source || echo "Directory /source does not exist"
57
-
58
- echo "Entrypoint: Launching application"
59
- exec python /app/app.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.10-slim as base image
2
+ FROM python:3.10-slim
3
+
4
+ # Install system dependencies for OpenCV, FFmpeg, and debugging
5
+ RUN apt-get update && apt-get install -y \
6
+ libgl1-mesa-glx \
7
+ libglib2.0-0 \
8
+ ffmpeg \
9
+ curl \
10
+ wget \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Create a non-root user and set up directories with proper permissions
14
+ RUN useradd -m -u 1000 appuser && \
15
+ mkdir -p /tmp/Ultralytics /snapshots /app /model /source && \
16
+ chown -R appuser:appuser /tmp/Ultralytics /snapshots /app /model /source && \
17
+ chmod -R 777 /tmp/Ultralytics /snapshots /app /model /source && \
18
+ ls -ld /app/ && \
19
+ ls -ld /model/ && \
20
+ ls -ld /source/
21
+
22
+ # Remove appuser's home directory to prevent interference
23
+ RUN rm -rf /home/appuser && \
24
+ ln -s /app /home/appuser
25
+
26
+ # Set environment variables early
27
+ ENV YOLO_CONFIG_DIR=/tmp/Ultralytics
28
+ ENV PYTHONUNBUFFERED=1
29
+ ENV PYTHONPATH=/app
30
+
31
+ # Set working directory
32
+ WORKDIR /app
33
+
34
+ # Verify working directory exists
35
+ RUN ls -ld /app/ || (echo "Error: /app/ directory not found after WORKDIR" && exit 1)
36
+
37
+ # Download YOLOv8n model weights to /model/ and copy to /source/
38
+ RUN wget https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt -O /model/yolov8n.pt && \
39
+ test -f /model/yolov8n.pt || (echo "Error: Failed to download yolov8n.pt." && exit 1) && \
40
+ cp /model/yolov8n.pt /source/yolov8n.pt && \
41
+ chmod 644 /model/yolov8n.pt /source/yolov8n.pt && \
42
+ chown appuser:appuser /model/yolov8n.pt /source/yolov8n.pt && \
43
+ ls -l /model/yolov8n.pt && \
44
+ ls -l /source/yolov8n.pt
45
+
46
+ # Install Python dependencies
47
+ COPY requirements.txt .
48
+ RUN pip install --no-cache-dir -r requirements.txt
49
+
50
+ # Copy application code to /source/ for persistence
51
+ COPY app.py /source/app.py
52
+ RUN chmod 644 /source/app.py && \
53
+ chown appuser:appuser /source/app.py
54
+
55
+ # Copy application code to /app/ (may be overwritten by Hugging Face mount)
56
+ COPY . .
57
+
58
+ # Verify /app/ contents before switching user
59
+ RUN ls -ld /app/ || (echo "Error: /app/ directory missing before switching user" && exit 1) && \
60
+ ls -l /app/ || (echo "Error: Failed to list contents of /app/" && exit 1)
61
+
62
+ # Switch to non-root user
63
+ USER appuser
64
+
65
+ # Verify /app/ exists and is accessible by appuser
66
+ RUN ls -ld /app/ || (echo "Error: /app/ directory missing for appuser" && exit 1) && \
67
+ ls -l /app/ || (echo "Error: Failed to list contents of /app/ as appuser" && exit 1)
68
+
69
+ # Copy and set up entrypoint
70
+ COPY entrypoint.sh /entrypoint.sh
71
+ RUN chmod +x /entrypoint.sh
72
+
73
+ # Use entrypoint to ensure working directory and run the app
74
+ # Also set CMD as a fallback in case ENTRYPOINT is overridden
75
+ ENTRYPOINT ["/entrypoint.sh"]
76
+ CMD ["/entrypoint.sh"]