Esmaill1 commited on
Commit
a4bb474
·
1 Parent(s): 4ea7d45

Refactor Dockerfile for improved user setup and dependency installation

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -20
Dockerfile CHANGED
@@ -1,38 +1,30 @@
1
  FROM python:3.9-slim
2
 
3
- # Install system dependencies for OpenCV
4
  RUN apt-get update && apt-get install -y \
5
  libgl1 \
6
  libglib2.0-0 \
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
- # Set up a new user named "user" with user ID 1000
10
  RUN useradd -m -u 1000 user
 
 
11
 
12
- # Switch to user
13
  USER user
14
  ENV PATH="/home/user/.local/bin:$PATH"
15
 
16
- # Set working directory (this will be owned by root if we don't be careful, but user can write to their home)
17
- # Better practice: create the dir as root, chown it, then switch user.
18
- # But standard pattern: just work in home or ensure pre-creation.
19
- # Let's simplify: Work in /app but ensure we have permissions.
20
- USER root
21
- RUN mkdir /app && chown user:user /app
22
- USER user
23
-
24
- WORKDIR /app
25
-
26
- # Copy requirements and install
27
- COPY --chown=user requirements.txt requirements.txt
28
  RUN pip install --no-cache-dir --upgrade pip && \
29
  pip install --no-cache-dir --user -r requirements.txt
30
 
31
- # Copy application code
32
- COPY --chown=user app.py app.py
 
 
 
33
 
34
- # Expose the Hugging Face Spaces port
35
  EXPOSE 7860
36
 
37
- # Run the application
38
- CMD ["python", "app.py"]
 
1
  FROM python:3.9-slim
2
 
3
+ # 1. Install system dependencies for OpenCV
4
  RUN apt-get update && apt-get install -y \
5
  libgl1 \
6
  libglib2.0-0 \
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
+ # 2. Set up a non-root user for Hugging Face Spaces
10
  RUN useradd -m -u 1000 user
11
+ WORKDIR /app
12
+ RUN chown user:user /app
13
 
 
14
  USER user
15
  ENV PATH="/home/user/.local/bin:$PATH"
16
 
17
+ # 3. Install Python dependencies
18
+ COPY --chown=user requirements.txt .
 
 
 
 
 
 
 
 
 
 
19
  RUN pip install --no-cache-dir --upgrade pip && \
20
  pip install --no-cache-dir --user -r requirements.txt
21
 
22
+ # 4. PRE-DOWNLOAD THE MODEL (This prevents the "stuck" build/startup)
23
+ RUN python -c "from ultralytics import YOLO; YOLO('yolov8n-pose.pt')"
24
+
25
+ # 5. Copy the app code
26
+ COPY --chown=user app.py .
27
 
 
28
  EXPOSE 7860
29
 
30
+ CMD ["python", "app.py"]