Somalitts commited on
Commit
f95c80f
·
verified ·
1 Parent(s): c8ea8ab

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +41 -0
Dockerfile CHANGED
@@ -5,7 +5,48 @@ WORKDIR /app
5
  # Prevent permission errors with HuggingFace cache
6
  ENV TRANSFORMERS_CACHE=/tmp/hf-cache
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
 
 
9
  COPY requirements.txt .
10
  RUN apt-get update && apt-get install -y ffmpeg && pip install --no-cache-dir -r requirements.txt
11
 
 
5
  # Prevent permission errors with HuggingFace cache
6
  ENV TRANSFORMERS_CACHE=/tmp/hf-cache
7
 
8
+ # Start from a slim Python base image
9
+ FROM python:3.10-slim
10
+
11
+ # Set the working directory
12
+ WORKDIR /app
13
+
14
+ # Create a non-root user and group. This is a security best practice.
15
+ RUN groupadd -r appuser && useradd -r -g appuser appuser
16
+
17
+ # Install system dependencies. 'ffmpeg' is needed by torchaudio for some formats.
18
+ # Using --no-install-recommends keeps the image size smaller.
19
+ RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && apt-get clean && rm -rf /var/lib/apt/lists/*
20
+
21
+ # Create the Hugging Face cache directory within the app's home.
22
+ # This is a more reliable location than /tmp.
23
+ RUN mkdir -p /app/hf-cache
24
+
25
+ # Copy application files
26
+ COPY requirements.txt .
27
+ COPY app.py .
28
+
29
+ # Change the ownership of the app directory (and its contents) to the non-root user.
30
+ # This is the most critical step for fixing the permission error.
31
+ RUN chown -R appuser:appuser /app
32
+
33
+ # Switch to the non-root user. From this point on, all commands run as 'appuser'.
34
+ USER appuser
35
+
36
+ # Set environment variables for Hugging Face cache.
37
+ # The 'appuser' now owns this directory, so it can write here.
38
+ ENV HF_HOME=/app/hf-cache
39
+ ENV TRANSFORMERS_CACHE=/app/hf-cache
40
+
41
+ # Install Python dependencies.
42
+ # Running this as the non-root user can sometimes help avoid permission issues.
43
+ RUN pip install --no-cache-dir -r requirements.txt
44
+
45
+ # Expose the port the app runs on
46
+ EXPOSE 7860
47
 
48
+ # The command to run your application
49
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
50
  COPY requirements.txt .
51
  RUN apt-get update && apt-get install -y ffmpeg && pip install --no-cache-dir -r requirements.txt
52