abdullahalioo commited on
Commit
509b7ad
·
verified ·
1 Parent(s): 6f6ae2a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -8
Dockerfile CHANGED
@@ -3,21 +3,36 @@ FROM python:3.10-slim
3
  # Set working directory
4
  WORKDIR /app
5
 
6
- # Install dependencies
7
- RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
 
 
8
 
9
- # Set a writable Hugging Face cache directory
10
- ENV TRANSFORMERS_CACHE=/app/hf_cache
 
11
 
12
- # Copy requirements and install
 
 
 
 
 
13
  COPY requirements.txt .
14
- RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
15
 
16
- # Copy app files
 
 
 
 
17
  COPY . .
18
 
19
  # Expose port
20
  EXPOSE 7860
21
 
 
 
 
 
22
  # Run the app
23
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
3
  # Set working directory
4
  WORKDIR /app
5
 
6
+ # Install system dependencies
7
+ RUN apt-get update && \
8
+ apt-get install -y --no-install-recommends build-essential && \
9
+ rm -rf /var/lib/apt/lists/*
10
 
11
+ # Create and set writable cache directories with proper permissions
12
+ RUN mkdir -p /tmp/hf_cache && \
13
+ chmod -R 777 /tmp/hf_cache
14
 
15
+ # Set environment variables for Hugging Face cache
16
+ ENV HF_HOME=/tmp/hf_cache
17
+ ENV TRANSFORMERS_CACHE=/tmp/hf_cache
18
+ ENV HUGGINGFACE_HUB_CACHE=/tmp/hf_cache
19
+
20
+ # Copy requirements first to leverage Docker cache
21
  COPY requirements.txt .
 
22
 
23
+ # Install Python dependencies
24
+ RUN pip install --upgrade pip && \
25
+ pip install --no-cache-dir -r requirements.txt
26
+
27
+ # Copy application code
28
  COPY . .
29
 
30
  # Expose port
31
  EXPOSE 7860
32
 
33
+ # Run as non-root user for better security
34
+ RUN useradd -m myuser && chown -R myuser /app
35
+ USER myuser
36
+
37
  # Run the app
38
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]