devcom33
commited on
Commit
·
7f80261
1
Parent(s):
35e86bd
Updated FastAPI code
Browse files- Dockerfile +29 -23
Dockerfile
CHANGED
@@ -5,7 +5,7 @@ RUN apt-get update && apt-get install -y \
|
|
5 |
git \
|
6 |
ffmpeg \
|
7 |
libsndfile1 \
|
8 |
-
|
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
|
17 |
-
RUN mkdir -p /
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
# Copy
|
21 |
-
COPY . .
|
22 |
-
RUN chown
|
23 |
|
24 |
-
# Switch to the non-root user
|
25 |
USER app
|
26 |
|
27 |
-
# Set environment variables
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
ENV PATH="/home/app/.local/bin:${PATH}"
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
RUN
|
|
|
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
|