MISSAOUI commited on
Commit
4938104
·
verified ·
1 Parent(s): 3b55b10

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -9
Dockerfile CHANGED
@@ -1,14 +1,35 @@
1
- FROM python:3.12.4
2
- # Use the official Python 3.10.9 image
3
 
4
- # Copy the current directory contents into the container at .
5
- COPY . .
 
 
 
 
 
 
 
 
 
 
6
 
7
- # Set the working directory to /
8
  WORKDIR /app
9
 
10
- # Install requirements.txt
11
- RUN pip install --no-cache-dir --upgrade -r /requirements.txt
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- # Start the FastAPI app on port 7860, the default port expected by Spaces
14
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ FROM python:3.12.4-slim
 
2
 
3
+ # Set environment variables for cache and Python
4
+ ENV PYTHONUNBUFFERED=1 \
5
+ PYTHONDONTWRITEBYTECODE=1 \
6
+ PIP_NO_CACHE_DIR=1 \
7
+ HF_HOME=/app/.cache/huggingface \
8
+ TRANSFORMERS_CACHE=/app/.cache/huggingface \
9
+ TORCH_HOME=/app/.cache/torch
10
+
11
+ # Create non-root user and set up directories
12
+ RUN useradd -m appuser && \
13
+ mkdir -p /app/.cache/huggingface /app/.cache/torch && \
14
+ chown -R appuser:appuser /app
15
 
 
16
  WORKDIR /app
17
 
18
+ # Copy requirements first for better layer caching
19
+ COPY requirements.txt .
20
+
21
+ # Install dependencies as root
22
+ RUN pip install --no-cache-dir --upgrade pip && \
23
+ pip install --no-cache-dir -r requirements.txt
24
+
25
+ # Copy application code
26
+ COPY --chown=appuser:appuser . .
27
+
28
+ # Switch to non-root user
29
+ USER appuser
30
+
31
+ # Expose the port the app runs on
32
+ EXPOSE 7860
33
 
34
+ # Command to run the application
35
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]