okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b2de2641f
main
1# Strata container image, built from the engine COMPONENT PACKAGE: nothing is compiled on the user's side. 2# 3# one image = the Terminal (bundled Python 3.12 + strata_cli / strata_control / serve, built exactly as the release archive) 4# + one engine package (CUDA 13, CUDA 12, HIP gfx120X, HIP gfx110X or SYCL) + the entrypoint 5# 6# Build it with docker/build.sh (it assembles the build context: the Terminal sources and the package folder): 7# 8# docker/build.sh --flavor cuda --engine /path/to/0.1.45.3-linux-x86_64-cuda-cuda13 --tag strata:0.2.7-cuda13 9# 10# Plain `docker build` also works when the context folder has this layout (build.sh makes it): 11# terminal-src/ the files package_terminal.py needs (packaging/, strata_cli/, strata_control/, serve/, tools/, data/, ...) 12# engine/ one folder per engine package, exactly as `package_engine.py` wrote it (engine-component.json inside) 13# docker/ entrypoint.sh, strata-wrapper.sh, healthcheck.sh 14# docker build --build-arg FLAVOR=cuda -t strata:0.2.7-cuda13 -f Dockerfile <context> 15# 16# FLAVOR picks the small set of system libraries the runtime image adds and its base: 17# cuda NVIDIA: the engine package carries cudart/cublas; the driver's libcuda comes from nvidia-container-toolkit 18# hip AMD: the engine package carries the ROCm runtime and kernels; the host's amdgpu driver and /dev/kfd are used 19# sycl Intel: the engine package carries oneAPI's SYCL runtime; this image adds the Level Zero loader and Intel's compute runtime 20# (Ubuntu 26.04 base: its compute runtime knows Arc A- and B-series; the 24.04 one does not know Battlemage) 21# 22# Only the legacy-builder-safe Dockerfile features are used (no heredocs, no --mount), so it builds with `docker build` as shipped 23# in docker.io as well as with BuildKit. 24 25ARG BASE_IMAGE=ubuntu:24.04 26 27# ---- 1. the Terminal: the release archive, built here (pinned CPython 3.12 + hash-locked wheels, installed at build time only) 28FROM ${ BASE_IMAGE } AS terminal 29ENV DEBIAN_FRONTEND=noninteractive 30RUN apt-get update \ 31 && apt-get install -y --no-install-recommends python3 ca-certificates \ 32 && rm -rf /var/lib/apt/lists/* 33COPY terminal-src/ /src/ 34# the sources have no .git here (and the image has no git): build.sh passes the commit they are from, package_terminal.py writes it to COMMIT 35ARG STRATA_COMMIT= 36ENV STRATA_BUILD_COMMIT=${ STRATA_COMMIT } 37RUN python3 /src/packaging/package_terminal.py --out /out --cache /cache \ 38 && mkdir -p /opt/strata \ 39 && tar -xzf /out/strata-terminal-*-linux-x86_64.tar.gz -C /opt/strata \ 40 && mv /opt/strata/strata-terminal-* /opt/strata/terminal \ 41 && /opt/strata/terminal/bin/strata --version 42# gguf-py (the model preparation tools) is part of the Terminal archive (third_party/strata-gguf-py), so the first start fetches nothing from 43# GitHub and the image needs no llama.cpp: check that it is there 44RUN test -f /opt/strata/terminal/third_party/strata-gguf-py/gguf/__init__.py 45 46# ---- 2. the engine package, checked before it is allowed into the image: every file's hash, and every library it imports is 47# bundled or belongs to the OS / GPU driver (packaging/binary_deps.py, the check the packager runs) 48FROM ${ BASE_IMAGE } AS verify 49COPY --from=terminal /opt/strata/terminal /opt/strata/terminal 50COPY terminal-src/packaging/package_engine.py terminal-src/packaging/binary_deps.py /opt/strata/terminal/packaging/ 51COPY engine/ /engine/ 52RUN set -e; n=0; for d in /engine/*/; do \ 53 echo "== $d"; \ 54 /opt/strata/terminal/python/bin/python3 /opt/strata/terminal/packaging/package_engine.py --verify "$d"; \ 55 /opt/strata/terminal/python/bin/python3 /opt/strata/terminal/packaging/binary_deps.py "$d"; \ 56 n=$((n+1)); \ 57 done; [ "$n" -ge 1 ] || { echo "no engine package in the build context (engine/<package>/engine-component.json)"; exit 1; } 58 59# ---- 3. the runtime image 60FROM ${ BASE_IMAGE } 61ARG FLAVOR=cuda 62ARG STRATA_VERSION=dev 63ARG ENGINE_LABEL= 64ENV DEBIAN_FRONTEND=noninteractive 65 66# system libraries the engine packages leave to the OS (SYSTEM-LIBS.txt), plus tini (PID 1: forwards docker stop, reaps children) 67RUN set -e; \ 68 pkgs="tini ca-certificates libgomp1 libatomic1 libnuma1 zlib1g"; \ 69 case "$FLAVOR" in \ 70 cuda) ;; \ 71 hip) pkgs="$pkgs libdrm2 libdrm-amdgpu1 libelf1t64 libtinfo6 libpci3" ;; \ 72 sycl) pkgs="$pkgs libze1 libze-intel-gpu1 intel-opencl-icd" ;; \ 73 *) echo "FLAVOR must be cuda, hip or sycl"; exit 1 ;; \ 74 esac; \ 75 apt-get update; apt-get install -y --no-install-recommends $pkgs; \ 76 rm -rf /var/lib/apt/lists/* /var/cache/apt/* 77 78COPY --from=terminal /opt/strata/terminal /opt/strata/terminal 79COPY --from=verify /engine/ /opt/strata/components/engine/ 80COPY docker/entrypoint.sh docker/healthcheck.sh /opt/strata/ 81COPY docker/strata-wrapper.sh /usr/local/bin/strata 82RUN chmod 0755 /opt/strata/entrypoint.sh /opt/strata/healthcheck.sh /usr/local/bin/strata 83 84# Does the dynamic linker find every library of the package inside this image? (the GPU driver's libcuda / libnvidia-* come from the host) 85RUN set -e; \ 86 for d in /opt/strata/components/engine/*/; do \ 87 miss=$(find "$d" -type f \( -name 'strata*' -o -name '*.so' -o -name '*.so.*' \) ! -name '*.json' ! -name '*.txt' | while read -r f; do \ 88 head -c4 "$f" | grep -q ELF || continue; \ 89 LD_LIBRARY_PATH="$d" ldd "$f" 2>/dev/null | grep 'not found' | grep -v -E 'libcuda\.so|libnvidia|libnvcuvid|libze_intel_gpu|libhsa-runtime64|libdrm_amdgpu' | sed "s|^|$(basename "$f"): |"; \ 90 done | sort -u); \ 91 if [ -n "$miss" ]; then echo "MISSING LIBRARIES in $d"; echo "$miss"; exit 1; fi; \ 92 echo "libraries of $d resolve inside this image"; \ 93 done 94 95# Everything that is yours lives in /data: model files, the prepared pack, presets, tuning results, the API key, logs. 96# The engine and the Terminal are in the image; updating the image never touches /data. 97ENV STRATA_COMPONENTS_DIR=/opt/strata/components \ 98 STRATA_INSTALL_DIR=/data/install \ 99 XDG_STATE_HOME=/data/state \ 100 XDG_CONFIG_HOME=/data/config \ 101 HOME=/data/home \ 102 PORT=8080 \ 103 LANG=C.UTF-8 PYTHONUNBUFFERED=1 PYTHONNOUSERSITE=1 \ 104 STRATA_IN_DOCKER=1 \ 105 NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=compute,utility 106VOLUME ["/data" ] 107EXPOSE 8080 108 109LABEL org.opencontainers.image.title="Strata" \ 110 org.opencontainers.image.source="https://github.com/Niko1221/Strata" \ 111 org.opencontainers.image.url="https://github.com/Niko1221/Strata" \ 112 org.opencontainers.image.documentation="https://github.com/Niko1221/Strata/blob/main/docs/DOCKER.md" \ 113 org.opencontainers.image.description="Strata local LLM server (Terminal + engine package), flavor ${ FLAVOR } " \ 114 org.opencontainers.image.version=" ${ STRATA_VERSION } " \ 115 org.opencontainers.image.licenses="see LICENSE" \ 116 com.strata.flavor=" ${ FLAVOR } " \ 117 com.strata.engine=" ${ ENGINE_LABEL } " 118 119# The port only opens after the model is downloaded, prepared and loaded (minutes; hours for a first 70 GB download), so the 120# start period is long: "starting" is not "unhealthy". 121HEALTHCHECK --interval=30s --timeout=8s --start-period=2h --retries=3CMD ["/opt/strata/healthcheck.sh" ] 122 123# `docker stop` sends SIGTERM to tini, which passes it to the entrypoint; the entrypoint runs `strata launch --stop` (drain, unload, 124# free the GPU memory). Give it time: docker run --stop-timeout 120 (compose: stop_grace_period: 2m). 125STOPSIGNAL SIGTERM 126ENTRYPOINT ["/usr/bin/tini" ,"--" ,"/opt/strata/entrypoint.sh" ] 127CMD ["run" ]