mothy-08 commited on
Commit ·
075c5e0
1
Parent(s): a2da8c8
Updated Dockerfile
Browse files- Dockerfile +21 -13
Dockerfile
CHANGED
|
@@ -3,29 +3,37 @@ FROM python:3.10-slim
|
|
| 3 |
# 1. Environment Config
|
| 4 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 5 |
PYTHONUNBUFFERED=1 \
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
|
| 9 |
# 2. Security: Create Non-Root User
|
| 10 |
RUN useradd -m -u 1000 user
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
-
# 3. Install Dependencies
|
| 14 |
-
# We install Torch CPU first to avoid the massive GPU bloat
|
| 15 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 16 |
-
RUN pip install --upgrade pip && \
|
| 17 |
-
pip install -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
|
| 18 |
|
| 19 |
-
# 4.
|
| 20 |
-
# We
|
| 21 |
-
# This
|
| 22 |
-
RUN
|
| 23 |
|
| 24 |
-
# 5.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
COPY --chown=user . .
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
USER user
|
| 29 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 30 |
|
| 31 |
CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 3 |
# 1. Environment Config
|
| 4 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 5 |
PYTHONUNBUFFERED=1 \
|
| 6 |
+
# Explicitly set where models get saved so we can control permissions
|
| 7 |
+
HF_HOME="/home/user/.cache/huggingface"
|
| 8 |
|
| 9 |
# 2. Security: Create Non-Root User
|
| 10 |
RUN useradd -m -u 1000 user
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
+
# 3. Install Dependencies (As Root)
|
|
|
|
| 14 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 15 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 16 |
+
pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
|
| 17 |
|
| 18 |
+
# 4. PREPARE CACHE (Critical Fix)
|
| 19 |
+
# We create the directory and give 'user' ownership BEFORE switching users.
|
| 20 |
+
# This prevents "Permission Denied" errors at runtime.
|
| 21 |
+
RUN mkdir -p $HF_HOME && chown -R user:user $HF_HOME
|
| 22 |
|
| 23 |
+
# 5. SWITCH TO USER
|
| 24 |
+
# We switch users NOW so that the model download is owned by 'user', not 'root'.
|
| 25 |
+
USER user
|
| 26 |
+
|
| 27 |
+
# 6. DOWNLOAD MODEL (Memory Safe Fix)
|
| 28 |
+
# We use 'snapshot_download' instead of 'SentenceTransformer()'.
|
| 29 |
+
# This downloads the files to disk WITHOUT loading them into RAM (avoids OOM crashes).
|
| 30 |
+
RUN python -c "from huggingface_hub import snapshot_download; snapshot_download('sentence-transformers/all-mpnet-base-v2')"
|
| 31 |
+
|
| 32 |
+
# 7. Copy Code
|
| 33 |
+
# Since we are already 'user', we use --chown just to be safe.
|
| 34 |
COPY --chown=user . .
|
| 35 |
|
| 36 |
+
# 8. Runtime Config
|
|
|
|
| 37 |
ENV PATH="/home/user/.local/bin:$PATH"
|
| 38 |
|
| 39 |
CMD ["uvicorn", "api.server:app", "--host", "0.0.0.0", "--port", "7860"]
|