abdullahalioo commited on
Commit
548e04f
·
verified ·
1 Parent(s): a63dfa3

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -14
Dockerfile CHANGED
@@ -2,30 +2,31 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
5
- # 1. Install system dependencies first (better caching)
6
  RUN apt-get update && \
7
- apt-get install -y --no-install-recommends gcc python3-dev && \
8
- rm -rf /var/lib/apt/lists/*
 
9
 
10
- # 2. Install Python dependencies
11
- COPY requirements.txt .
12
- RUN pip install --no-cache-dir -r requirements.txt
13
-
14
- # 3. Configure cache locations (using Hugging Face's recommended paths)
15
  ENV TRANSFORMERS_CACHE=/tmp/model_cache \
16
  HF_HOME=/tmp/huggingface \
17
  XDG_CACHE_HOME=/tmp/xdg_cache
18
 
19
- # 4. Create cache directories with correct permissions
20
- RUN mkdir -p ${TRANSFORMERS_CACHE} ${HF_HOME} ${XDG_CACHE_HOME} && \
21
- chmod -R 777 /tmp
 
 
 
 
22
 
23
- # 5. Copy application files
24
  COPY . .
25
 
26
- # 6. Health check (recommended for HF Spaces)
27
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
28
  CMD curl -f http://localhost:7860/health || exit 1
29
 
30
- # 7. Run with optimized Uvicorn settings
31
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
 
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"]