The image is published to GHCR as the release's version when a release dispatches docker.yml, and never as latest or per commit. Pushes and pull requests that touch it build it and try headless (with and without a token) and browser mode, without publishing. The image: node:24-slim pinned by digest (the major CI tests on), npm ci from the lockfile in its own layer, only src, site, scripts and the harness copied in (an allow-list .dockerignore), root-owned and run as node, /saves ready for --save-dir. The entrypoint runs the servers with node directly and, with no SOT_MCP_TOKEN, makes a token for the run and prints it (MCP_NO_TOKEN=1 to opt out); the docs publish ports to 127.0.0.1 and explain --allow-host. Labels, SBOM and provenance on push. Every GitHub Action in every workflow is pinned to a commit SHA with its version, and Dependabot keeps the actions, the image's base and the npm tools current. tests/docker.test.js guards all of it. The ADR and the github-pages skill say the image is a tool: GHCR only, never Pages.
55 lines
2.3 KiB
Bash
55 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Starts the container's servers (docker/Dockerfile, docs/MCP.md "In a container").
|
|
# MCP_MODE=browser (default): the development server on :8080, with the relay a player's tab dials, and the MCP server
|
|
# on :7777 driving that tab.
|
|
# MCP_MODE=headless: only the MCP server, with a game of its own.
|
|
# Everything after the image name goes to scripts/mcp.js (node scripts/mcp.js --help lists the options).
|
|
set -uo pipefail
|
|
cd /series-of-tubes
|
|
|
|
mode=${MCP_MODE:-browser}
|
|
case "$mode" in
|
|
browser|headless) ;;
|
|
*) echo "[entrypoint] MCP_MODE must be browser or headless, not '$mode'" >&2; exit 1 ;;
|
|
esac
|
|
|
|
extra=("$@")
|
|
has() { local a; for a in "${extra[@]}"; do [ "$a" = "$1" ] && return 0; done; return 1; }
|
|
|
|
# A container must listen beyond loopback to be reachable at all; --http in the arguments overrides it.
|
|
http=(--http 0.0.0.0:7777)
|
|
has --http && http=()
|
|
|
|
# Listening beyond loopback, the MCP server would take orders from anyone who reaches the port (its Host check stops
|
|
# browsers, not other clients), so it gets a token. None given (SOT_MCP_TOKEN or --token-file): this run makes one and
|
|
# prints it. MCP_NO_TOKEN=1 turns that off, for a port published to 127.0.0.1 only.
|
|
if [ -z "${SOT_MCP_TOKEN:-}" ] && ! has --token-file && [ "${MCP_NO_TOKEN:-}" != 1 ]; then
|
|
SOT_MCP_TOKEN=$(node -e "process.stdout.write(require('node:crypto').randomBytes(24).toString('base64url'))")
|
|
export SOT_MCP_TOKEN
|
|
echo "[entrypoint] No SOT_MCP_TOKEN given: this run's token is $SOT_MCP_TOKEN" >&2
|
|
echo "[entrypoint] claude mcp add --transport http seriesoftubes http://127.0.0.1:7777/mcp --header \"Authorization: Bearer $SOT_MCP_TOKEN\"" >&2
|
|
fi
|
|
|
|
pids=()
|
|
start() { "$@" & pids+=("$!"); }
|
|
shutdown() {
|
|
trap '' TERM INT
|
|
kill -TERM "${pids[@]}" 2>/dev/null || true
|
|
wait "${pids[@]}" 2>/dev/null || true
|
|
exit "${1:-0}"
|
|
}
|
|
trap shutdown TERM INT
|
|
|
|
# node directly, not npm run: one process less, and signals reach the server.
|
|
if [ "$mode" = browser ]; then
|
|
start node scripts/dev.js --host 0.0.0.0 --port 8080
|
|
start node scripts/mcp.js --browser "${http[@]}" "${extra[@]}"
|
|
else
|
|
start node scripts/mcp.js "${http[@]}" "${extra[@]}"
|
|
fi
|
|
|
|
# One server stopping stops the container, with its status, so a restart policy can bring both back.
|
|
status=0
|
|
wait -n || status=$?
|
|
echo "[entrypoint] a server exited with status $status; stopping the container" >&2
|
|
shutdown "$status"
|