PrashanthB461 commited on
Commit
39f8025
·
verified ·
1 Parent(s): 83a84c9

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +62 -76
entrypoint.sh CHANGED
@@ -1,76 +1,62 @@
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"]
 
1
+ #!/bin/sh
2
+ echo "===== Entrypoint: Starting at $(date) ====="
3
+ echo "Entrypoint: Current user: $(id)"
4
+ echo "Entrypoint: Environment variables:"
5
+ env
6
+
7
+ echo "Entrypoint: Verifying directories exist"
8
+ mkdir -p /app /model /tmp/Ultralytics /snapshots || { echo "Error: Failed to create directories"; exit 1; }
9
+ chown appuser:appuser /app /model /tmp/Ultralytics /snapshots || { echo "Error: Failed to chown directories"; exit 1; }
10
+ chmod 777 /app /model /tmp/Ultralytics /snapshots || { echo "Error: Failed to chmod directories"; exit 1; }
11
+ echo "Entrypoint: Directory permissions:"
12
+ ls -ld /app /model /tmp/Ultralytics /snapshots
13
+
14
+ echo "Entrypoint: Copying yolov8n.pt to /app"
15
+ if [ -f /model/yolov8n.pt ]; then
16
+ cp /model/yolov8n.pt /app/yolov8n.pt || { echo "Error: Failed to copy yolov8n.pt"; exit 1; }
17
+ chown appuser:appuser /app/yolov8n.pt
18
+ chmod 644 /app/yolov8n.pt
19
+ else
20
+ echo "Error: /model/yolov8n.pt not found. Build may have failed."
21
+ exit 1
22
+ fi
23
+
24
+ echo "Entrypoint: Copying app.py to /app (in case Hugging Face mount overwrites it)"
25
+ if [ -f /source/app.py ]; then
26
+ cp /source/app.py /app/app.py || { echo "Error: Failed to copy app.py"; exit 1; }
27
+ chown appuser:appuser /app/app.py
28
+ chmod 644 /app/app.py
29
+ else
30
+ echo "Error: /source/app.py not found. Build may have failed."
31
+ exit 1
32
+ fi
33
+
34
+ echo "Entrypoint: Setting working directory to /app"
35
+ cd /app || { echo "Error: Failed to change directory to /app"; exit 1; }
36
+
37
+ echo "Entrypoint: Current working directory: $(pwd)"
38
+ echo "Entrypoint: Contents of /app:"
39
+ ls -l /app || echo "Error: Failed to list /app contents"
40
+
41
+ echo "Entrypoint: Verifying yolov8n.pt exists in /app"
42
+ if [ ! -f /app/yolov8n.pt ]; then
43
+ echo "Error: yolov8n.pt not found in /app after copy. Directory contents:"
44
+ ls -l /app
45
+ exit 1
46
+ fi
47
+
48
+ echo "Entrypoint: Verifying app.py exists in /app"
49
+ if [ ! -f /app/app.py ]; then
50
+ echo "Error: app.py not found in /app after copy. Directory contents:"
51
+ ls -l /app
52
+ exit 1
53
+ fi
54
+
55
+ echo "Entrypoint: Contents of /home/user/app (Hugging Face mount point):"
56
+ ls -l /home/user/app || echo "Directory /home/user/app does not exist"
57
+
58
+ echo "Entrypoint: Contents of /source (persistent storage):"
59
+ ls -l /source || echo "Directory /source does not exist"
60
+
61
+ echo "Entrypoint: Launching application"
62
+ exec python /app/app.py