Update Dockerfile
Browse files- Dockerfile +11 -13
Dockerfile
CHANGED
|
@@ -1,32 +1,30 @@
|
|
| 1 |
# Use a lightweight Python 3.10 base image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
-
# 1.
|
| 5 |
-
RUN apt-get update && apt-get install -y \
|
| 6 |
-
build-essential \
|
| 7 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
-
|
| 9 |
-
# 2. Hugging Face strictly requires running as a non-root user (UID 1000)
|
| 10 |
RUN useradd -m -u 1000 user
|
| 11 |
USER user
|
| 12 |
|
| 13 |
-
# Set up environment variables for the user
|
| 14 |
ENV HOME=/home/user \
|
| 15 |
PATH=/home/user/.local/bin:$PATH
|
| 16 |
|
| 17 |
# 3. Set the working directory
|
| 18 |
WORKDIR $HOME/app
|
| 19 |
|
| 20 |
-
# 4. Copy requirements
|
| 21 |
-
# We do this before copying the rest of the code to leverage Docker layer caching
|
| 22 |
COPY --chown=user requirements.txt $HOME/app/
|
|
|
|
|
|
|
| 23 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 24 |
-
pip install --no-cache-dir -r requirements.txt
|
|
|
|
| 25 |
|
| 26 |
-
#
|
| 27 |
COPY --chown=user app.py $HOME/app/
|
| 28 |
|
| 29 |
-
#
|
| 30 |
EXPOSE 7860
|
| 31 |
|
| 32 |
-
#
|
|
|
|
|
|
| 1 |
# Use a lightweight Python 3.10 base image
|
| 2 |
FROM python:3.10-slim
|
| 3 |
|
| 4 |
+
# 1. Hugging Face strictly requires running as a non-root user (UID 1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
RUN useradd -m -u 1000 user
|
| 6 |
USER user
|
| 7 |
|
| 8 |
+
# 2. Set up environment variables for the user
|
| 9 |
ENV HOME=/home/user \
|
| 10 |
PATH=/home/user/.local/bin:$PATH
|
| 11 |
|
| 12 |
# 3. Set the working directory
|
| 13 |
WORKDIR $HOME/app
|
| 14 |
|
| 15 |
+
# 4. Copy requirements first to leverage Docker layer caching
|
|
|
|
| 16 |
COPY --chown=user requirements.txt $HOME/app/
|
| 17 |
+
|
| 18 |
+
# 5. Install dependencies, using the pre-built CPU wheel to bypass compilation
|
| 19 |
RUN pip install --no-cache-dir --upgrade pip && \
|
| 20 |
+
pip install --no-cache-dir -r requirements.txt \
|
| 21 |
+
--extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu
|
| 22 |
|
| 23 |
+
# 6. Copy the main application code
|
| 24 |
COPY --chown=user app.py $HOME/app/
|
| 25 |
|
| 26 |
+
# 7. Expose port 7860 (The standard port for HF Spaces)
|
| 27 |
EXPOSE 7860
|
| 28 |
|
| 29 |
+
# 8. Start the Uvicorn server
|
| 30 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|