# opencode-gemma4-gb10: opencode 1.18.23 driving Gemma 4 26B-A4B NVFP4 served by vLLM in the same container.
# Port of gx10 start_opencode_gemma4.sh. The vLLM part is the gemma4-26b-a4b-nvfp4-gb10 capsule's image; the opencode
# part is the opencode-dsflash-openrouter-gb10 capsule's (same version, same warm-up).
# Base: vllm/vllm-openai:gemma4-cu130 (vLLM 0.19.1), the image gx10's start_gemma4.sh runs,
# pinned by its multi-arch index digest.
FROM vllm/vllm-openai@sha256:0d152595cd940ea1e0890fa190a37b7a86e3f7f0f5048ac3e2e4c14529fea833
# gx10's script mounts the checkpoint's gemma4_patched.py over vLLM's gemma4.py: it fixes the
# NVFP4 scale-key mapping in FusedMoE. Same file, taken from the pinned revision of the weights
# repo and checked by sha256, installed at build time (the capsule runs as nobody).
RUN python3 -c "import urllib.request as u; u.urlretrieve('https://huggingface.co/bg-digitalservices/Gemma-4-26B-A4B-it-NVFP4/resolve/a15dd6f161881b62db952303a5bfb7be118ed15e/gemma4_patched.py', '/tmp/gemma4_patched.py')" \
 && echo '26d4748c74de9e24a5600e19c53e671ff0d0e5d6143f29c8c54b679e4f455977  /tmp/gemma4_patched.py' | sha256sum -c - \
 && mv /tmp/gemma4_patched.py /usr/local/lib/python3.12/dist-packages/vllm/model_executor/models/gemma4.py

RUN apt-get update -qq && apt-get install -y --no-install-recommends \
      ca-certificates git ripgrep jq curl xz-utils unzip file less procps build-essential python3-venv \
    && rm -rf /var/lib/apt/lists/*

# Node 22.23.2, official arm64 build, checked against nodejs.org's SHASUMS256.txt.
RUN curl -fsSL https://nodejs.org/dist/v22.23.2/node-v22.23.2-linux-arm64.tar.xz -o /tmp/node.tar.xz \
 && echo "fff4078c5def658577f92c88db7db3bc0072924bfb93fe52c1e744a54e94abb8  /tmp/node.tar.xz" | sha256sum -c - \
 && mkdir -p /opt/node && tar xJf /tmp/node.tar.xz -C /opt/node --strip-components=1 && rm /tmp/node.tar.xz \
 && ln -s /opt/node/bin/node /opt/node/bin/npm /opt/node/bin/npx /usr/local/bin/
ENV PATH=/opt/node/bin:$PATH

RUN npm install -g opencode-ai@1.18.23 && npm cache clean --force

# Everything opencode would otherwise fetch at run time (models.dev catalogue, LSP servers,
# self-update) is disabled. The npm packages it installs on a project's first use are
# warmed here, where the build has network (warm_opencode.sh); start.sh copies them into
# the throwaway HOME. Without this, every run would log a blocked registry.npmjs.org.
ENV OPENCODE_DISABLE_AUTOUPDATE=1 \
    OPENCODE_DISABLE_LSP_DOWNLOAD=1 \
    OPENCODE_DISABLE_MODELS_FETCH=1 \
    OPENCODE_DISABLE_SHARE=1
COPY opencode.json /etc/opencode/opencode.json
COPY warm_opencode.sh /tmp/warm_opencode.sh
RUN bash /tmp/warm_opencode.sh && rm /tmp/warm_opencode.sh

WORKDIR /scratch
