AAYUSH1003 commited on
Commit
369ddee
·
1 Parent(s): 49ef539

fix: CPU-only torch + move indexing to container startup

Browse files

- Install torch from CPU wheel index to prevent sentence-transformers
from pulling multi-GB CUDA wheels (nvidia-cublas, cudnn, etc.) onto
the CPU-only HF Space, which was OOM-killing the build.
- Move repo indexing out of docker build (which loaded the embedding
model + embedded two repos into RAM) into a startup entrypoint.
First container start now indexes on demand; subsequent restarts
reuse ephemeral disk.
- Multi-stage build: node:20-slim for frontend, python:3.11-slim for
app. Frontend dist copied across.

Fixes HF Space build error (exit 137 / OOMKilled).

Files changed (2) hide show
  1. Dockerfile +19 -9
  2. docker-entrypoint.sh +12 -0
Dockerfile CHANGED
@@ -6,7 +6,7 @@ RUN npm ci
6
  COPY frontend/ ./
7
  RUN npm run build
8
 
9
- # ---- Stage 2: Python app + pre-built indexes -------------------------------
10
  FROM python:3.11-slim
11
 
12
  # git is needed for `git diff`-based incremental indexing and to clone the
@@ -18,6 +18,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
18
 
19
  WORKDIR /app
20
 
 
 
 
 
 
 
 
21
  COPY requirements.txt ./
22
  RUN pip install --no-cache-dir -r requirements.txt
23
 
@@ -27,22 +34,25 @@ COPY . .
27
  COPY --from=frontend /frontend/dist ./frontend/dist
28
 
29
  # HF Spaces containers run as a non-root user by convention; create one and
30
- # make sure it owns everything, including the HF model cache written below.
 
31
  RUN useradd -m -u 1000 appuser
32
  ENV HF_HOME=/app/.cache/huggingface
33
- RUN mkdir -p "$HF_HOME" && chown -R appuser:appuser /app
 
34
 
35
  USER appuser
36
  ENV PYTHONPATH=/app/src
37
  ENV REPOGRAG_INDEX_DIR=/app/indexes
38
 
39
  # Showcase repo used for the second demo entry in indexes/showcase.json.
40
- RUN git clone --depth 1 https://github.com/expressjs/express.git /app/showcase_repos/express
 
41
 
42
- # Build both indexes at image-build time (bakes in the ~320MB embedding model
43
- # download too) so the first real user request isn't slow.
44
- RUN python3 -m repograg.cli index . --db /app/indexes/repograg.db && \
45
- python3 -m repograg.cli index /app/showcase_repos/express --db /app/indexes/express.db
 
46
 
47
  EXPOSE 7860
48
- CMD ["uvicorn", "repograg.server:app", "--host", "0.0.0.0", "--port", "7860"]
 
6
  COPY frontend/ ./
7
  RUN npm run build
8
 
9
+ # ---- Stage 2: Python app ----------------------------------------------------
10
  FROM python:3.11-slim
11
 
12
  # git is needed for `git diff`-based incremental indexing and to clone the
 
18
 
19
  WORKDIR /app
20
 
21
+ # CPU-only torch first — sentence-transformers will see it already installed
22
+ # and skip the multi-GB CUDA wheels (this Space has no GPU; the CUDA download
23
+ # was OOM-killing the build).
24
+ RUN pip install --no-cache-dir \
25
+ --index-url https://download.pytorch.org/whl/cpu \
26
+ torch==2.12.1
27
+
28
  COPY requirements.txt ./
29
  RUN pip install --no-cache-dir -r requirements.txt
30
 
 
34
  COPY --from=frontend /frontend/dist ./frontend/dist
35
 
36
  # HF Spaces containers run as a non-root user by convention; create one and
37
+ # make sure it owns everything, including the HF model cache and the index
38
+ # directory written at container startup.
39
  RUN useradd -m -u 1000 appuser
40
  ENV HF_HOME=/app/.cache/huggingface
41
+ RUN mkdir -p "$HF_HOME" /app/indexes /app/showcase_repos && \
42
+ chown -R appuser:appuser /app
43
 
44
  USER appuser
45
  ENV PYTHONPATH=/app/src
46
  ENV REPOGRAG_INDEX_DIR=/app/indexes
47
 
48
  # Showcase repo used for the second demo entry in indexes/showcase.json.
49
+ RUN git clone --depth 1 https://github.com/expressjs/express.git \
50
+ /app/showcase_repos/express
51
 
52
+ # Indexing (embedding model download + embedding two repos) happens at
53
+ # container startup, not at build time — the builder VM was OOM-killing it.
54
+ COPY --chown=appuser:appuser docker-entrypoint.sh /app/docker-entrypoint.sh
55
+ RUN chmod +x /app/docker-entrypoint.sh
56
+ CMD ["/app/docker-entrypoint.sh"]
57
 
58
  EXPOSE 7860
 
docker-entrypoint.sh ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+ if [ ! -f /app/indexes/repograg.db ]; then
4
+ echo "Building repograg index..."
5
+ python3 -m repograg.cli index . --db /app/indexes/repograg.db
6
+ fi
7
+ if [ ! -f /app/indexes/express.db ]; then
8
+ echo "Building express index..."
9
+ python3 -m repograg.cli index /app/showcase_repos/express \
10
+ --db /app/indexes/express.db
11
+ fi
12
+ exec uvicorn repograg.server:app --host 0.0.0.0 --port 7860