PMS61 commited on
Commit
5f4db71
·
1 Parent(s): fbd0a6b
Files changed (1) hide show
  1. Dockerfile +18 -12
Dockerfile CHANGED
@@ -1,14 +1,14 @@
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.10-slim
3
 
4
- # Set the working directory in the container
5
- WORKDIR /code
6
 
7
- # Set environment variables for caching
8
- ENV PYTHONPATH="/code"
9
- ENV HF_HOME="/code/.cache"
10
 
11
- # Install system dependencies
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
13
  build-essential \
14
  ffmpeg \
@@ -16,16 +16,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
16
  libxext6 \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
- # Copy and install Python dependencies
20
- COPY ./requirements.txt /code/requirements.txt
 
 
 
21
  RUN pip install --no-cache-dir --upgrade pip
22
  RUN pip install --no-cache-dir -r requirements.txt gunicorn gevent
23
 
24
- # Copy the application code
25
- COPY . /code/
 
 
 
26
 
27
- # Expose the port
28
  EXPOSE 7860
29
 
30
- # Run the application
31
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "4", "--worker-class", "gevent", "--timeout", "600", "app:app"]
 
1
  # Use an official Python runtime as a parent image
2
  FROM python:3.10-slim
3
 
4
+ # Create a non-root user and group to run the application
5
+ RUN groupadd -r appuser && useradd -r -g appuser -m appuser
6
 
7
+ # Set environment variables for caching in a writable directory and for Python's module path
8
+ ENV HF_HOME="/home/appuser/.cache"
9
+ ENV PYTHONPATH="/app"
10
 
11
+ # Install system dependencies as root
12
  RUN apt-get update && apt-get install -y --no-install-recommends \
13
  build-essential \
14
  ffmpeg \
 
16
  libxext6 \
17
  && rm -rf /var/lib/apt/lists/*
18
 
19
+ # Set the working directory
20
+ WORKDIR /app
21
+
22
+ # Copy and install Python dependencies as root
23
+ COPY ./requirements.txt /app/requirements.txt
24
  RUN pip install --no-cache-dir --upgrade pip
25
  RUN pip install --no-cache-dir -r requirements.txt gunicorn gevent
26
 
27
+ # Copy the application code and set ownership to the non-root user
28
+ COPY --chown=appuser:appuser . /app/
29
+
30
+ # Switch to the non-root user
31
+ USER appuser
32
 
33
+ # Expose the port the app runs on
34
  EXPOSE 7860
35
 
36
+ # Command to run the application using Gunicorn
37
  CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "4", "--worker-class", "gevent", "--timeout", "600", "app:app"]