docs: annotate Foundry source and deployment lifecycle in Chinese [skip ci]
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# 由 main 部署工作流在远程基础设施主机执行,参数一必须是已构建的 Foundry 二进制。
|
||||
# 本脚本会迁移数据库、替换 worker 并启动候选服务,不能当作本地静态检查执行。
|
||||
set -euo pipefail
|
||||
umask 077
|
||||
|
||||
@@ -8,6 +10,7 @@ origin=https://api.foundry.entroia.com
|
||||
candidate=foundry-core-candidate
|
||||
network=endoleap-dev_default
|
||||
|
||||
# 必需凭据仅从环境传入,拒绝换行以保持容器环境参数边界,日志不打印值。
|
||||
for name in GOOGLE_CLIENT_ID GOOGLE_CLIENT_SECRET; do
|
||||
value=${!name-}
|
||||
if [[ -z "$value" || "$value" == *$'\n'* || "$value" == *$'\r'* ]]; then
|
||||
@@ -16,6 +19,7 @@ for name in GOOGLE_CLIENT_ID GOOGLE_CLIENT_SECRET; do
|
||||
fi
|
||||
done
|
||||
# Accept formatted JSON from Actions Variables and never print its contents.
|
||||
# 将 Actions 中可多行排版的 JSON 压为单行;这里只校验映射形状,URL 协议由服务启动继续验证。
|
||||
FOUNDRY_PROJECTS=$(python3 - <<'PYCONFIG'
|
||||
import json
|
||||
import os
|
||||
@@ -44,11 +48,14 @@ test -s "$foundry/database.env"
|
||||
ca_bundle=/etc/ssl/certs/ca-certificates.crt
|
||||
test -s "$ca_bundle"
|
||||
docker network inspect "$network" >/dev/null
|
||||
# 先运行全事务迁移及角色授权,迁移失败立即终止,不让新服务在半升级 schema 上启动。
|
||||
python3 "$(dirname "$0")/migrate.py"
|
||||
|
||||
# 每次发布使用独立二进制目录供只读挂载;本脚本不清除旧 release 目录。
|
||||
release=$(mktemp -d "$foundry/release.XXXXXXXX")
|
||||
install -m 755 "$1" "$release/foundry"
|
||||
export HOST=0.0.0.0 PORT=8080 PUBLIC_ORIGIN="$origin"
|
||||
# 邮件/研究配置可选且从受保护文件加载;Slack 优先 Actions 环境,缺省才回退服务器文件。
|
||||
mail_env=()
|
||||
if [[ -s "$foundry/mail.env" ]]; then
|
||||
mail_env=(--env-file "$foundry/mail.env")
|
||||
@@ -73,6 +80,7 @@ elif [[ -s "$foundry/slack.env" ]]; then
|
||||
fi
|
||||
codex_mounts=()
|
||||
codex_dir=$foundry/codex
|
||||
# 存在 worker 配置才启用 IPC;worker 必须先与当前 Core 二进制协议对齐,启动失败恢复旧 worker。
|
||||
if [[ -d "$codex_dir" ]]; then
|
||||
# Core and its private worker must speak the same Canvas artifact protocol.
|
||||
# Keep the previous container definition for exact startup rollback.
|
||||
@@ -107,6 +115,7 @@ if [[ -d "$codex_dir" ]]; then
|
||||
printf 'Canvas worker startup/catalog verification failed; previous worker restored.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
# 目录探测成功后删除旧 worker 定义;后续候选/路由失败不会再恢复该 worker,回滚范围需据此理解。
|
||||
if [[ -n "$worker_backup" ]]; then docker rm "$worker_backup" >/dev/null; fi
|
||||
for attempt in {1..20}; do
|
||||
[[ ! -S "$codex_dir/run/worker.sock" ]] || break
|
||||
@@ -122,6 +131,7 @@ if [[ -d "$codex_dir" ]]; then
|
||||
)
|
||||
fi
|
||||
|
||||
# Core 只挂载 IPC/授权表,不挂载 CLI 登录;以非 root、只读根文件系统和裁剪能力运行。
|
||||
docker run -d --name "$candidate" "${codex_mounts[@]}" "${mail_env[@]}" "${slack_env[@]}" "${research_env[@]}" --network "$network" \
|
||||
--env-file "$foundry/database.env" -e HOST -e PORT -e PUBLIC_ORIGIN \
|
||||
-e GOOGLE_CLIENT_ID -e GOOGLE_CLIENT_SECRET -e FOUNDRY_PROJECTS -e FOUNDRY_ONBOARDING \
|
||||
@@ -132,11 +142,13 @@ docker run -d --name "$candidate" "${codex_mounts[@]}" "${mail_env[@]}" "${slack
|
||||
--mount "type=bind,source=$release/foundry,target=/opt/foundry,readonly" \
|
||||
node:24-bookworm-slim /opt/foundry >/dev/null
|
||||
|
||||
# 候选或路由失败时删除本次新 Core;旧 Core 由 route 成功探测后才停止。
|
||||
cleanup_candidate() {
|
||||
docker rm -f "${live:-$candidate}" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup_candidate EXIT
|
||||
|
||||
# 容器内 smoke 只验证 CA 文件、数据库就绪及匿名请求被拒,不执行真实 OAuth 或付费模型。
|
||||
docker exec "$candidate" node -e '
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs");
|
||||
@@ -166,6 +178,7 @@ docker exec "$candidate" node -e '
|
||||
|
||||
# Keep the previous running container until the new candidate has passed checks.
|
||||
# Traefik reads the route atomically from its watched config directory.
|
||||
# 使用容器 ID 前缀命名新 live,route.sh 负责原子路由写入、外部就绪检查和失败恢复路由。
|
||||
id=$(docker inspect -f '{{.Id}}' "$candidate")
|
||||
live=foundry-core-${id:0:12}
|
||||
docker rename "$candidate" "$live"
|
||||
|
||||
Reference in New Issue
Block a user