Coots commited on
Commit
32f5b59
·
verified ·
1 Parent(s): 15a4429

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -22
Dockerfile CHANGED
@@ -2,38 +2,32 @@ FROM python:3.10-slim
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"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Install system dependencies (git is needed for some transformers models)
6
  RUN apt-get update && \
7
+ apt-get install -y git && \
8
+ apt-get clean && \
9
  rm -rf /var/lib/apt/lists/*
10
 
11
+ # Create a directory for cache that will be writeable by the user
12
+ RUN mkdir -p /cache && chmod a+rwx /cache
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  # Set environment variables
15
  ENV TRANSFORMERS_CACHE=/cache
16
+ ENV HF_HOME=/cache
17
  ENV PYTHONUNBUFFERED=1
 
18
 
19
+ COPY requirements.txt .
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ COPY . .
23
+
24
+ # Fix permissions (in case you're running as non-root)
25
+ RUN chmod a+rwx /app
26
 
27
  EXPOSE 7860
28
 
29
+ # Run as non-root user for security
30
+ RUN useradd -m myuser && chown -R myuser:myuser /app /cache
31
+ USER myuser
32
+
33
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]