JJTsao commited on
Commit
bbda247
·
verified ·
1 Parent(s): 9d1b549

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -12
Dockerfile CHANGED
@@ -1,28 +1,29 @@
1
- # Use a slim Python base image
2
  FROM python:3.10-slim
3
 
4
- # Set working directory
5
- WORKDIR /app
6
 
7
- # Install Python dependencies
8
  COPY requirements.txt .
 
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
11
- # Copy project files
12
  COPY . .
13
 
14
- # Set environment for faster, clearer logging
15
- ENV PYTHONUNBUFFERED=1
16
 
17
- # Set cache directories to writable /tmp
18
  ENV HF_HOME=/tmp/huggingface \
19
- TRANSFORMERS_CACHE=/tmp/huggingface/transformers \
20
  HF_DATASETS_CACHE=/tmp/huggingface/datasets \
21
  HUGGINGFACE_HUB_CACHE=/tmp/huggingface/hub \
22
- XDG_CACHE_HOME=/tmp/huggingface
 
 
 
 
 
23
 
24
- # Expose the HF Spaces-required port
25
  EXPOSE 7860
26
 
27
- # Start the FastAPI app via uvicorn
28
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
  FROM python:3.10-slim
2
 
3
+ # Create a non-root user for Spaces (UID 1000 is the default)
4
+ RUN useradd -m -u 1000 user
5
 
6
+ WORKDIR /app
7
  COPY requirements.txt .
8
+
9
  RUN pip install --no-cache-dir -r requirements.txt
10
 
 
11
  COPY . .
12
 
13
+ # Make sure cache directories exist and are writable by non-root user
14
+ RUN mkdir -p /tmp/huggingface && chown -R user:user /tmp/huggingface
15
 
16
+ # Environment variables must be set before any Python code runs
17
  ENV HF_HOME=/tmp/huggingface \
 
18
  HF_DATASETS_CACHE=/tmp/huggingface/datasets \
19
  HUGGINGFACE_HUB_CACHE=/tmp/huggingface/hub \
20
+ TRANSFORMERS_CACHE=/tmp/huggingface/transformers \
21
+ XDG_CACHE_HOME=/tmp/huggingface \
22
+ PYTHONUNBUFFERED=1
23
+
24
+ USER user
25
+ WORKDIR /app
26
 
 
27
  EXPOSE 7860
28
 
 
29
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]