Spaces:
Sleeping
Sleeping
Create Dockerfile
Browse files- Dockerfile +40 -0
Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1. Stable Python base
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# 2. System dependencies (root)
|
| 5 |
+
RUN apt-get update && apt-get install -y \
|
| 6 |
+
libgomp1 \
|
| 7 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 8 |
+
|
| 9 |
+
# 3. Create non-root user
|
| 10 |
+
RUN useradd -m -u 1000 user
|
| 11 |
+
ENV HOME=/home/user \
|
| 12 |
+
PATH=/home/user/.local/bin:$PATH
|
| 13 |
+
WORKDIR $HOME/app
|
| 14 |
+
|
| 15 |
+
# 4. Permissions
|
| 16 |
+
RUN chown -R user:user $HOME
|
| 17 |
+
USER user
|
| 18 |
+
|
| 19 |
+
# 5. Environment (FIXED)
|
| 20 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 21 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 22 |
+
HF_HOME=$HOME/.cache/huggingface
|
| 23 |
+
|
| 24 |
+
# 6. Copy requirements first (better caching)
|
| 25 |
+
COPY --chown=user requirements.txt .
|
| 26 |
+
|
| 27 |
+
# 7. Install deps (Torch first = correct move)
|
| 28 |
+
RUN pip install --upgrade pip && \
|
| 29 |
+
pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu && \
|
| 30 |
+
pip install --no-cache-dir -r requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu
|
| 31 |
+
|
| 32 |
+
# 8. Copy app code
|
| 33 |
+
COPY --chown=user . .
|
| 34 |
+
|
| 35 |
+
# 9. Pre-download model (zero cold start)
|
| 36 |
+
RUN python -c "from sentence_transformers import CrossEncoder; CrossEncoder('cross-encoder/ms-marco-MiniLM-L6-v2')"
|
| 37 |
+
|
| 38 |
+
# 10. Expose + run
|
| 39 |
+
EXPOSE 7860
|
| 40 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|