quantumos commited on
Commit
42970bb
·
verified ·
1 Parent(s): f29b9ae

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +38 -29
Dockerfile CHANGED
@@ -1,7 +1,12 @@
1
  # Use an official CUDA runtime as a parent image
2
- FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04
3
 
 
4
  ENV DEBIAN_FRONTEND=noninteractive
 
 
 
 
5
 
6
  # Install necessary system dependencies
7
  RUN apt-get update && apt-get install -y \
@@ -15,54 +20,58 @@ RUN apt-get update && apt-get install -y \
15
  python3-pip \
16
  python3-dev \
17
  && rm -rf /var/lib/apt/lists/*
18
-
19
  # Reset noninteractive mode
20
  ENV DEBIAN_FRONTEND=
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
 
 
 
 
 
 
 
 
23
  ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
24
  ENV MPLCONFIGDIR=/app/.cache/matplotlib
25
  ENV XDG_CACHE_HOME=/app/.cache
26
  ENV FONTCONFIG_PATH=/app/.cache/fontconfig
27
 
 
28
  RUN mkdir -p /app/.cache/huggingface/hub /app/.cache/matplotlib /app/.cache/fontconfig
29
 
 
 
30
 
31
  # Set working directory
32
- COPY . /app
33
  WORKDIR /app
34
 
35
- # Copy the requirements file
36
- #COPY requirements.txt .
37
-
38
- # Copy the wheel files for insightface and dlib
39
- #COPY insightface-0.7.3-cp310-cp310-win_amd64.whl /app/
40
- #COPY dlib-19.22.99-cp310-cp310-win_amd64.whl /app/
41
-
42
- # Install pip and upgrade it
43
- RUN pip install --upgrade pip
44
 
45
- # Install the wheel files
46
- #RUN pip install /app/insightface-0.7.3-cp310-cp310-win_amd64.whl
47
- #RUN pip install /app/dlib-19.22.99-cp310-cp310-win_amd64.whl
48
-
49
- # Install the rest of the dependencies from requirements.txt
50
- RUN pip install -r requirements.txt
51
-
52
- # Install torch, torchvision, and torchaudio with the specified extra index URL
53
- RUN pip install torch==2.0.1+cu118 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
54
-
55
- # Ensure the application is run as a non-root user
56
- RUN adduser --disabled-password --gecos '' appuser && chown -R appuser /app
57
  USER appuser
58
 
59
- # Copy the rest of the application code
60
- #COPY . .
61
  # Expose the port
62
  EXPOSE 7860
63
 
64
  # Command to run the app
65
  CMD ["python3", "app.py"]
66
-
67
-
68
-
 
1
  # Use an official CUDA runtime as a parent image
2
+ FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04 as builder
3
 
4
+ # Set environment variables
5
  ENV DEBIAN_FRONTEND=noninteractive
6
+ ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
7
+ ENV MPLCONFIGDIR=/app/.cache/matplotlib
8
+ ENV XDG_CACHE_HOME=/app/.cache
9
+ ENV FONTCONFIG_PATH=/app/.cache/fontconfig
10
 
11
  # Install necessary system dependencies
12
  RUN apt-get update && apt-get install -y \
 
20
  python3-pip \
21
  python3-dev \
22
  && rm -rf /var/lib/apt/lists/*
23
+
24
  # Reset noninteractive mode
25
  ENV DEBIAN_FRONTEND=
26
 
27
+ # Set working directory
28
+ WORKDIR /app
29
+
30
+ # Copy only the requirements file first to leverage Docker cache
31
+ COPY requirements.txt .
32
+
33
+ # Install pip and upgrade it
34
+ RUN pip install --upgrade pip
35
+
36
+ # Install dependencies
37
+ RUN pip install -r requirements.txt
38
+
39
+ # Install PyTorch with CUDA support
40
+ RUN pip install torch==2.0.1+cu118 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118
41
+
42
+ # Create a non-root user
43
+ RUN adduser --disabled-password --gecos '' appuser
44
 
45
+ # Second stage: final image
46
+ FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu20.04
47
+
48
+ # Copy installed packages from builder stage
49
+ COPY --from=builder /usr/local/lib/python3.8/dist-packages /usr/local/lib/python3.8/dist-packages
50
+ COPY --from=builder /usr/local/bin /usr/local/bin
51
+
52
+ # Set environment variables
53
  ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
54
  ENV MPLCONFIGDIR=/app/.cache/matplotlib
55
  ENV XDG_CACHE_HOME=/app/.cache
56
  ENV FONTCONFIG_PATH=/app/.cache/fontconfig
57
 
58
+ # Create cache directories
59
  RUN mkdir -p /app/.cache/huggingface/hub /app/.cache/matplotlib /app/.cache/fontconfig
60
 
61
+ # Copy the application code
62
+ COPY . /app
63
 
64
  # Set working directory
 
65
  WORKDIR /app
66
 
67
+ # Change ownership of the app directory to the non-root user
68
+ RUN chown -R appuser:appuser /app
 
 
 
 
 
 
 
69
 
70
+ # Switch to non-root user
 
 
 
 
 
 
 
 
 
 
 
71
  USER appuser
72
 
 
 
73
  # Expose the port
74
  EXPOSE 7860
75
 
76
  # Command to run the app
77
  CMD ["python3", "app.py"]