Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Unreleased
volume, own checkouts over the baked trees. It is copied into the
image.

• scripts/docker/spear bounds the container's memory and processes
and tells the harness so. Without it the terminal of a session
started from that launcher refused every command.

• In an image, Claude Code starts from what a SPEAR request starts
from: beside the rules and skills, the learned rules, the corpus's
map and the project's build and test commands are laid out as rule
Expand Down
9 changes: 9 additions & 0 deletions client/tests/test_reds_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,15 @@ def test_the_image_gives_a_prompt_of_the_other_assistant_what_a_turn_gets(self):
self.assertIn("spear-claude-setup", (REPO / "docker" / "claude-launcher").read_text())
self.assertIn("spear-claude-setup", (REPO / "docker" / "spear-shell").read_text())

def test_the_container_is_bounded_and_the_harness_told(self):
"""The harness refuses a command nothing bounds; the limits and the
word that they exist are on the same docker run."""
run = self.SCRIPT.read_text().split("exec docker run", 1)[1]

for flag in ('--memory "$MEMORY"', "--pids-limit",
"-e SPEAR_RESOURCE_CONTROL=delegated"):
self.assertIn(flag, run)

def test_the_image_carries_it(self):
dockerfile = (REPO / "docker" / "Dockerfile").read_text()

Expand Down
8 changes: 8 additions & 0 deletions doc/source/start/container_run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ container reaches it through an SSH tunnel you open on your machine.
--security-opt seccomp=unconfined \
--security-opt apparmor=unconfined \
--security-opt systempaths=unconfined \
--memory 16g --memory-swap 16g --pids-limit 4096 \
-e SPEAR_RESOURCE_CONTROL=delegated \
--network host \
--user "$(id -u):$(id -g)" \
-e SPEAR_API_BASE=http://127.0.0.1:8082/v1 \
Expand All @@ -127,6 +129,12 @@ container reaches it through an SSH tunnel you open on your machine.
-w /corpora/opencn/opencn-ng \
ghcr.io/smartobjectoriented/spear-reds:<version>-reds --ask

The limits and ``SPEAR_RESOURCE_CONTROL=delegated`` go together: the
harness refuses to run a command that nothing bounds, and in a container
Docker is what bounds it (:ref:`resource_control`). The launcher gives
the container three quarters of the machine's memory;
``SPEAR_CONTAINER_MEMORY`` in the configuration file names another bound.

The paths under ``/corpora`` are those of the building machine, relative to
its home: ``opencn/opencn-ng`` (and ``opencn/opencn-ng/linux/usr``),
``soo/so3/so3``, ``soo/so3/doc``, ``sye/sye_sol``,
Expand Down
11 changes: 11 additions & 0 deletions scripts/docker/spear
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,23 @@ TTY=(-i); [ -t 0 ] && TTY=(-i -t)

NAME="spear-$(printf '%s' "${WORKDIR##*/}" | tr -c 'A-Za-z0-9_.-' '-')-$$"

# The harness bounds what each command may take, and refuses to run one when
# nothing does. A container has no systemd to do it per command, so Docker
# bounds the container and the harness is told so: the limits and the variable
# go together. They hold your own builds too, hence most of the machine;
# SPEAR_CONTAINER_MEMORY in the configuration file names another bound.

MEMORY="${SPEAR_CONTAINER_MEMORY:-$(awk '/^MemTotal:/ { printf "%dm", $2 * 3 / 4 / 1024 }' /proc/meminfo)}"

# The three --security-opt are what bubblewrap, the harness's sandbox, needs
# to start inside a container; without them it refuses every command.

exec docker run --rm --name "$NAME" "${TTY[@]}" \
--security-opt seccomp=unconfined \
--security-opt apparmor=unconfined \
--security-opt systempaths=unconfined \
--memory "$MEMORY" --memory-swap "$MEMORY" --pids-limit 4096 \
-e SPEAR_RESOURCE_CONTROL=delegated \
--network host \
--user "$(id -u):$(id -g)" \
"${BACKEND[@]}" \
Expand Down
Loading