abdullahalioo commited on
Commit
9249fc8
·
verified ·
1 Parent(s): aab7d7a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +10 -13
Dockerfile CHANGED
@@ -2,31 +2,28 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
5
- # 1. Install only essential system dependencies
6
- RUN apt-get update && \
7
- apt-get install -y --no-install-recommends \
8
- build-essential \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- # 2. Set cache directories (HF Spaces provides writable /tmp)
12
  ENV TRANSFORMERS_CACHE=/tmp/model_cache \
13
  HF_HOME=/tmp/huggingface \
14
  XDG_CACHE_HOME=/tmp/xdg_cache
15
 
16
- # 3. Create cache directories
17
- RUN mkdir -p ${TRANSFORMERS_CACHE} ${HF_HOME} ${XDG_CACHE_HOME}
 
18
 
19
- # 4. Copy requirements first (better layer caching)
20
  COPY requirements.txt .
21
  RUN pip install --no-cache-dir --upgrade pip && \
22
  pip install --no-cache-dir -r requirements.txt
23
 
24
- # 5. Copy application code
25
  COPY . .
26
 
27
- # 6. Health check endpoint
 
 
 
28
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
29
  CMD curl -f http://localhost:7860/health || exit 1
30
 
31
- # 7. Run with optimized settings
32
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # 1. Set cache directories with proper permissions
 
 
 
 
 
 
6
  ENV TRANSFORMERS_CACHE=/tmp/model_cache \
7
  HF_HOME=/tmp/huggingface \
8
  XDG_CACHE_HOME=/tmp/xdg_cache
9
 
10
+ # 2. Create cache directories with world write permissions
11
+ RUN mkdir -p ${TRANSFORMERS_CACHE} ${HF_HOME} ${XDG_CACHE_HOME} && \
12
+ chmod -R 777 /tmp
13
 
14
+ # 3. Install requirements
15
  COPY requirements.txt .
16
  RUN pip install --no-cache-dir --upgrade pip && \
17
  pip install --no-cache-dir -r requirements.txt
18
 
19
+ # 4. Copy application
20
  COPY . .
21
 
22
+ # 5. Run as non-root user
23
+ USER 1000
24
+
25
+ # 6. Health check
26
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
27
  CMD curl -f http://localhost:7860/health || exit 1
28
 
 
29
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]