SHA256
按 deploy/ci-cd.md 方案把除推送触发之外的东西都准备好:
- customization/check.sh <base-url>: 把 preview.sh check 里的"定制生效"断言抽成
任意实例可跑的脚本(首页/页脚/meta/官网链接/登录页两张卡/无通行密钥方框/
无「工单」/无 example.com), 另加生产才有的 OIDC 入口 307 断言(404 = 认证源没注册上)。
实测对生产 17/17 通过。
- deploy/scripts/auto-deploy.sh: build.py -> compose up -d -> verify.sh + check.sh,
失败自动回滚到 deploy/.state/last-deployed; flock 串行; 结束时把 clone 所有权还给
ymy(job 容器里是 root); 内网验证强制不走代理。
- deploy/runner/{compose.yaml,config.yaml,.env.example}: act_runner v0.6.1 跑在容器里
(不需要 root), network: host + 同路径挂载部署克隆 + 宿主 docker CLI/compose 插件,
capacity 1 保证部署串行。
- .gitea/workflows/deploy.yml: push main + workflow_dispatch, [skip deploy] 跳过,
concurrency 串行, 只做"同步到 github.sha + 调 auto-deploy.sh"。
- .gitignore: deploy/.state/、deploy/runner/{.env,data/}。
依据见 deploy/ci-cd.md(含全部实测证据与待确认项)。
This commit is contained in:
@@ -188,7 +188,15 @@ def main() -> int:
|
||||
return 0
|
||||
|
||||
OUT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
OUT_PATH.write_text(rendered, encoding="utf-8")
|
||||
try:
|
||||
OUT_PATH.write_text(rendered, encoding="utf-8")
|
||||
except PermissionError as exc:
|
||||
raise SystemExit(
|
||||
f"写入失败: {exc}\n"
|
||||
f" 多半是 docker 以 root 创建过这个挂载源目录(bind mount 的源目录不存在时它会这么做),\n"
|
||||
f" 普通用户就写不进去了。删掉再重试: sudo rm -rf {OUT_PATH.parent}\n"
|
||||
f" (仓库里 customization/custom/options/.gitkeep 就是为防止这种情况而存在的)"
|
||||
) from exc
|
||||
print(f"✓ 已生成 {OUT_PATH}")
|
||||
fixed = ensure_readable(CUSTOM_DIR)
|
||||
if fixed:
|
||||
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/env bash
|
||||
# 定制生效断言 —— 对任意实例跑一遍, 预览与生产共用。
|
||||
# 用法:
|
||||
# customization/check.sh http://127.0.0.1:2081 # 预览
|
||||
# customization/check.sh https://cpp.tongji.sh/QA # 生产(CI 里也调这个)
|
||||
#
|
||||
# 退出码: 0 全通过 / 1 有断言失败 / 2 用法错误。
|
||||
# 只读: 只发 GET, 不改任何东西。
|
||||
set -uo pipefail
|
||||
|
||||
BASE_URL="${1:-}"
|
||||
if [[ -z ${BASE_URL} ]]; then
|
||||
sed -n '2,9p' "$0"
|
||||
exit 2
|
||||
fi
|
||||
BASE_URL="${BASE_URL%/}"
|
||||
ORIGIN="$(printf '%s' "${BASE_URL}" | sed -E 's#(^https?://[^/]+).*#\1#')"
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
fail=0
|
||||
ok() { printf ' ✓ %s\n' "$1"; }
|
||||
bad() {
|
||||
printf ' ✗ %s\n' "$1"
|
||||
fail=1
|
||||
}
|
||||
skip() { printf ' – %s\n' "$1"; }
|
||||
|
||||
tmp="$(mktemp -d)"
|
||||
trap 'rm -rf "${tmp}"' EXIT
|
||||
# --noproxy: 验证目标都在内网, 走代理只会把 200 变成 502(见 deploy/README.md 陷阱 5)
|
||||
curl_() { curl -sS --noproxy '*' --max-time 20 "$@"; }
|
||||
|
||||
echo "== 定制检查 ${BASE_URL} =="
|
||||
|
||||
# --- 首页 -------------------------------------------------------------------
|
||||
if ! curl_ -fsS -H 'Accept-Language: zh-CN' "${BASE_URL}/" -o "${tmp}/home.html"; then
|
||||
echo " ✗ 首页打不开(HTTP 非 2xx), 后面不再检查"
|
||||
exit 1
|
||||
fi
|
||||
ok "首页可访问"
|
||||
|
||||
grep -q "先搜索,再提问" "${tmp}/home.html" &&
|
||||
ok "首页用的是定制模板 home.tmpl" || bad "首页没有定制模板的内容"
|
||||
grep -q "assets/tjhlp/ask-guide.html" "${tmp}/home.html" &&
|
||||
ok "导航栏/首页已指向课程提问指南" || bad "没找到提问指南链接"
|
||||
! grep -q "painless\|极易搭建\|Easy to install\|Cross-platform" "${tmp}/home.html" &&
|
||||
ok "首页已无 Gitea 功能介绍" || bad "首页仍有 Gitea 功能介绍文案"
|
||||
! grep -qi "powered by" "${tmp}/home.html" &&
|
||||
ok "页脚已无 Powered by Gitea" || bad "页脚仍有 Powered by"
|
||||
! grep -q "docs.gitea.com" "${tmp}/home.html" &&
|
||||
ok "页面已无 docs.gitea.com 外链" || bad "仍有 docs.gitea.com 外链"
|
||||
grep -q 'name="description" content="同济大学高级语言程序设计课程答疑平台"' "${tmp}/home.html" &&
|
||||
ok "meta description 已替换" || bad "meta description 未替换"
|
||||
|
||||
# --- 与课程官网的联动 -------------------------------------------------------
|
||||
grep -q "https://cpp.tongji.sh/Website/" "${tmp}/home.html" &&
|
||||
ok "首页/导航栏已链接课程官网" || bad "首页没有课程官网链接"
|
||||
grep -q "https://cpp.tongji.sh/Website/ask-question/" "${tmp}/home.html" &&
|
||||
ok "首页已链接官网《学会提问》" || bad "首页没有《学会提问》链接"
|
||||
if curl_ -fsS -o "${tmp}/guide.html" "${BASE_URL}/assets/tjhlp/ask-guide.html"; then
|
||||
ok "custom/public 静态页可访问"
|
||||
grep -q "Website/ask-question/" "${tmp}/guide.html" &&
|
||||
ok "站内提问指南已回链官网" || bad "站内提问指南没有官网链接"
|
||||
else
|
||||
bad "提问指南静态页 404"
|
||||
fi
|
||||
|
||||
# --- 中文术语与登录页 -------------------------------------------------------
|
||||
if curl_ -fsS -H 'Accept-Language: zh-CN' "${BASE_URL}/user/login" -o "${tmp}/login.html"; then
|
||||
ok "登录页可访问"
|
||||
grep -q "管理员登录" "${tmp}/login.html" &&
|
||||
ok "登录页有独立的「管理员登录」卡片" || bad "登录页缺少管理员登录卡片"
|
||||
! grep -q "webauthn-error\|signin-passkey" "${tmp}/login.html" &&
|
||||
ok "登录页已无空的通行密钥(WebAuthn)方框" || bad "登录页仍有通行密钥区块"
|
||||
# OIDC 入口: 配了认证源的实例才会渲染 external-login-navigator
|
||||
if grep -q 'id="external-login-navigator"' "${tmp}/login.html"; then
|
||||
href="$(grep -o 'href="[^"]*/user/oauth2/[^"]*"' "${tmp}/login.html" | head -1 |
|
||||
sed -E 's/^href="//; s/"$//')"
|
||||
if [[ -z ${href} ]]; then
|
||||
bad "登录页有认证源区块但没解析出 OAuth2 链接"
|
||||
else
|
||||
code="$(curl_ -o /dev/null -w '%{http_code}' "${ORIGIN}${href}")"
|
||||
# 307 = 认证源注册成功并跳转统一身份认证; 404 = 认证源没注册上(见 README 陷阱 6)
|
||||
[[ ${code} == 307 ]] &&
|
||||
ok "OIDC 入口 ${href} 返回 307(跳转统一身份认证)" ||
|
||||
bad "OIDC 入口返回 ${code}, 期望 307(404 = 认证源没注册上)"
|
||||
fi
|
||||
else
|
||||
skip "该实例未配置认证源, 跳过 OIDC 入口检查(预览实例属此情况)"
|
||||
fi
|
||||
else
|
||||
bad "登录页打不开"
|
||||
fi
|
||||
|
||||
# 术语: 中文界面里不该再出现「工单」
|
||||
if curl_ -fsS -H 'Accept-Language: zh-CN' -o "${tmp}/issues.html" \
|
||||
"${BASE_URL}/course-team/tjhlp-gitea/issues"; then
|
||||
! grep -q "工单" "${tmp}/issues.html" &&
|
||||
ok "Issue 列表页中文界面已无「工单」" || bad "Issue 列表页仍有「工单」"
|
||||
else
|
||||
skip "读不到 issue 列表页(需要登录?), 跳过「工单」检查"
|
||||
fi
|
||||
|
||||
# --- 仓库内文件(在 checkout 里跑时才有意义) --------------------------------
|
||||
if [[ -d ${ROOT}/issue-templates ]]; then
|
||||
! grep -rq "example.com" "${ROOT}/issue-templates/" &&
|
||||
ok "Issue 模板已无 example.com 占位链接" || bad "Issue 模板里仍有 example.com"
|
||||
fi
|
||||
if [[ -f ${ROOT}/custom/options/locale/locale_zh-CN.json ]]; then
|
||||
! grep -q "工单" "${ROOT}/custom/options/locale/locale_zh-CN.json" &&
|
||||
ok "生成的 zh-CN 语言文件已无「工单」" || bad "语言文件里仍有「工单」"
|
||||
fi
|
||||
|
||||
if [[ ${fail} == 0 ]]; then
|
||||
echo "全部检查通过"
|
||||
else
|
||||
echo "存在检查未通过项"
|
||||
fi
|
||||
exit "${fail}"
|
||||
@@ -0,0 +1,15 @@
|
||||
# 这个文件唯一的用途: 让 git 跟踪住这个空目录。
|
||||
#
|
||||
# customization/custom/ 下的三个子目录会被逐个 bind mount 进容器:
|
||||
# custom/options -> /data/gitea/options
|
||||
# custom/public -> /data/gitea/public
|
||||
# custom/templates-> /data/gitea/templates
|
||||
# 如果 options/ 在全新克隆里不存在(它下面只放生成出来的 locale_zh-CN.json, 而那个文件
|
||||
# 是 gitignore 的), 那么 docker compose 会【以 root 创建】这个挂载源目录 —— 之后
|
||||
# 普通用户跑 customization/build.py 就写不进去:
|
||||
# PermissionError: [Errno 13] Permission denied: .../custom/options/locale
|
||||
# 于是语言文件永远生成不出来, 中文界面退回上游文案(「工单」又回来了)。
|
||||
# 2026-09-13 第一次把生产切到部署克隆时真实踩到。
|
||||
#
|
||||
# 有了这个占位文件, 目录随 checkout 就存在且属于当前用户, 问题从结构上消失。
|
||||
# 真正有内容的是 custom/templates 与 custom/public, 它们不需要占位。
|
||||
Reference in New Issue
Block a user