File size: 3,326 Bytes
df6cd5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ─────────────────────────────────────────────────────────────────────────────
# DevAI Studio v4.9.2 β€” STORAGE-OPTIMIZED Dockerfile
# Target: Hugging Face Spaces (CPU basic, 50 GB free storage)
#
# Key changes vs original:
#   1. Ollama is NOT installed at build time (~150 MB saved).
#      It installs lazily inside entrypoint.sh on first Private Mode request.
#   2. NO local model weights are pre-bundled (~22 GB saved).
#   3. Same Python + framework stack as original β€” all functionality intact.
# ─────────────────────────────────────────────────────────────────────────────
FROM python:3.10-slim

ENV DEBIAN_FRONTEND=noninteractive \
    PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    GRADIO_ANALYTICS_ENABLED=false

# ── System deps ───────────────────────────────────────────────────────────────
# curl: needed by entrypoint.sh to install Ollama on demand
# git: needed by DevAI Studio's git_operations module
# build-essential: torch/transformers compile deps
RUN apt-get update && apt-get install -y --no-install-recommends \
        git \
        curl \
        ca-certificates \
        build-essential \
        libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# ── Non-root user (HF Spaces convention) ─────────────────────────────────────
RUN useradd -m -u 1000 devai
USER devai
ENV HOME=/home/devai \
    PATH=/home/devai/.local/bin:$PATH \
    WORKSPACE_DIR=/home/devai/workspace \
    TRANSFORMERS_CACHE=/home/devai/.cache/huggingface \
    HF_HOME=/home/devai/.cache/huggingface

WORKDIR /home/devai/app

# ── Python dependencies (only on-disk cost at build time) ────────────────────
COPY --chown=devai:devai requirements.txt ./requirements.txt
RUN pip install --user --upgrade pip \
    && pip install --user -r requirements.txt

# ── Project code ─────────────────────────────────────────────────────────────
COPY --chown=devai:devai . .

# ── Runtime config ───────────────────────────────────────────────────────────
ENV GRADIO_SERVER_NAME=0.0.0.0 \
    GRADIO_SERVER_PORT=7860 \
    PORT=7860 \
    # Tell DevAI that Ollama isn't installed yet; it'll be installed lazily
    DEVAI_OLLAMA_INSTALLED=false

# ── Replace CMD with our smart bootstrap ─────────────────────────────────────
COPY --chown=devai:devai entrypoint.sh /home/devai/entrypoint.sh
RUN chmod +x /home/devai/entrypoint.sh

EXPOSE 7860

CMD ["/home/devai/entrypoint.sh"]