# Negotiated GPU — vLLM Serving Image
#
# Build:
#   cd infra/vllm && ./deploy.sh build push
#
# Used by RunPod on-demand pods (and Modal once their platform recovers).
# Must be publicly pullable, and published to ghcr.io — NOT Docker Hub, whose
# per-IP anonymous pull limit fails every pull from RunPod's shared-IP fleet
# (negotiated-x0l). Contains no secrets: a public base image plus two scripts.
#
# Defaults to Qwen 3.5-35B-A3B FP8 on a single 48GB+ card (L40S / L40 / A6000 /
# A100). Every knob is env-overridable at pod-create time so the image doesn't
# need to be rebuilt to try a different model.
#
# v0.21.0 could not load Qwen3.8-27B-FP8 (2026-08-29 spike: 900s, HTTP 404,
# embed never bound). v0.28.0 documents Qwen3.8 / GDN. Pin the cu129 Ubuntu
# 24.04 tag to match the previous CUDA/OS pair.

FROM vllm/vllm-openai:v0.28.0-cu129-ubuntu2404

# Fast HF downloads — hf_transfer parallelizes shard fetch by ~3-5x.
RUN pip install --no-cache-dir 'huggingface_hub[hf_transfer]'

# btrfs-progs for the Mjolnir-compatible snapshotting volume; util-linux for
# losetup/mount/truncate; openssh-server for diagnostic SSH access to pods;
# curl for start.sh's /health polling against the embedding sidecar.
RUN apt-get update && apt-get install -y --no-install-recommends \
		btrfs-progs util-linux openssh-server curl \
	&& rm -rf /var/lib/apt/lists/* \
	&& mkdir -p /var/run/sshd /root/.ssh \
	&& chmod 700 /root/.ssh

ENV VLLM_MODEL=Qwen/Qwen3.5-35B-A3B-FP8 \
	VLLM_QUANTIZATION=fp8 \
	VLLM_KV_CACHE_DTYPE=fp8 \
	VLLM_MAX_MODEL_LEN=81920 \
	VLLM_MAX_NUM_SEQS=32 \
	VLLM_GPU_MEMORY_UTILIZATION=0.88 \
	VLLM_SERVED_MODEL_NAME=qwen-3.5-35b-a3b \
	LLM_API_PORT=8000 \
	VLLM_TENSOR_PARALLEL_SIZE=1 \
	VLLM_EMBED_MODEL=Qwen/Qwen3-Embedding-0.6B \
	VLLM_EMBED_SERVED_MODEL_NAME=qwen3-embedding:0.6b \
	VLLM_EMBED_PORT=8001 \
	VLLM_EMBED_MAX_MODEL_LEN=512 \
	VLLM_EMBED_GPU_MEMORY_UTILIZATION=0.05 \
	HF_HOME=/workspace/hf-cache \
	HF_HUB_ENABLE_HF_TRANSFER=1

# Both models (LLM and embedding) are fetched at first boot into HF_HOME on
# the persistent network volume, so they survive pod restarts. With
# HF_HUB_ENABLE_HF_TRANSFER=1 the embedding download (~1.2 GB) is ~30s and
# dwarfed by the FP8 LLM weights — not worth baking into image layers.

COPY start.sh /start.sh
COPY setup-btrfs.sh /setup-btrfs.sh
RUN chmod +x /start.sh /setup-btrfs.sh

EXPOSE 8000 8001

# Override vllm/vllm-openai's entrypoint so we can interpolate env vars.
ENTRYPOINT ["/start.sh"]
