hmm183 commited on
Commit
a79c90d
Β·
verified Β·
1 Parent(s): 109fd2d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -11
Dockerfile CHANGED
@@ -1,11 +1,10 @@
1
  # ────────────────────────────────────────────────────────────────────────────
2
- # Dockerfile for FastAPI + RAG on Hugging Face Spaces
3
- # Ensures /app/hf_cache is world-writable so Hugging Face can download models
4
  # ────────────────────────────────────────────────────────────────────────────
5
 
6
  FROM python:3.10-slim
7
 
8
- # 1) Install system packages needed for building native extensions
9
  RUN apt-get update && \
10
  apt-get install -y --no-install-recommends \
11
  build-essential \
@@ -14,29 +13,30 @@ RUN apt-get update && \
14
 
15
  WORKDIR /app
16
 
17
- # 2) Copy only requirements.txt first (faster Docker caching)
18
  COPY requirements.txt .
19
 
20
- # 3) Install PyTorch CPU from the official index, then install rest
21
  RUN pip install --upgrade pip && \
22
  pip install --no-cache-dir torch==2.1.2+cpu --index-url https://download.pytorch.org/whl/cpu && \
23
  pip install --no-cache-dir -r requirements.txt
24
 
25
- # 4) Create /app/hf_cache (for all Hugging Face downloads) and make it world‐writable
26
- RUN mkdir -p /app/hf_cache && chmod 777 /app/hf_cache
 
27
 
28
- # 5) Set environment vars so that Transformers, Sentence-Transformers, etc. use /app/hf_cache
29
  ENV HF_HOME=/app/hf_cache
30
  ENV TRANSFORMERS_CACHE=/app/hf_cache
31
  ENV HF_DATASETS_CACHE=/app/hf_cache
32
  ENV HF_METRICS_CACHE=/app/hf_cache
33
  ENV SENTENCE_TRANSFORMERS_CACHE=/app/hf_cache
34
 
35
- # 6) Copy the FastAPI code into the container
36
  COPY . .
37
 
38
- # 7) Expose port 7860 (HF Spaces default web port)
39
  EXPOSE 7860
40
 
41
- # 8) Run Uvicorn against app.py (which defines "app = FastAPI()")
42
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # ────────────────────────────────────────────────────────────────────────────
2
+ # Dockerfile for FastAPI + RAG (with pre-created writable chroma_db_users)
 
3
  # ────────────────────────────────────────────────────────────────────────────
4
 
5
  FROM python:3.10-slim
6
 
7
+ # 1) Install system packages for building any native extensions
8
  RUN apt-get update && \
9
  apt-get install -y --no-install-recommends \
10
  build-essential \
 
13
 
14
  WORKDIR /app
15
 
16
+ # 2) Copy requirements.txt first so pip layers can be cached
17
  COPY requirements.txt .
18
 
19
+ # 3) Install PyTorch CPU + the rest of your Python deps
20
  RUN pip install --upgrade pip && \
21
  pip install --no-cache-dir torch==2.1.2+cpu --index-url https://download.pytorch.org/whl/cpu && \
22
  pip install --no-cache-dir -r requirements.txt
23
 
24
+ # 4) Pre-create the HF cache folder and chroma_db_users folder, and make them writable
25
+ RUN mkdir -p /app/hf_cache && chmod 777 /app/hf_cache && \
26
+ mkdir -p /app/chroma_db_users && chmod 777 /app/chroma_db_users
27
 
28
+ # 5) Tell all HuggingFace libs to use /app/hf_cache instead of .cache
29
  ENV HF_HOME=/app/hf_cache
30
  ENV TRANSFORMERS_CACHE=/app/hf_cache
31
  ENV HF_DATASETS_CACHE=/app/hf_cache
32
  ENV HF_METRICS_CACHE=/app/hf_cache
33
  ENV SENTENCE_TRANSFORMERS_CACHE=/app/hf_cache
34
 
35
+ # 6) Copy the rest of your application code
36
  COPY . .
37
 
38
+ # 7) Expose the default HF Spaces port (7860)
39
  EXPOSE 7860
40
 
41
+ # 8) Launch Uvicorn against app.py (which defines `app = FastAPI()`)
42
  CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]