Spaces:
Build error
Build error
thijs commited on
Commit ·
70f933a
1
Parent(s): d0ecf6b
- Dockerfile +25 -11
Dockerfile
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
|
|
| 1 |
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
|
|
|
|
| 7 |
WORKDIR /app
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
RUN mkdir -p /home/user/.cache/huggingface /app/.cache/huggingface &&
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
COPY --chown=user . .
|
| 23 |
-
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# Use official FastAPI image with Python 3.11 slim
|
| 2 |
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
|
| 3 |
|
| 4 |
+
# Copy requirements.txt first to leverage Docker cache
|
| 5 |
+
COPY --chown=user ./requirements.txt /app/requirements.txt
|
|
|
|
| 6 |
|
| 7 |
+
# Set working directory to /app
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
+
# Create user with uid 1000 (same as your logs)
|
| 11 |
+
RUN useradd -m -u 1000 user
|
| 12 |
+
|
| 13 |
+
# Give ownership of /app to the user so it can create folders there
|
| 14 |
+
RUN chown -R user:user /app
|
| 15 |
+
|
| 16 |
+
# Install dependencies as user
|
| 17 |
+
USER user
|
| 18 |
+
|
| 19 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 20 |
|
| 21 |
+
# Switch back to root temporarily to create cache folders with correct ownership
|
| 22 |
+
USER root
|
| 23 |
|
| 24 |
+
RUN mkdir -p /home/user/.cache/huggingface /app/.cache/huggingface && \
|
| 25 |
+
chown -R user:user /home/user/.cache /app/.cache
|
| 26 |
+
|
| 27 |
+
# Switch back to non-root user for app runtime
|
| 28 |
+
USER user
|
| 29 |
|
| 30 |
+
# Copy app source code (adjust as needed)
|
| 31 |
+
COPY --chown=user ./app /app/app
|
| 32 |
|
| 33 |
+
# Expose port if needed (default 80 for this image)
|
| 34 |
+
EXPOSE 80
|
| 35 |
|
| 36 |
+
# Command is inherited from base image: starts Uvicorn/Gunicorn server
|
| 37 |
|
|
|
|
|
|