Files
novalon-website/infra/cicd/gitea-custom/patch-compose.py
T
zhangxiang becb9407bd feat(gitea): 升 28.2.0 并把品牌装饰层纳管为可重跑的仓库真源
自建 Gitea 此前是出厂外观(茶杯标 + 「Gitea: Git with a cup of tea」标题),而品牌「纯字标 + 朱砂条」已在官网落地;同时现网 1.27.2
  落后两个安全版本 —— 1.27.3 的 fix(git): restrict hook permissions 打的正是本实例 8 月被入侵所用的 packObjectsHook
  向量。装饰基准取自升级后从容器抽出的真实模板,不凭记忆手写。

- 升级 28.2.0:pg_dump 后还原到一次性探针库对账(116 表 / 20 仓库 / 8 用户全等),停服 8s;28.0.0 的 git egress BREAKING
  按裁定收为 EGRESS_MODE=strict(实测 app.ini 无旧 ALLOWED_* 键、mirror 仓库 0 个 ⇒ 空白名单不伤业务)。

- 装饰层真源入库 infra/cicd/gitea-custom/(结构即实测 CustomPath=/data/gitea):页头/OG/默认头像换简标与刻版、novalon-
  brand.css 覆盖 --color-primary 全色阶、custom/header.tmpl 外链注入、signin_inner.tmpl
  登录页加字标锁定(220×103)。

- 色阶由脚本生成并自带夹具:先对上游 14 档对账(light/dark 两档 ramp 命名互为反向,手敲必错),再喂上游蓝做反向自证,双双通过才写盘。

- 深档按钮改「黑字朱底」:Gitea 用同一令牌既当按钮底色又当链接文字色,AA 区间为空(按钮白字 L≤0.1833 vs 链接 on #1e1f20 L≥0.2362)⇒ #E13C58
  × #0D0D0D 实测 4.62:1;深档链接 3.92:1 作为已登记让步保留(上游蓝同位 4.14,本就不达标)。

- deploy/verify 带预检、备份、内容 sha256 比对、负对照与 0/1/2/3 退出码分档,核心判红自动回滚(首轮就靠它把「标题未生效」与「装饰未生效」区分开)。

- 纠正两处生产口径失真:仓库那份「加固版」compose 从未上线(真实文件纳管为 infra/cicd/gitea/docker-compose.live.yml);生产
  REQUIRE_SIGNIN_VIEW 实为 false,且 compose 的 DISABLE_REGISTRATION=false 会经 environment-to-ini
  在重建时静默打开注册 —— 已对齐为 true。遗留的匿名浏览面与 SSH_PORT 错配只登记不擅动。
2026-10-22 18:55:55 +08:00

68 lines
2.2 KiB
Python
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 python3
"""幂等地把品牌相关配置项写进生产 docker-compose.yml 的 environment 段。
为什么单独成文件而不是内联在 ssh 里:内联要穿过「本地 bash → ssh → 远端 sh → python」四层引号,
而 python 正则里的 `$'` 会被本地 bash 当 ANSI-C 引用吃掉 —— 这类静默改写在生产脚本里不可接受。
用法: patch-compose.py <DESCRIPTION> <KEYWORDS>
在 compose 所在目录内运行(就地改 docker-compose.yml)。
输出:PATCHED / UNCHANGED / NO_ANCHOR(NO_ANCHOR 时不改文件,退出码 3)
"""
import re
import sys
WANT_KEYS = ["GITEA__ui.meta__DESCRIPTION",
"GITEA__ui.meta__KEYWORDS"]
# APP_NAME 不在这里:Gitea 读的是 app.ini 顶层 DEFAULT 段,env 这条路到不了(见 patch-app-ini.py 文件头)
ANCHOR_RE = re.compile(r"^([ \t]*)- GITEA__security__INSTALL_LOCK=.*$")
FILE = "docker-compose.yml"
def main():
if len(sys.argv) != 3:
print("用法: patch-compose.py <DESCRIPTION> <KEYWORDS>")
return 2
want = dict(zip(WANT_KEYS, sys.argv[1:3]))
try:
src = open(FILE, encoding="utf-8").read()
except OSError as e:
print("READ_FAIL %s" % e)
return 2
lines = src.split("\n")
ind = None
anchor_idx = None
for i, line in enumerate(lines):
m = ANCHOR_RE.match(line)
if m:
ind, anchor_idx = m.group(1), i
break
if anchor_idx is None:
print("NO_ANCHOR")
return 3
out = list(lines)
# 从锚点往下逐个键:已存在则原地替换,不存在则紧跟锚点插入(保持同一缩进块内)
pos = anchor_idx + 1
for key in WANT_KEYS:
pat = re.compile(r"^[ \t]*- %s=.*$" % re.escape(key))
hit = next((i for i, l in enumerate(out) if pat.match(l)), None)
line = "%s- %s=%s" % (ind, key, want[key])
if hit is not None:
out[hit] = line
else:
out.insert(pos, line)
pos += 1
new = "\n".join(out)
if new == src:
print("UNCHANGED")
return 0
open(FILE, "w", encoding="utf-8").write(new)
print("PATCHED")
return 0
if __name__ == "__main__":
sys.exit(main())