mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
Since the layout move /engine/ is the engine's source, but tools/docker/Dockerfile.src.dockerignore still carried the old /engine/ line (the built engine of setup.py), so the build context had no engine/ and `cmake -S engine` could not run. The list now names the folders .gitignore names for the built engines (/terminal/engine/, /terminal/engine-sycl/, /terminal/engine-cuda12/, /engine-sycl/, /engine-cuda12/) and the vendored llama.cpp at its new place (engine/third_party/llama.cpp, terminal/third_party/llama.cpp). There is no Dockerfile at the repository root, so the commands in docs/DOCKER.md and in the Dockerfile.src header now name it with -f tools/docker/Dockerfile.src (the ignore list next to it is only read then) and pass STRATA_COMMIT, which the Terminal stage needs because .git is not copied. The CUDA 12 example uses nvidia/cuda:12.9.2-devel-ubuntu24.04 (the tag exists) and no longer says BUILD_VISION=0: the picture reader is built for the same architectures as the engine, sm_60 / 61 / 70 included, and package_engine.py checks vision_archs against the package's archs; BUILD_VISION=0 stays documented as the opt-out. terminal/tests/terminal/test_docker_src_context.py reads the ignore list the way docker does and checks that no tracked file under engine/, tools/ or terminal/ is cut out, that the engine source is in, that the built-engine folders are out, and that every documented source build names the Dockerfile with -f. It fails on the old files and passes now. Based on the report and change of #6064 by rafal-prasal (credited in the release notes).
114 lines
8.2 KiB
Docker
114 lines
8.2 KiB
Docker
# Strata, built FROM SOURCE (NVIDIA CUDA 13). The engine is compiled here, packaged as an engine component package and then
|
|
# installed into the same runtime image as the ready-made ones (tools/docker/Dockerfile): same Terminal, same entrypoint, same /data volume.
|
|
#
|
|
# Most people want the ready-made images instead (nothing compiled): docs/DOCKER.md.
|
|
#
|
|
# Every source build needs STRATA_COMMIT: .git is not copied into the build, and the Terminal archive has to carry a COMMIT file.
|
|
# This is not the ready-made image's Dockerfile, so it is named with -f; the build then reads its ignore list from
|
|
# tools/docker/Dockerfile.src.dockerignore.
|
|
#
|
|
# docker build -t strata:src --build-arg STRATA_COMMIT=$(git rev-parse HEAD) -f tools/docker/Dockerfile.src . # RTX 20/30/40/50 (~25 min)
|
|
# docker build -t strata:src --build-arg STRATA_COMMIT=$(git rev-parse HEAD) -f tools/docker/Dockerfile.src --build-arg CUDA_ARCHITECTURES=86 .
|
|
# # one card only (faster); 86 = RTX 30, 89 = RTX 40, 120 = RTX 50
|
|
# docker build -t strata:src-cuda12 --build-arg STRATA_COMMIT=$(git rev-parse HEAD) -f tools/docker/Dockerfile.src \
|
|
# --build-arg CUDA_IMAGE=nvidia/cuda:12.9.2-devel-ubuntu24.04 \
|
|
# --build-arg CUDA_ARCHITECTURES="60;61;70;75;80;86;89" . # GTX 10 / P100 / V100 (driver 575+): the picture reader is built
|
|
# for the same architectures as the engine (checked on a Tesla P40 sm_61, a Tesla P100 sm_60 and a Tesla V100 sm_70);
|
|
# --build-arg BUILD_VISION=0 leaves it out
|
|
# docker run --rm --gpus all -p 127.0.0.1:8080:8080 --ulimit memlock=-1 --shm-size 2g --stop-timeout 120 \
|
|
# -v strata-data:/data -e MODEL=IQ3_XXS -e API_KEY=change-me-please-123 strata:src
|
|
#
|
|
# docker build has no GPU, so the CUDA architectures are given here instead of read from nvidia-smi. The engine is a fat binary with
|
|
# a machine-code part per listed architecture (plus PTX for the newest, which later cards can JIT), and the runtime picks the one
|
|
# matching your card. Narrow CUDA_ARCHITECTURES to your card for a faster build. Native code for the CPU that builds the image is NOT
|
|
# used (STRATA_PORTABLE=ON), so the image runs on any x86-64 CPU with AVX2.
|
|
#
|
|
# Plain legacy-builder features only (no heredocs, no --mount). AMD (HIP) and Intel (SYCL) source builds: docs/AMD_HIP.md, docs/INTEL.md.
|
|
|
|
ARG CUDA_IMAGE=nvidia/cuda:13.0.0-devel-ubuntu24.04
|
|
ARG RUNTIME_BASE=ubuntu:24.04
|
|
|
|
# ---- 1. compile the engine and make its component package
|
|
FROM ${CUDA_IMAGE} AS engine-build
|
|
ENV DEBIAN_FRONTEND=noninteractive PYTHONUNBUFFERED=1 PATH=/venv/bin:$PATH
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential ca-certificates git libgomp1 libatomic1 python3 python3-pip python3-venv unzip \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
WORKDIR /src
|
|
COPY . .
|
|
ARG CUDA_ARCHITECTURES="75;80;86;89;120"
|
|
ARG BUILD_VISION=1
|
|
ARG ENGINE_VERSION=
|
|
RUN python3 -m venv /venv && /venv/bin/pip install --no-cache-dir -r terminal/requirements.txt -r terminal/requirements-build.txt
|
|
# ggml comes from the vendored engine/third_party/strata-ggml; strata-vision is Strata's own reader (terminal/tools/vision/own): nothing is downloaded
|
|
RUN set -e; \
|
|
real=""; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' ' '); do real="$real;${a}-real"; done; real=${real#;}; \
|
|
last=$(echo "$CUDA_ARCHITECTURES" | tr ';,' ' ' | awk '{print $NF}'); \
|
|
sm60=OFF; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' ' '); do if [ "$a" -lt 75 ]; then sm60=ON; fi; done; \
|
|
/venv/bin/cmake -G Ninja -S engine -B build -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \
|
|
-DSTRATA_EXPERIMENTAL_SM60=$sm60 \
|
|
-DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON \
|
|
"-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual"; \
|
|
. tools/packaging/engine_targets.sh; targets=$(engine_targets /venv/bin/cmake build); \
|
|
/venv/bin/cmake --build build --target $targets -j "$(nproc)"; \
|
|
if [ "$BUILD_VISION" = "1" ]; then \
|
|
/venv/bin/cmake -G Ninja -S terminal/tools/vision -B build-vision -DCMAKE_BUILD_TYPE=Release \
|
|
-DSTRATA_VISION_CUDA=ON -DSTRATA_PORTABLE=ON "-DCMAKE_CUDA_ARCHITECTURES=${real};${last}-virtual"; \
|
|
/venv/bin/cmake --build build-vision --target strata-vision -j "$(nproc)"; \
|
|
fi
|
|
RUN set -e; \
|
|
mkdir -p /stage /engine; \
|
|
cp build/strata /stage/; \
|
|
[ -f build/libstrata_kq.so ] && cp build/libstrata_kq.so /stage/ || true; \
|
|
[ -f build-vision/bin/strata-vision ] && cp build-vision/bin/strata-vision /stage/ || true; \
|
|
ver="${ENGINE_VERSION:-$(sed -n 's/^[[:space:]]*project([^)]*VERSION[[:space:]]*\([0-9][0-9.]*\).*/\1/p' engine/CMakeLists.txt | head -1)}"; \
|
|
cudafull=$(nvcc --version | sed -n 's/.*release \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1); cudamajor=${cudafull%%.*}; \
|
|
if [ "$cudamajor" = 13 ]; then mindriver=580.65; else mindriver=575.51; fi; \
|
|
vision_archs=""; [ -f /stage/strata-vision ] && vision_archs=", \"vision_archs\": \"$CUDA_ARCHITECTURES\""; \
|
|
echo "{\"version\": \"$ver\", \"source\": \"docker build\", \"archs\": \"$CUDA_ARCHITECTURES\", \"cuda\": \"$cudafull\", \"portable\": true${vision_archs}}" > /stage/BUILD.json; \
|
|
python3 tools/packaging/collect_libs.py --binary build/strata --search /usr/local/cuda/lib64 --out /stage --also 'libcublasLt.so*'; \
|
|
archs=""; for a in $(echo "$CUDA_ARCHITECTURES" | tr ';,' ' '); do archs="$archs --arch sm_$a"; done; \
|
|
last=$(echo "$CUDA_ARCHITECTURES" | tr ';,' ' ' | awk '{print $NF}'); \
|
|
python3 tools/packaging/package_engine.py --src /stage --backend cuda --version "$ver" --out /engine $archs --arch "compute_$last" \
|
|
--min-driver nvidia=$mindriver --variant cuda$cudamajor --platform linux-x86_64 --build-id "docker-source-${ver}-cuda${cudafull}" --include SYSTEM-LIBS.txt --include 'libstrata_kq*' \
|
|
--include strata-vision; \
|
|
for d in /engine/*/; do python3 tools/packaging/package_engine.py --verify "$d"; python3 tools/packaging/binary_deps.py "$d"; done
|
|
|
|
# ---- 2. the Terminal (the release archive, built here)
|
|
FROM ${RUNTIME_BASE} AS terminal
|
|
ARG STRATA_COMMIT=
|
|
ENV STRATA_BUILD_COMMIT=${STRATA_COMMIT}
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install -y --no-install-recommends python3 ca-certificates git && rm -rf /var/lib/apt/lists/*
|
|
COPY . /src/
|
|
RUN python3 /src/tools/packaging/package_terminal.py --out /out --cache /cache \
|
|
&& mkdir -p /opt/strata \
|
|
&& tar -xzf /out/strata-terminal-*-linux-x86_64.tar.gz -C /opt/strata \
|
|
&& mv /opt/strata/strata-terminal-* /opt/strata/terminal \
|
|
&& /opt/strata/terminal/bin/strata --version
|
|
# gguf-py (the model preparation tools) is part of the Terminal archive (engine/third_party/strata-gguf-py), so the first start fetches nothing from
|
|
# GitHub and the image needs no llama.cpp: check that it is there
|
|
RUN test -f /opt/strata/terminal/third_party/strata-gguf-py/gguf/__init__.py
|
|
|
|
# ---- 3. the runtime image (the same as tools/docker/Dockerfile's, FLAVOR=cuda)
|
|
FROM ${RUNTIME_BASE}
|
|
ARG STRATA_VERSION=dev
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
RUN apt-get update && apt-get install -y --no-install-recommends tini ca-certificates libgomp1 libatomic1 libnuma1 zlib1g \
|
|
&& rm -rf /var/lib/apt/lists/* /var/cache/apt/*
|
|
COPY --from=terminal /opt/strata/terminal /opt/strata/terminal
|
|
COPY --from=engine-build /engine/ /opt/strata/components/engine/
|
|
COPY tools/docker/entrypoint.sh tools/docker/healthcheck.sh /opt/strata/
|
|
COPY tools/docker/strata-wrapper.sh /usr/local/bin/strata
|
|
RUN chmod 0755 /opt/strata/entrypoint.sh /opt/strata/healthcheck.sh /usr/local/bin/strata
|
|
ENV STRATA_COMPONENTS_DIR=/opt/strata/components STRATA_INSTALL_DIR=/data/install XDG_STATE_HOME=/data/state \
|
|
XDG_CONFIG_HOME=/data/config HOME=/data/home PORT=8080 LANG=C.UTF-8 PYTHONUNBUFFERED=1 PYTHONNOUSERSITE=1 STRATA_IN_DOCKER=1 \
|
|
NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=compute,utility
|
|
VOLUME ["/data"]
|
|
EXPOSE 8080
|
|
LABEL org.opencontainers.image.title="Strata" com.strata.flavor="cuda" com.strata.build="from-source" org.opencontainers.image.version="${STRATA_VERSION}"
|
|
HEALTHCHECK --interval=30s --timeout=8s --start-period=2h --retries=3 CMD ["/opt/strata/healthcheck.sh"]
|
|
STOPSIGNAL SIGTERM
|
|
ENTRYPOINT ["/usr/bin/tini", "--", "/opt/strata/entrypoint.sh"]
|
|
CMD ["run"]
|