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

Updated FastAPI code

Browse files
Files changed (1) hide show
  1. Dockerfile +10 -7
Dockerfile CHANGED
@@ -10,28 +10,31 @@ RUN apt-get update && apt-get install -y \
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
30
  ENV HF_HUB_CACHE=/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
 
10
  # Set working directory
11
  WORKDIR /app
12
 
13
+ # Create a non-root user with a dedicated home directory
14
+ RUN addgroup --system app && adduser --system --group --home /home/app app
15
 
16
+ # Create cache directories and set ownership
 
17
  RUN mkdir -p /tmp/huggingface /tmp/matplotlib
18
  RUN chown -R app:app /tmp/huggingface /tmp/matplotlib
19
 
20
+ # Copy source code and set ownership
21
+ # Do this before switching user
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
29
+ # Add the user's local bin to the PATH
30
+ ENV PATH=/home/app/.local/bin:$PATH
31
  ENV HF_HOME=/tmp/huggingface
32
  ENV HF_HUB_CACHE=/tmp/huggingface
33
  ENV TRANSFORMERS_CACHE=/tmp/huggingface
34
  ENV MPLCONFIGDIR=/tmp/matplotlib
35
 
36
+ # Now, run pip install as the 'app' user.
37
+ # Pip will correctly install packages to /home/app/.local
38
  RUN pip install --upgrade pip
39
  RUN pip install --no-cache-dir torch torchvision torchaudio
40
  RUN pip install --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git