agentsay commited on
Commit
63b1417
·
verified ·
1 Parent(s): 6543f83

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +10 -4
Dockerfile CHANGED
@@ -1,23 +1,29 @@
1
  # Use an official Python runtime as the base image
2
  FROM python:3.9-slim
3
 
 
 
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
  # Create a cache directory and set permissions
8
- RUN mkdir -p /app/cache && chmod -R 777 /app/cache
9
 
10
  # Set environment variable for Hugging Face cache
11
- ENV TRANSFORMERS_CACHE=/app/cache
12
 
13
  # Copy requirements file
14
- COPY requirements.txt .
15
 
16
  # Install dependencies
17
  RUN pip install --no-cache-dir -r requirements.txt
18
 
19
  # Copy the FastAPI application code
20
- COPY main.py .
 
 
 
21
 
22
  # Expose port 7860 for the FastAPI app
23
  EXPOSE 7860
 
1
  # Use an official Python runtime as the base image
2
  FROM python:3.9-slim
3
 
4
+ # Create a non-root user
5
+ RUN useradd -m -u 1000 appuser
6
+
7
  # Set working directory
8
  WORKDIR /app
9
 
10
  # Create a cache directory and set permissions
11
+ RUN mkdir -p /app/cache/huggingface && chown -R appuser:appuser /app
12
 
13
  # Set environment variable for Hugging Face cache
14
+ ENV HF_HOME=/app/cache/huggingface
15
 
16
  # Copy requirements file
17
+ COPY --chown=appuser:appuser requirements.txt .
18
 
19
  # Install dependencies
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
  # Copy the FastAPI application code
23
+ COPY --chown=appuser:appuser main.py .
24
+
25
+ # Switch to non-root user
26
+ USER appuser
27
 
28
  # Expose port 7860 for the FastAPI app
29
  EXPOSE 7860