Update Dockerfile
Browse files- Dockerfile +37 -28
Dockerfile
CHANGED
|
@@ -1,28 +1,37 @@
|
|
| 1 |
-
# Use lightweight Python base
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
# Set working directory
|
| 5 |
-
WORKDIR /app
|
| 6 |
-
|
| 7 |
-
# Copy files
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
ENV
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use lightweight Python base
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# Set working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy files first
|
| 8 |
+
# These will be owned by root initially
|
| 9 |
+
COPY . .
|
| 10 |
+
|
| 11 |
+
# Install dependencies
|
| 12 |
+
RUN pip install --no-cache-dir -r requirements.txt [cite: 2]
|
| 13 |
+
|
| 14 |
+
# Create cache directory (no chmod needed yet)
|
| 15 |
+
RUN mkdir -p /app/hf_cache
|
| 16 |
+
|
| 17 |
+
# Set environment variables for Hugging Face cache
|
| 18 |
+
ENV HF_HOME=/app/hf_cache
|
| 19 |
+
ENV TRANSFORMERS_CACHE=/app/hf_cache
|
| 20 |
+
|
| 21 |
+
# Expose Space port
|
| 22 |
+
EXPOSE 7860
|
| 23 |
+
|
| 24 |
+
# --- FIX IS HERE ---
|
| 25 |
+
# Create non-root user
|
| 26 |
+
RUN useradd -m appuser
|
| 27 |
+
|
| 28 |
+
# Give the new user ownership of the entire app directory
|
| 29 |
+
# This includes all code files and the hf_cache
|
| 30 |
+
RUN chown -R appuser:appuser /app
|
| 31 |
+
# --- END FIX ---
|
| 32 |
+
|
| 33 |
+
# Switch to non-root user
|
| 34 |
+
USER appuser
|
| 35 |
+
|
| 36 |
+
# Run Flask directly (no Gunicorn)
|
| 37 |
+
CMD ["python", "api_inference.py"]
|