Files
foundry-core/deploy/codex-worker.sh
T

43 lines
2.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 远程私有 worker 启动器;使用与 Core 同一二进制的 codex-worker 模式,CLI 和登录目录由运维预先提供。
set -euo pipefail
# 参数一是已经构建好的 Go 程序;realpath 把挂载源固定为绝对路径,Docker 不会替这里编译源码。
base=/opt/endoleap-infra
dir=$base/foundry/codex
binary=$(realpath "$1")
# 启动前检查可执行文件、专用 CLI 登录和项目授权表;本脚本不执行登录流程,也不生成授权令牌。
test -x "$binary"
test -s "$dir/home/auth.json"
test -s "$dir/grants/projects.json"
# socket 目录归容器 uid 1000,socket 本身由服务设为 0600;不公布宿主 TCP 端口。
install -d -m 700 "$dir/run"
chown 1000:1000 "$dir/run"
# 可选目录声明已验证图片输出后端;没有此名单时不根据图片输入能力推测图片生成能力。
canvas_env=()
if [[ -s "$dir/canvas.env" ]]; then canvas_env=(--env-file "$dir/canvas.env"); fi
# The host operator supplies an isolated Codex home and starts a single worker.
# The Docker default bridge supplies egress independently of Foundry's network.
# 单 worker 使用独立 bridge 出网,根文件系统只读;临时任务写 /tmp,登录目录需允许 CLI 自身状态更新。
# CLI/二进制只读挂载,Core 只看到 socket,不共享本登录目录。
# 容器参数分工:--init 负责子进程收尾,资源上限限制进程数/内存,cap-drop 与 no-new-privileges 收紧权限。
# /tmp 可写用于临时任务,/work 只读且设为工作目录;没有 -p,因此不向宿主发布 worker 的 TCP 端口。
# 挂载中 /opt/foundry 是 Go worker,/opt/codex 是预装 Node CLI;执行 CLI 才是这里需要 Node 环境的原因。
# 最后一行的 codex-worker 参数选中 main.go 的 worker 分支,而不是启动普通 Foundry HTTP API。
docker run -d --name foundry-codex-worker --restart unless-stopped --init \
--network bridge --user 1000:1000 --cap-drop ALL --security-opt no-new-privileges \
--read-only --pids-limit 128 --memory 1g --tmpfs /tmp:rw,nosuid,nodev \
--tmpfs /work:ro,nosuid,nodev --workdir /work \
--mount "type=bind,source=$binary,target=/opt/foundry,readonly" \
--mount "type=bind,source=$base/codex-cli,target=/opt/codex,readonly" \
--mount "type=bind,source=$dir/home,target=/home/node/.codex" \
--mount "type=bind,source=$dir/run,target=/run/foundry-codex" \
--mount "type=bind,source=/etc/ssl/certs/ca-certificates.crt,target=/etc/ssl/certs/ca-certificates.crt,readonly" \
"${canvas_env[@]}" \
node:24-bookworm-slim /opt/foundry codex-worker