devcom33 commited on
Commit
ef5b9d3
·
1 Parent(s): cc0d473

Updated FastAPI code

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -9
Dockerfile CHANGED
@@ -10,17 +10,20 @@ RUN apt-get update && apt-get install -y \
10
  # Set working directory
11
  WORKDIR /app
12
 
13
- # Copy source code
14
- COPY . .
15
-
16
- # Upgrade pip and install dependencies
17
- RUN pip install --upgrade pip
18
- RUN pip install --no-cache-dir torch torchvision torchaudio
19
- RUN pip install --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git
20
- RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # Create writable directories for model and matplotlib cache
 
23
  RUN mkdir -p /tmp/huggingface /tmp/matplotlib
 
 
 
 
 
 
 
 
24
 
25
  # Set environment variables to use writable paths
26
  ENV HF_HOME=/tmp/huggingface
@@ -28,8 +31,14 @@ ENV HF_HUB_CACHE=/tmp/huggingface
28
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
29
  ENV MPLCONFIGDIR=/tmp/matplotlib
30
 
 
 
 
 
 
 
31
  # Expose FastAPI port
32
  EXPOSE 7860
33
 
34
  # Run the FastAPI app
35
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
10
  # Set working directory
11
  WORKDIR /app
12
 
13
+ # Create a non-root user and group
14
+ RUN addgroup --system app && adduser --system --group app
 
 
 
 
 
 
15
 
16
  # Create writable directories for model and matplotlib cache
17
+ # And change their ownership to the new user
18
  RUN mkdir -p /tmp/huggingface /tmp/matplotlib
19
+ RUN chown -R app:app /tmp/huggingface /tmp/matplotlib
20
+
21
+ # Copy source code and change its ownership
22
+ COPY . .
23
+ RUN chown -R app:app /app
24
+
25
+ # Switch to the non-root user
26
+ USER app
27
 
28
  # Set environment variables to use writable paths
29
  ENV HF_HOME=/tmp/huggingface
 
31
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
32
  ENV MPLCONFIGDIR=/tmp/matplotlib
33
 
34
+ # Upgrade pip and install dependencies
35
+ RUN pip install --upgrade pip
36
+ RUN pip install --no-cache-dir torch torchvision torchaudio
37
+ RUN pip install --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git
38
+ RUN pip install --no-cache-dir -r requirements.txt
39
+
40
  # Expose FastAPI port
41
  EXPOSE 7860
42
 
43
  # Run the FastAPI app
44
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]