feat(docker): bake claude+codex CLI + auth into image, non-root user
Dockerfile additions:
- Node 20 (NodeSource repo) + @anthropic-ai/claude-code@2.1.141 via npm.
- codex 0.130.0 musl tarball from github releases, dropped into
/usr/local/bin/codex.
- jq + xz-utils + gnupg apt packages.
- Symlink /usr/games/stockfish → /usr/local/bin/stockfish (Debian
puts it under /usr/games which isn't on the default PATH).
- Non-root user 'chess' (uid 1000) because claude-code refuses to run
with --dangerously-skip-permissions as root; HOME=/home/chess.
- Pre-seeded /home/chess/.claude/settings.json + /home/chess/.claude.json:
- hasCompletedOnboarding=true / lastOnboardingVersion='2.1.141'
- projects['/app'].hasTrustDialogAccepted=true (mirrors the user's
claude-trust-current-dir helper, but baked since cwd is always /app)
- permissions.defaultMode='bypassPermissions'
- skipDangerousModePermissionPrompt=true
Without these, every fresh tmux pane hangs on the theme picker, then
the workspace-trust dialog, never reaching its first MCP call.
docker-compose.yml:
- ANTHROPIC_BASE_URL + ANTHROPIC_AUTH_TOKEN env (loaded from /opt/chessai/.env).
- ./secrets/codex mounted read-only at /home/chess/.codex so the user's
cliproxyapi-flavored codex config + auth.json travel with the deploy
but stay outside the image layers.
deploy/codex/config.toml:
- Minimal codex config (cliproxyapi provider, gpt-5.5 xhigh fast,
chess MCP url placeholder overridden per-side by pane-agent.sh).
scripts/pane-agent.sh:
- Use CLAUDE_BIN / CODEX_BIN from PATH (mac vs linux dynamics);
the inline -c mcp_servers.chess.url override removes the need for
'codex mcp add/remove' that polluted ~/.codex/config.toml on Mac runs.
Verified end-to-end on chess.danosito.com: AI-vs-AI game starts,
claude (white) inside the container makes the first move with a
toxic russian comment, MCP HTTP roundtrip works.
This commit is contained in:
+73
-1
@@ -6,15 +6,42 @@ ENV PYTHONDONTWRITEBYTECODE=1 \
|
|||||||
PIP_DISABLE_PIP_VERSION_CHECK=1
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||||
|
|
||||||
# Runtime deps: stockfish for eval, tmux for the agent panes, curl for the
|
# Runtime deps: stockfish for eval, tmux for the agent panes, curl for the
|
||||||
# in-container vendor fetch step.
|
# in-container vendor fetch step, jq for pane-agent.sh JSON parse,
|
||||||
|
# node+npm for the claude-code CLI.
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
stockfish \
|
stockfish \
|
||||||
tmux \
|
tmux \
|
||||||
curl \
|
curl \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
procps \
|
procps \
|
||||||
|
jq \
|
||||||
|
xz-utils \
|
||||||
|
gnupg \
|
||||||
|
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
|
||||||
|
&& apt-get install -y --no-install-recommends nodejs \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# claude-code CLI — install globally via npm. The version pin keeps the
|
||||||
|
# image deterministic; bump as needed.
|
||||||
|
RUN npm install -g --omit=dev @anthropic-ai/claude-code@2.1.141 \
|
||||||
|
&& claude --version
|
||||||
|
|
||||||
|
# codex CLI — official linux release tarball. The musl static binary
|
||||||
|
# works on Debian.
|
||||||
|
ARG CODEX_VERSION=0.130.0
|
||||||
|
RUN curl -fsSL "https://github.com/openai/codex/releases/download/rust-v${CODEX_VERSION}/codex-x86_64-unknown-linux-musl.tar.gz" \
|
||||||
|
-o /tmp/codex.tar.gz \
|
||||||
|
&& mkdir -p /tmp/codex && tar -xzf /tmp/codex.tar.gz -C /tmp/codex --strip-components=0 \
|
||||||
|
&& find /tmp/codex -type f -name 'codex-*' -exec mv {} /usr/local/bin/codex \; \
|
||||||
|
&& chmod +x /usr/local/bin/codex \
|
||||||
|
&& rm -rf /tmp/codex /tmp/codex.tar.gz \
|
||||||
|
&& codex --version
|
||||||
|
|
||||||
|
# Debian's stockfish package installs to /usr/games/stockfish which is not
|
||||||
|
# on the default PATH for non-login shells. Symlink it so `which stockfish`
|
||||||
|
# works for both the Python wrapper and any spawn from tmux panes.
|
||||||
|
RUN ln -s /usr/games/stockfish /usr/local/bin/stockfish && stockfish --help >/dev/null 2>&1 || true
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy everything first — pip install -e needs src/ai_chess to exist at
|
# Copy everything first — pip install -e needs src/ai_chess to exist at
|
||||||
@@ -35,5 +62,50 @@ RUN chmod +x scripts/*.sh && ./scripts/fetch-vendor.sh
|
|||||||
# Runtime artefacts (games/, logs/, config/) — keep as named mountable dirs.
|
# Runtime artefacts (games/, logs/, config/) — keep as named mountable dirs.
|
||||||
RUN mkdir -p games logs config
|
RUN mkdir -p games logs config
|
||||||
|
|
||||||
|
# claude-code refuses to run with --dangerously-skip-permissions as root,
|
||||||
|
# so the container's main process drops to a non-root user. Codex is also
|
||||||
|
# fine here. The user's HOME (=/home/chess) is where ~/.codex lives, so
|
||||||
|
# the docker-compose volume mounts target /home/chess/.codex.
|
||||||
|
RUN useradd -m -u 1000 -s /bin/bash chess && chown -R chess:chess /app
|
||||||
|
|
||||||
|
# Pre-seed claude-code state so its first-run onboarding (theme picker,
|
||||||
|
# changelog popup, etc.) is skipped — the flag lives in ~/.claude.json
|
||||||
|
# (a file in HOME, *not* the ~/.claude/ directory). Without this every
|
||||||
|
# fresh pane-agent.sh hangs at the theme prompt.
|
||||||
|
RUN mkdir -p /home/chess/.claude && \
|
||||||
|
cat > /home/chess/.claude/settings.json <<'EOF'
|
||||||
|
{
|
||||||
|
"theme": "light",
|
||||||
|
"permissions": { "allow": ["*"], "defaultMode": "bypassPermissions" },
|
||||||
|
"skipDangerousModePermissionPrompt": true
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
RUN cat > /home/chess/.claude.json <<'EOF'
|
||||||
|
{
|
||||||
|
"hasCompletedOnboarding": true,
|
||||||
|
"lastOnboardingVersion": "2.1.141",
|
||||||
|
"numStartups": 1,
|
||||||
|
"autoUpdates": false,
|
||||||
|
"officialMarketplaceAutoInstallAttempted": true,
|
||||||
|
"officialMarketplaceAutoInstalled": false,
|
||||||
|
"migrationVersion": 13,
|
||||||
|
"opusProMigrationComplete": true,
|
||||||
|
"sonnet1m45MigrationComplete": true,
|
||||||
|
"projects": {
|
||||||
|
"/app": {
|
||||||
|
"hasTrustDialogAccepted": true,
|
||||||
|
"hasClaudeMdExternalIncludesApproved": true,
|
||||||
|
"hasClaudeMdExternalIncludesWarningShown": true,
|
||||||
|
"projectOnboardingSeenCount": 1,
|
||||||
|
"allowedTools": ["*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
RUN chown -R chess:chess /home/chess
|
||||||
|
USER chess
|
||||||
|
WORKDIR /app
|
||||||
|
ENV HOME=/home/chess
|
||||||
|
|
||||||
EXPOSE 7833
|
EXPOSE 7833
|
||||||
CMD ["python", "-m", "ai_chess"]
|
CMD ["python", "-m", "ai_chess"]
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Minimal codex config for the ai-chess container.
|
||||||
|
# Uses the user's cliproxyapi gateway; the chess MCP server lives next door
|
||||||
|
# (uvicorn on 127.0.0.1:7833 inside the same container) and is overridden
|
||||||
|
# per-side via -c at launch time by scripts/pane-agent.sh.
|
||||||
|
|
||||||
|
model = "gpt-5.5"
|
||||||
|
model_provider = "cliproxyapi"
|
||||||
|
model_reasoning_effort = "xhigh"
|
||||||
|
approval_policy = "never"
|
||||||
|
sandbox_mode = "danger-full-access"
|
||||||
|
service_tier = "fast"
|
||||||
|
|
||||||
|
[model_providers.cliproxyapi]
|
||||||
|
name = "cliproxyapi"
|
||||||
|
base_url = "https://cli.machka.dev/v1"
|
||||||
|
wire_api = "responses"
|
||||||
|
|
||||||
|
[mcp_servers.chess]
|
||||||
|
url = "http://127.0.0.1:7833/mcp/black"
|
||||||
|
|
||||||
|
[notice]
|
||||||
|
hide_full_access_warning = true
|
||||||
+8
-1
@@ -7,16 +7,23 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
AI_CHESS_HOST: "0.0.0.0" # listen on all interfaces inside the container
|
AI_CHESS_HOST: "0.0.0.0" # listen on all interfaces inside the container
|
||||||
AI_CHESS_PORT: "7833"
|
AI_CHESS_PORT: "7833"
|
||||||
|
# claude-code auth — talks to user's machka gateway, no Anthropic
|
||||||
|
# subscription needed at runtime.
|
||||||
|
ANTHROPIC_BASE_URL: "${ANTHROPIC_BASE_URL:-https://claude.machka.dev}"
|
||||||
|
ANTHROPIC_AUTH_TOKEN: "${ANTHROPIC_AUTH_TOKEN}"
|
||||||
networks:
|
networks:
|
||||||
default:
|
default:
|
||||||
caddy-network:
|
caddy-network:
|
||||||
aliases:
|
aliases:
|
||||||
- chessai
|
- chessai
|
||||||
# Persistent runtime data — survives container rebuilds.
|
|
||||||
volumes:
|
volumes:
|
||||||
|
# Persistent runtime data — survives container rebuilds.
|
||||||
- ./games:/app/games
|
- ./games:/app/games
|
||||||
- ./logs:/app/logs
|
- ./logs:/app/logs
|
||||||
- ./config:/app/config
|
- ./config:/app/config
|
||||||
|
# codex config + auth lives in /opt/chessai/secrets/codex on the host
|
||||||
|
# and is mapped into the container's $CODEX_HOME (= ~/.codex by default).
|
||||||
|
- ./secrets/codex:/home/chess/.codex:ro
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
caddy-network:
|
caddy-network:
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ fi
|
|||||||
|
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
|
|
||||||
|
: "${CLAUDE_BIN:=$(command -v claude || echo /usr/local/bin/claude)}"
|
||||||
|
: "${CODEX_BIN:=$(command -v codex || echo /usr/local/bin/codex)}"
|
||||||
|
|
||||||
case "$agent" in
|
case "$agent" in
|
||||||
claude)
|
claude)
|
||||||
cat > "$CFG/claude-settings.${side}.json" <<EOF
|
cat > "$CFG/claude-settings.${side}.json" <<EOF
|
||||||
@@ -68,7 +71,7 @@ EOF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
exec /Users/dan/.local/bin/claude \
|
exec "$CLAUDE_BIN" \
|
||||||
--model opus \
|
--model opus \
|
||||||
--effort max \
|
--effort max \
|
||||||
--mcp-config "$CFG/claude-mcp.${side}.json" \
|
--mcp-config "$CFG/claude-mcp.${side}.json" \
|
||||||
@@ -78,17 +81,15 @@ EOF
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
codex)
|
codex)
|
||||||
# Register MCP HTTP server in ~/.codex/config.toml (idempotent).
|
# Override the global config's chess MCP url (each side talks to its own
|
||||||
# Clean up on exit so we don't leave the user's config polluted.
|
# path). The user's persistent ~/.codex/config.toml does NOT get
|
||||||
/opt/homebrew/bin/codex mcp remove chess >/dev/null 2>&1 || true
|
# rewritten — we just pass an inline override.
|
||||||
/opt/homebrew/bin/codex mcp add chess --url "http://127.0.0.1:7833/mcp/${side}"
|
exec "$CODEX_BIN" \
|
||||||
trap '/opt/homebrew/bin/codex mcp remove chess >/dev/null 2>&1 || true' EXIT
|
|
||||||
|
|
||||||
exec /opt/homebrew/bin/codex \
|
|
||||||
-c 'model="gpt-5.5"' \
|
-c 'model="gpt-5.5"' \
|
||||||
-c 'model_reasoning_effort="xhigh"' \
|
-c 'model_reasoning_effort="xhigh"' \
|
||||||
-c 'service_tier="fast"' \
|
-c 'service_tier="fast"' \
|
||||||
-c "tui.theme=\"${codex_theme}\"" \
|
-c "tui.theme=\"${codex_theme}\"" \
|
||||||
|
-c "mcp_servers.chess.url=\"http://127.0.0.1:7833/mcp/${side}\"" \
|
||||||
--dangerously-bypass-approvals-and-sandbox
|
--dangerously-bypass-approvals-and-sandbox
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user