Container image: releases only, a token by default, lean layers; every action pinned
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.
This commit is contained in:
parent
9c8cda44c1
commit
98735eb769
16 changed files with 367 additions and 110 deletions
|
|
@ -1,42 +1,55 @@
|
|||
#!/usr/bin/env bash
|
||||
set -u
|
||||
# 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
|
||||
|
||||
# MCP_MODE picks what runs: browser (default) serves the game page and relays the
|
||||
# player's tab to the MCP server; headless runs a game of its own, no page needed.
|
||||
mode=${MCP_MODE:-browser}
|
||||
case "$mode" in
|
||||
browser|headless) ;;
|
||||
*) echo "[entrypoint] MCP_MODE must be browser or headless, not '$mode'" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# Everything after the image name is passed to the MCP server as well
|
||||
# (node scripts/mcp.js --help lists the options).
|
||||
extra=("$@")
|
||||
has() { local a; for a in "${extra[@]}"; do [ "$a" = "$1" ] && return 0; done; return 1; }
|
||||
|
||||
# A container needs 0.0.0.0 to be reachable at all; default --http unless given.
|
||||
# A container must listen beyond loopback to be reachable at all; --http in the arguments overrides it.
|
||||
http=(--http 0.0.0.0:7777)
|
||||
for a in "${extra[@]}"; do [ "$a" = --http ] && http=(); done
|
||||
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
|
||||
wait "${pids[@]}" 2>/dev/null
|
||||
exit 0
|
||||
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 npm run dev -- --host 0.0.0.0 --port 8080
|
||||
start npm run mcp -- --browser "${http[@]}" "${extra[@]}"
|
||||
start node scripts/dev.js --host 0.0.0.0 --port 8080
|
||||
start node scripts/mcp.js --browser "${http[@]}" "${extra[@]}"
|
||||
else
|
||||
start npm run mcp -- "${http[@]}" "${extra[@]}"
|
||||
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 process exited with status $status; stopping the container" >&2
|
||||
shutdown
|
||||
echo "[entrypoint] a server exited with status $status; stopping the container" >&2
|
||||
shutdown "$status"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue