Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +20 -15
Dockerfile
CHANGED
|
@@ -1,26 +1,31 @@
|
|
| 1 |
-
# Use the official Python image
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
-
# Install uv for fast dependency installation
|
| 5 |
COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
RUN useradd -m -u 1000 user
|
| 9 |
-
USER user
|
| 10 |
-
ENV PATH="/home/user/.local/bin:$PATH"
|
| 11 |
-
ENV UV_SYSTEM_PYTHON=1
|
| 12 |
-
|
| 13 |
WORKDIR /app
|
| 14 |
|
| 15 |
-
# Copy and install
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
RUN uv pip install -r requirements.txt
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# Tell HF which port to use
|
| 23 |
EXPOSE 7860
|
| 24 |
|
| 25 |
-
# Start the app
|
| 26 |
-
CMD ["
|
|
|
|
| 1 |
+
# 1. Use the official Python image (starts as root)
|
| 2 |
FROM python:3.12-slim
|
| 3 |
|
| 4 |
+
# 2. Install uv for fast dependency installation
|
| 5 |
COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv
|
| 6 |
|
| 7 |
+
# 3. Set the working directory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
WORKDIR /app
|
| 9 |
|
| 10 |
+
# 4. Copy requirements and install AS ROOT
|
| 11 |
+
# (Root has permission to write to /usr/local/lib/python3.12)
|
| 12 |
+
COPY requirements.txt .
|
| 13 |
+
ENV UV_SYSTEM_PYTHON=1
|
| 14 |
RUN uv pip install -r requirements.txt
|
| 15 |
|
| 16 |
+
# 5. Create the non-root user (UID 1000 is required by Hugging Face)
|
| 17 |
+
RUN useradd -m -u 1000 user
|
| 18 |
+
|
| 19 |
+
# 6. Copy the rest of your app and change ownership to the 'user'
|
| 20 |
+
COPY . .
|
| 21 |
+
RUN chown -R user:user /app
|
| 22 |
+
|
| 23 |
+
# 7. Switch to the non-root user for security at runtime
|
| 24 |
+
USER user
|
| 25 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 26 |
|
| 27 |
+
# 8. Tell HF which port to use
|
| 28 |
EXPOSE 7860
|
| 29 |
|
| 30 |
+
# 9. Start the app (using Gunicorn is recommended for production)
|
| 31 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:server"]
|