Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +37 -30
Dockerfile
CHANGED
|
@@ -1,31 +1,38 @@
|
|
| 1 |
-
# Use a lightweight Python image
|
| 2 |
-
FROM python:3.10-slim
|
| 3 |
-
|
| 4 |
-
# Set
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
+
# 1. Use a lightweight Python image
|
| 2 |
+
FROM python:3.10-slim
|
| 3 |
+
|
| 4 |
+
# 2. Set environment variables
|
| 5 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 6 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 7 |
+
PYTHONPATH=/code \
|
| 8 |
+
HOME=/home/user \
|
| 9 |
+
PATH=/home/user/.local/bin:$PATH \
|
| 10 |
+
HF_HOME=/code/.cache
|
| 11 |
+
|
| 12 |
+
# 3. Set working directory
|
| 13 |
+
WORKDIR /code
|
| 14 |
+
|
| 15 |
+
# 4. Install system dependencies
|
| 16 |
+
RUN apt-get update && apt-get install -y \
|
| 17 |
+
build-essential \
|
| 18 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 19 |
+
|
| 20 |
+
# 5. Create a non-root user (Hugging Face Requirement)
|
| 21 |
+
RUN useradd -m -u 1000 user
|
| 22 |
+
RUN mkdir -p /code/.cache && chown -R user:user /code
|
| 23 |
+
|
| 24 |
+
# 6. Switch to the non-root user
|
| 25 |
+
USER user
|
| 26 |
+
|
| 27 |
+
# 7. Copy requirements and install
|
| 28 |
+
COPY --chown=user requirements.txt /code/requirements.txt
|
| 29 |
+
RUN pip install --no-cache-dir --user --upgrade -r /code/requirements.txt
|
| 30 |
+
|
| 31 |
+
# 8. Copy the entire project
|
| 32 |
+
COPY --chown=user . /code
|
| 33 |
+
|
| 34 |
+
# 9. Expose port 7860
|
| 35 |
+
EXPOSE 7860
|
| 36 |
+
|
| 37 |
+
# 10. Start the application
|
| 38 |
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|