Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

Docker: pass the source commit into the terminal stage (no git in the image)

Niko1221436fbd0a6eae
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 709c43b11..83d9e64fd 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -31,6 +31,9 @@ RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 ca-certificates \
&& rm -rf /var/lib/apt/lists/*
COPY terminal-src/ /src/
+# 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
+ARG STRATA_COMMIT=
+ENV STRATA_BUILD_COMMIT=${STRATA_COMMIT}
RUN python3 /src/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 \
diff --git a/docker/build.sh b/docker/build.sh
index 4dfaf56bb..242c356ea 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -56,6 +56,10 @@ mkdir -p "$ctx/terminal-src" "$ctx/engine" "$ctx/docker"
cleanup() { if [ -n "$own_ctx" ] && [ -z "$ctxonly" ]; then rm -rf "$ctx"; fi; }
trap cleanup EXIT
+# the commit the sources are from (the build context has no .git; package_terminal.py writes it into the archive's COMMIT)
+commit=$(git -C "$repo" rev-parse HEAD 2>/dev/null || true)
+case "$commit" in *[!0-9a-f]*|"") commit="" ;; esac
+
# 1. the Terminal's sources: exactly what packaging/package_terminal.py copies (the working tree, so local edits are in the image)
cd "$repo"
paths="packaging bin strata.py strata_control strata_cli serve requirements.txt requirements-monitor.txt docs/MANAGEMENT_PROTOCOL.md docs/TERMINAL_LAUNCH.md data bench/prompts/standard-v1 setup.py ref/load.py CMakeLists.txt"
@@ -98,7 +102,7 @@ echo "flavor $flavor, base $base, engine(s): $engine_label, tag $tag"
# shellcheck disable=SC2086
docker build $nocache ${STRATA_DOCKER_BUILD_OPTS:-} \
--build-arg "BASE_IMAGE=$base" --build-arg "FLAVOR=$flavor" \
- --build-arg "STRATA_VERSION=$version" --build-arg "ENGINE_LABEL=$engine_label" \
+ --build-arg "STRATA_COMMIT=$commit" --build-arg "STRATA_VERSION=$version" --build-arg "ENGINE_LABEL=$engine_label" \
-t "$tag" "$ctx"
docker image inspect "$tag" --format 'built {{.RepoTags}} {{.Size}} bytes'
echo "Not pushed anywhere. Size on disk: $(docker image inspect "$tag" --format '{{.Size}}') bytes."
diff --git a/packaging/package_terminal.py b/packaging/package_terminal.py
index 7d1221061..afa0ee4a9 100644
--- a/packaging/package_terminal.py
+++ b/packaging/package_terminal.py
@@ -281,6 +281,19 @@ def write_archive(root: Path, name: str, out_dir: Path, kind: str) -> Path:
return path
+def source_commit() -> str:
+ """The commit the sources are from. STRATA_BUILD_COMMIT wins (a Docker build copies the files without .git and without git);
+ otherwise `git rev-parse HEAD`, when git exists and ROOT is a checkout. Empty when neither answers: the archive just has no COMMIT."""
+ given = os.environ.get("STRATA_BUILD_COMMIT", "").strip().lower()
+ if re.fullmatch(r"[0-9a-f]{40}", given):
+ return given
+ try:
+ out = subprocess.run(["git", "-C", str(ROOT), "rev-parse", "HEAD"], capture_output=True, text=True).stdout
+ except OSError: # no git installed
+ return ""
+ return out.strip().lower()
+
+
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--out", required=True, help="directory to write the archive into")
@@ -345,7 +358,7 @@ def main() -> int:
installer = None if args.no_installer else add_installer(root)
(root / "VERSION").write_text(version + "\n", encoding="utf-8")
# the commit the archive was built from: `strata bench run` records it (an archive has no .git to ask)
- built = subprocess.run(["git", "-C", str(ROOT), "rev-parse", "HEAD"], capture_output=True, text=True).stdout.strip().lower()
+ built = source_commit()
if re.fullmatch(r"[0-9a-f]{40}", built):
(root / "COMMIT").write_text(built + "\n", encoding="utf-8")
diff --git a/tests/terminal/test_terminal_commit.py b/tests/terminal/test_terminal_commit.py
new file mode 100644
index 000000000..cf2ec95a9
--- /dev/null
+++ b/tests/terminal/test_terminal_commit.py
@@ -0,0 +1,63 @@
+"""package_terminal.py must work where there is no git (the Docker build stage copies the sources without .git and the image has no git):
+the commit comes from STRATA_BUILD_COMMIT, falls back to git when it exists, and is simply left out when neither answers."""
+from __future__ import annotations
+
+import os
+import re
+import subprocess
+import sys
+import unittest
+from pathlib import Path
+from unittest import mock
+
+ROOT = Path(__file__).resolve().parents[2]
+sys.path.insert(0, str(ROOT / "packaging"))
+import package_terminal # noqa: E402
+
+SHA = "0123456789abcdef0123456789abcdef01234567"
+
+
+class SourceCommit(unittest.TestCase):
+ def test_env_wins_and_is_lower_cased(self):
+ with mock.patch.dict(os.environ, {"STRATA_BUILD_COMMIT": " " + SHA.upper() + " "}), \
+ mock.patch.object(package_terminal.subprocess, "run", side_effect=AssertionError("git must not run")):
+ self.assertEqual(package_terminal.source_commit(), SHA)
+
+ def test_no_git_installed_gives_empty_not_a_crash(self):
+ env = {k: v for k, v in os.environ.items() if k != "STRATA_BUILD_COMMIT"}
+ with mock.patch.dict(os.environ, env, clear=True), \
+ mock.patch.object(package_terminal.subprocess, "run", side_effect=FileNotFoundError("git")):
+ self.assertEqual(package_terminal.source_commit(), "")
+
+ def test_bad_env_value_falls_back_to_git(self):
+ done = subprocess.CompletedProcess([], 0, stdout=SHA + "\n", stderr="")
+ with mock.patch.dict(os.environ, {"STRATA_BUILD_COMMIT": "not-a-sha"}), \
+ mock.patch.object(package_terminal.subprocess, "run", return_value=done):
+ self.assertEqual(package_terminal.source_commit(), SHA)
+
+ def test_not_a_checkout_gives_no_commit_file_value(self):
+ done = subprocess.CompletedProcess([], 128, stdout="", stderr="fatal: not a git repository")
+ env = {k: v for k, v in os.environ.items() if k != "STRATA_BUILD_COMMIT"}
+ with mock.patch.dict(os.environ, env, clear=True), \
+ mock.patch.object(package_terminal.subprocess, "run", return_value=done):
+ self.assertEqual(package_terminal.source_commit(), "")
+
+
+class DockerPassesTheCommit(unittest.TestCase):
+ def test_dockerfile_turns_the_build_arg_into_the_env_the_packager_reads(self):
+ text = (ROOT / "docker" / "Dockerfile").read_text(encoding="utf-8")
+ self.assertRegex(text, r"ARG STRATA_COMMIT")
+ self.assertRegex(text, r"ENV STRATA_BUILD_COMMIT=\$\{STRATA_COMMIT\}")
+ self.assertLess(text.index("ENV STRATA_BUILD_COMMIT"), text.index("RUN python3 /src/packaging/package_terminal.py"))
+
+ def test_build_sh_passes_the_commit(self):
+ text = (ROOT / "docker" / "build.sh").read_text(encoding="utf-8")
+ self.assertIn('--build-arg "STRATA_COMMIT=$commit"', text)
+
+ def test_the_packager_reads_the_same_name(self):
+ self.assertIn("STRATA_BUILD_COMMIT", (ROOT / "packaging" / "package_terminal.py").read_text(encoding="utf-8"))
+ self.assertTrue(re.fullmatch(r"[0-9a-f]{40}", SHA))
+
+
+if __name__ == "__main__":
+ unittest.main()