YALCINKAYA commited on
Commit
f843516
·
verified ·
1 Parent(s): f4105ac

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -14
Dockerfile CHANGED
@@ -1,35 +1,43 @@
1
- # Use the official Python image
2
  FROM python:3.9-slim
3
 
4
  # Set the working directory
5
  WORKDIR /app
6
 
7
- # Create a writable cache directory for Hugging Face
8
- RUN mkdir -p /workspace/huggingface_cache && \
9
- chmod -R 777 /workspace/huggingface_cache
10
 
11
- # Set environment variable for Hugging Face cache
12
- ENV HF_HOME=/workspace/huggingface_cache
 
13
 
14
- # Create and set permissions for the /.triton directory to avoid permission issues
15
- RUN mkdir -p /root/.triton && chmod -R 777 /root/.triton
16
- ENV TRITON_CACHE_DIR=/root/.triton
17
 
18
  # Install system dependencies
19
- RUN apt-get update && apt-get install -y git
 
 
 
20
 
21
  # Copy the requirements file into the image
22
  COPY requirements.txt requirements.txt
23
 
24
- # Install any needed packages specified in requirements.txt
25
  RUN pip install --no-cache-dir -r requirements.txt
26
 
27
- # Copy the rest of your application code into the image
28
  COPY . .
29
 
 
 
 
 
 
 
30
  # Expose the port your application will run on
31
  EXPOSE 7860
32
 
33
- # Command to run your application
34
  CMD ["python", "app.py"]
35
-
 
1
+ # Use the official Python image
2
  FROM python:3.9-slim
3
 
4
  # Set the working directory
5
  WORKDIR /app
6
 
7
+ # Create a non-root user
8
+ RUN useradd -m appuser
 
9
 
10
+ # Create writable directories for Hugging Face and Triton cache
11
+ RUN mkdir -p /workspace/huggingface_cache /home/appuser/.triton && \
12
+ chmod -R 777 /workspace/huggingface_cache /home/appuser/.triton
13
 
14
+ # Set environment variables
15
+ ENV HF_HOME=/workspace/huggingface_cache
16
+ ENV TRITON_CACHE_DIR=/home/appuser/.triton
17
 
18
  # Install system dependencies
19
+ RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
20
+
21
+ # Set umask to ensure proper file permissions
22
+ RUN umask 002
23
 
24
  # Copy the requirements file into the image
25
  COPY requirements.txt requirements.txt
26
 
27
+ # Install required packages
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
30
+ # Copy the rest of the application code
31
  COPY . .
32
 
33
+ # Change ownership to non-root user
34
+ RUN chown -R appuser:appuser /app /workspace/huggingface_cache /home/appuser/.triton
35
+
36
+ # Switch to non-root user
37
+ USER appuser
38
+
39
  # Expose the port your application will run on
40
  EXPOSE 7860
41
 
42
+ # Run the application
43
  CMD ["python", "app.py"]