Spaces:
Running
Running
Soumik Bose commited on
Commit ·
a653a00
1
Parent(s): c492bb4
ok
Browse files- Dockerfile +12 -16
Dockerfile
CHANGED
|
@@ -5,41 +5,37 @@ FROM python:3.11-slim
|
|
| 5 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 6 |
PYTHONUNBUFFERED=1 \
|
| 7 |
PYTHONIOENCODING=UTF-8 \
|
| 8 |
-
#
|
| 9 |
HF_HOME=/app/cache \
|
| 10 |
TRANSFORMERS_CACHE=/app/cache
|
| 11 |
|
| 12 |
-
# Install system dependencies
|
| 13 |
RUN apt-get update && apt-get install -y --no-install-recommends curl \
|
| 14 |
&& rm -rf /var/lib/apt/lists/* \
|
| 15 |
&& useradd -m -u 1000 user
|
| 16 |
|
| 17 |
-
# Set working directory
|
| 18 |
WORKDIR /app
|
| 19 |
|
| 20 |
-
# --- LAYER 1: Dependencies
|
| 21 |
COPY --chown=user:user requirements.txt .
|
| 22 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 23 |
|
| 24 |
-
# --- LAYER 2: Model
|
| 25 |
-
#
|
| 26 |
-
# This
|
| 27 |
-
|
| 28 |
-
COPY --chown=user:user models ./models
|
| 29 |
|
| 30 |
-
# --- LAYER 3: Application Code
|
| 31 |
COPY --chown=user:user . .
|
| 32 |
|
| 33 |
-
# Ensure
|
| 34 |
-
RUN mkdir -p $HF_HOME && chown -R user:user /app/cache
|
| 35 |
|
| 36 |
-
# Switch
|
| 37 |
USER user
|
| 38 |
|
| 39 |
-
# Expose port
|
| 40 |
EXPOSE 7860
|
| 41 |
|
| 42 |
# Start script
|
| 43 |
-
# 1. Background loop pings the HF Space URL to keep it alive
|
| 44 |
-
# 2. Uvicorn runs the app
|
| 45 |
CMD bash -c "while true; do curl -s https://sasasas635-database-chat.hf.space/ping >/dev/null && sleep 300; done & uvicorn main:app --host 0.0.0.0 --port 7860 --workers 4 --loop asyncio"
|
|
|
|
| 5 |
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 6 |
PYTHONUNBUFFERED=1 \
|
| 7 |
PYTHONIOENCODING=UTF-8 \
|
| 8 |
+
# Set HF_HOME to a writable directory
|
| 9 |
HF_HOME=/app/cache \
|
| 10 |
TRANSFORMERS_CACHE=/app/cache
|
| 11 |
|
| 12 |
+
# Install system dependencies
|
| 13 |
RUN apt-get update && apt-get install -y --no-install-recommends curl \
|
| 14 |
&& rm -rf /var/lib/apt/lists/* \
|
| 15 |
&& useradd -m -u 1000 user
|
| 16 |
|
|
|
|
| 17 |
WORKDIR /app
|
| 18 |
|
| 19 |
+
# --- LAYER 1: Dependencies ---
|
| 20 |
COPY --chown=user:user requirements.txt .
|
| 21 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 22 |
|
| 23 |
+
# --- LAYER 2: Model Download (Cached) ---
|
| 24 |
+
# Instead of copying local files, we download the model during the build.
|
| 25 |
+
# This layer will be CACHED and won't run again unless you change this line.
|
| 26 |
+
RUN python3 -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='BAAI/bge-base-en-v1.5', local_dir='./models/bge-base-en-v1.5')"
|
|
|
|
| 27 |
|
| 28 |
+
# --- LAYER 3: Application Code ---
|
| 29 |
COPY --chown=user:user . .
|
| 30 |
|
| 31 |
+
# Ensure permissions
|
| 32 |
+
RUN mkdir -p $HF_HOME && chown -R user:user /app/cache && chown -R user:user /app/models
|
| 33 |
|
| 34 |
+
# Switch user
|
| 35 |
USER user
|
| 36 |
|
| 37 |
+
# Expose port
|
| 38 |
EXPOSE 7860
|
| 39 |
|
| 40 |
# Start script
|
|
|
|
|
|
|
| 41 |
CMD bash -c "while true; do curl -s https://sasasas635-database-chat.hf.space/ping >/dev/null && sleep 300; done & uvicorn main:app --host 0.0.0.0 --port 7860 --workers 4 --loop asyncio"
|