neuralbroker commited on
Commit
ba3b381
Β·
verified Β·
1 Parent(s): b93d2d5

Update Dockerfile (v2.1 production)

Browse files
Files changed (1) hide show
  1. Dockerfile +53 -6
Dockerfile CHANGED
@@ -1,18 +1,65 @@
1
- FROM python:3.11-slim
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  WORKDIR /app
4
 
 
5
  COPY requirements.txt .
6
  RUN pip install --no-cache-dir -r requirements.txt
7
 
 
8
  COPY server.py .
9
- COPY frontend/ frontend/
10
 
11
- ENV BLITZKODE_HOST=0.0.0.0
12
- ENV BLITZKODE_PORT=7860
13
- ENV BLITZKODE_GPU_LAYERS=0
14
- ENV BLITZKODE_THREADS=4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  EXPOSE 7860
17
 
 
 
 
 
 
 
 
 
 
 
18
  CMD ["python", "server.py"]
 
1
+ # ─── Stage 1: Build frontend ─────────────────────────────────────────────────
2
+ FROM node:20-alpine AS frontend-build
3
+
4
+ WORKDIR /app/frontend
5
+
6
+ # Install deps first for better layer caching
7
+ COPY frontend/package*.json ./
8
+ RUN npm ci --silent
9
+
10
+ COPY frontend/ ./
11
+ RUN npm run build
12
+
13
+ # ─── Stage 2: Python runtime ─────────────────────────────────────────────────
14
+ FROM python:3.11-slim AS runtime
15
+
16
+ # Install curl (primary healthcheck tool) and keep the image lean
17
+ RUN apt-get update \
18
+ && apt-get install -y --no-install-recommends curl \
19
+ && rm -rf /var/lib/apt/lists/*
20
+
21
+ # Create non-root user early; home directory is created at /home/appuser
22
+ RUN useradd --create-home appuser
23
 
24
  WORKDIR /app
25
 
26
+ # Install Python dependencies as root (system-wide, before dropping privileges)
27
  COPY requirements.txt .
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
30
+ # Copy application source
31
  COPY server.py .
 
32
 
33
+ # Copy built frontend assets from stage 1
34
+ COPY --from=frontend-build /app/frontend/dist ./frontend/dist
35
+
36
+ # Create a zero-byte placeholder so Docker sees the expected mount path.
37
+ # At runtime this file is replaced by the volume-mounted blitzkode.gguf.
38
+ RUN touch /app/blitzkode.gguf \
39
+ && chown -R appuser:appuser /app
40
+
41
+ # ─── Sensible runtime defaults ────────────────────────────────────────────────
42
+ # All of these can be overridden at runtime via -e / docker-compose environment.
43
+ ENV BLITZKODE_HOST=0.0.0.0 \
44
+ BLITZKODE_PORT=7860 \
45
+ BLITZKODE_MODEL_PATH=/app/blitzkode.gguf \
46
+ BLITZKODE_FRONTEND_PATH=/app/frontend/dist/index.html \
47
+ BLITZKODE_GPU_LAYERS=0 \
48
+ BLITZKODE_THREADS=4 \
49
+ BLITZKODE_PRELOAD_MODEL=true \
50
+ BLITZKODE_N_CTX=2048 \
51
+ BLITZKODE_BATCH=128
52
 
53
  EXPOSE 7860
54
 
55
+ # Healthcheck: prefer curl (installed above); fall back to Python urllib so the
56
+ # check still works if this image is rebuilt without the curl layer.
57
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
58
+ CMD curl -sf http://localhost:7860/health \
59
+ || python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" \
60
+ || exit 1
61
+
62
+ # Drop to non-root for the actual process
63
+ USER appuser
64
+
65
  CMD ["python", "server.py"]