Coots commited on
Commit
15a4429
·
verified ·
1 Parent(s): 67059e0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -3
Dockerfile CHANGED
@@ -2,13 +2,38 @@ FROM python:3.10-slim
2
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y git
 
 
 
6
 
 
 
 
 
 
 
 
 
 
 
7
  COPY requirements.txt .
8
  RUN pip install --no-cache-dir -r requirements.txt
9
 
10
- COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  EXPOSE 7860
13
 
14
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Install required system dependencies
6
+ RUN apt-get update && \
7
+ apt-get install -y --no-install-recommends git gcc python3-dev && \
8
+ rm -rf /var/lib/apt/lists/*
9
 
10
+ # Create a dedicated user and cache directory with proper permissions
11
+ RUN useradd -m appuser && \
12
+ mkdir -p /cache && \
13
+ chown appuser:appuser /cache
14
+
15
+ # Create and activate virtual environment
16
+ RUN python -m venv /opt/venv
17
+ ENV PATH="/opt/venv/bin:$PATH"
18
+
19
+ # Install Python dependencies
20
  COPY requirements.txt .
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
23
+ # Copy application code (as non-root user)
24
+ COPY --chown=appuser:appuser . .
25
+
26
+ # Set environment variables
27
+ ENV TRANSFORMERS_CACHE=/cache
28
+ ENV PYTHONUNBUFFERED=1
29
+ ENV PYTHONPATH=/app
30
+
31
+ # Switch to non-root user
32
+ USER appuser
33
+
34
+ # Create the cache directory with correct permissions
35
+ RUN mkdir -p /cache
36
 
37
  EXPOSE 7860
38
 
39
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]