devcom33 commited on
Commit
7f80261
·
1 Parent(s): 35e86bd

Updated FastAPI code

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -23
Dockerfile CHANGED
@@ -5,7 +5,7 @@ RUN apt-get update && apt-get install -y \
5
  git \
6
  ffmpeg \
7
  libsndfile1 \
8
- && rm -rf /var/lib/apt/lists/*
9
 
10
  # Set working directory
11
  WORKDIR /app
@@ -13,33 +13,39 @@ WORKDIR /app
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 to the 'app' user
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 its ownership
21
- COPY . .
22
- RUN chown -R app:app /app
23
 
24
- # Switch to the non-root user
25
  USER app
26
 
27
- # Set environment variables so the system can find executables and modules
28
- # 1. Add user's local bin to PATH for executables (like uvicorn)
29
- # 2. Add user's site-packages to PYTHONPATH for module imports
 
 
 
30
  ENV PATH="/home/app/.local/bin:${PATH}"
31
- ENV PYTHONPATH="/home/app/.local/lib/python3.10/site-packages"
32
- ENV HF_HOME=/tmp/huggingface
33
- ENV HF_HUB_CACHE=/tmp/huggingface
34
- ENV TRANSFORMERS_CACHE=/tmp/huggingface
35
- ENV MPLCONFIGDIR=/tmp/matplotlib
36
-
37
- # Run pip install as the 'app' user.
38
- # Pip will correctly install packages to /home/app/.local
39
- RUN pip install --upgrade pip
40
- RUN pip install --no-cache-dir torch torchvision torchaudio
41
- RUN pip install --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git
42
- RUN pip install --no-cache-dir -r requirements.txt
 
43
 
44
  # Expose the application port
45
  EXPOSE 7860
 
5
  git \
6
  ffmpeg \
7
  libsndfile1 \
8
+ && rm -rf /var/lib/apt/lists/*
9
 
10
  # Set working directory
11
  WORKDIR /app
 
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 with proper permissions
17
+ RUN mkdir -p /home/app/.cache/huggingface \
18
+ /home/app/.cache/matplotlib \
19
+ /home/app/.cache/torch \
20
+ && chown -R app:app /home/app
21
 
22
+ # Copy requirements first for better caching
23
+ COPY requirements.txt .
24
+ RUN chown app:app requirements.txt
25
 
26
+ # Switch to the non-root user early
27
  USER app
28
 
29
+ # Set environment variables to use user's home directory for caches
30
+ ENV HF_HOME=/home/app/.cache/huggingface
31
+ ENV HF_HUB_CACHE=/home/app/.cache/huggingface
32
+ ENV TRANSFORMERS_CACHE=/home/app/.cache/huggingface
33
+ ENV MPLCONFIGDIR=/home/app/.cache/matplotlib
34
+ ENV TORCH_HOME=/home/app/.cache/torch
35
  ENV PATH="/home/app/.local/bin:${PATH}"
36
+
37
+ # Install Python packages as the 'app' user
38
+ RUN pip install --user --upgrade pip
39
+ RUN pip install --user --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
40
+ RUN pip install --user --no-cache-dir git+https://github.com/pyannote/pyannote-audio.git
41
+ RUN pip install --user --no-cache-dir -r requirements.txt
42
+
43
+ # Copy source code and set ownership
44
+ COPY --chown=app:app . .
45
+
46
+ # Pre-download models to avoid runtime permission issues (optional)
47
+ # RUN python -c "from transformers import pipeline; pipeline('summarization', model='facebook/bart-large-cnn')"
48
+ # RUN python -c "from faster_whisper import WhisperModel; WhisperModel('tiny')"
49
 
50
  # Expose the application port
51
  EXPOSE 7860