File size: 2,480 Bytes
ba3b381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c544c2
 
 
ba3b381
8c544c2
 
 
ba3b381
8c544c2
 
ba3b381
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8c544c2
 
 
ba3b381
 
 
 
 
 
 
 
 
 
8c544c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# ─── Stage 1: Build frontend ─────────────────────────────────────────────────
FROM node:20-alpine AS frontend-build

WORKDIR /app/frontend

# Install deps first for better layer caching
COPY frontend/package*.json ./
RUN npm ci --silent

COPY frontend/ ./
RUN npm run build

# ─── Stage 2: Python runtime ─────────────────────────────────────────────────
FROM python:3.11-slim AS runtime

# Install curl (primary healthcheck tool) and keep the image lean
RUN apt-get update \
    && apt-get install -y --no-install-recommends curl \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user early; home directory is created at /home/appuser
RUN useradd --create-home appuser

WORKDIR /app

# Install Python dependencies as root (system-wide, before dropping privileges)
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application source
COPY server.py .

# Copy built frontend assets from stage 1
COPY --from=frontend-build /app/frontend/dist ./frontend/dist

# Create a zero-byte placeholder so Docker sees the expected mount path.
# At runtime this file is replaced by the volume-mounted blitzkode.gguf.
RUN touch /app/blitzkode.gguf \
    && chown -R appuser:appuser /app

# ─── Sensible runtime defaults ────────────────────────────────────────────────
# All of these can be overridden at runtime via -e / docker-compose environment.
ENV BLITZKODE_HOST=0.0.0.0 \
    BLITZKODE_PORT=7860 \
    BLITZKODE_MODEL_PATH=/app/blitzkode.gguf \
    BLITZKODE_FRONTEND_PATH=/app/frontend/dist/index.html \
    BLITZKODE_GPU_LAYERS=0 \
    BLITZKODE_THREADS=4 \
    BLITZKODE_PRELOAD_MODEL=true \
    BLITZKODE_N_CTX=2048 \
    BLITZKODE_BATCH=128

EXPOSE 7860

# Healthcheck: prefer curl (installed above); fall back to Python urllib so the
# check still works if this image is rebuilt without the curl layer.
HEALTHCHECK --interval=30s --timeout=10s --start-period=90s --retries=3 \
    CMD curl -sf http://localhost:7860/health \
        || python -c "import urllib.request; urllib.request.urlopen('http://localhost:7860/health')" \
        || exit 1

# Drop to non-root for the actual process
USER appuser

CMD ["python", "server.py"]