Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +13 -12
Dockerfile
CHANGED
@@ -1,28 +1,29 @@
|
|
1 |
-
# Use a slim Python base image
|
2 |
FROM python:3.10-slim
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
|
8 |
COPY requirements.txt .
|
|
|
9 |
RUN pip install --no-cache-dir -r requirements.txt
|
10 |
|
11 |
-
# Copy project files
|
12 |
COPY . .
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
|
17 |
-
#
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
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"]
|