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 错配只登记不擅动。
This commit is contained in:
zhangxiang committed 2026-10-22 18:55:55 +08:00
1 parent 03be1c9e36
commit becb9407bd
55 files changed
+1657 -2

No files matched your search

+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env python3
"""睿新致遠 / NOVALON · Gitea 品牌资产校验(必须用 /usr/bin/python3,本机只有它有 Pillow)
三道校验,缺一不可:
1. 正向:逐个回读输出文件(PNG 解头验宽高与 alpha 占用、SVG 解析验结构与色值)。
2. 反向自证:明知违规的样本必须被判红。判不红 ⇒ 校验是空的,本次一律算失败。
3. 清单自证:允许清单里的文件若在盘上消失,报红(防止「少产出」被读成「通过」)。
退出码分档:0 全绿 / 1 预期红(打印红因)/ 2 脚本自身崩溃 —— 别让闸崩了和判红共用一个码。
"""
import os
import re
import struct
import subprocess
import sys
import tempfile
import xml.etree.ElementTree as ET
try:
from PIL import Image
except Exception as e: # 解释器选错会伪装成「依赖缺失」
print("FATAL: import PIL 失败(请用 /usr/bin/python3 运行): %s" % e)
sys.exit(2)
INK, RED, WHITE, PAPER = "#26221E", "#C41E3A", "#FFFFFF", "#F7F4EF"
ALLOWED_FILLS = {RED, WHITE, INK, PAPER, "none"}
# 目标清单:期望尺寸来自现网上游同名资产的实测值
EXPECT = {
"logo.svg": ("svg", None),
"favicon.svg": ("svg", None),
"favicon.png": ("png", (32, 32)),
"apple-touch-icon.png": ("png", (180, 180)),
"avatar_default.png": ("png", (200, 200)),
"logo.png": ("png", (512, 512)),
"novalon-lockup-light.svg": ("svg", None),
"novalon-lockup-dark.svg": ("svg", None),
}
STRIP_COMMENT = re.compile(r"<!--.*?-->", re.S)
FILL_RE = re.compile(r'fill="(#[0-9A-Fa-f]{3,8}|none)"')
def check_svg(path):
bad = []
raw = open(path, encoding="utf-8").read()
try:
root = ET.fromstring(STRIP_COMMENT.sub("", raw))
except ET.ParseError as e:
return ["XML 解析失败: %s" % e]
if not root.tag.endswith("svg"):
bad.append("根标签不是 svg: %s" % root.tag)
if "viewBox" not in root.attrib:
bad.append("缺 viewBox(Gitea 图标槽按 img 尺寸缩放,无 viewBox 会糊)")
body = STRIP_COMMENT.sub("", raw)
if "<text" in body:
bad.append("含 <text>:栅格化依赖字体,16px 档实测不可读")
if "http" in body.replace("http://www.w3.org/2000/svg", ""):
bad.append("含外部 http 引用(项目规则禁止外部字体/资源 CDN)")
fills = set(FILL_RE.findall(body))
off = fills - ALLOWED_FILLS
if off:
bad.append("色值越界: %s(允许 %s)" % (sorted(off), sorted(ALLOWED_FILLS)))
if body.count("<path") < 1:
bad.append("path 数为 0:图形主体缺失")
return bad
def check_png(path, size):
bad = []
try:
im = Image.open(path)
im.load()
except Exception as e:
return ["PNG 无法解读: %s" % e]
if im.size != tuple(size):
bad.append("尺寸 %dx%d ≠ 期望 %dx%d" % (im.size[0], im.size[1], size[0], size[1]))
if im.mode not in ("RGBA", "LA", "RGB", "P"):
bad.append("色彩模式异常: %s" % im.mode)
# 非空校验:全透明/全单色的输出说明栅格化根本没吃到图形
rgba = im.convert("RGBA")
px = list(rgba.getdata())
opaque = sum(1 for p in px if p[3] > 0)
if opaque == 0:
bad.append("全透明:图形未栅格化")
elif opaque * 1.0 / len(px) < 0.005:
bad.append("不透明像素占比 %.3f%% 过低,疑似空图" % (opaque * 100.0 / len(px)))
distinct = {p[:3] for p in px if p[3] > 0}
if len(distinct) < 2:
bad.append("可见色只有 %d 种,疑似丢字形" % len(distinct))
# 回读 PNG 头,确认宽高与 PIL 口径一致(两把尺子对不上就是仪器坏了)
with open(path, "rb") as f:
head = f.read(24)
if head[:8] != b"\x89PNG\r\n\x1a\n":
bad.append("PNG 签名不符")
else:
w, h = struct.unpack(">II", head[16:24])
if (w, h) != im.size:
bad.append("PNG 头 %dx%d 与解图 %dx%d 不一致" % (w, h, im.size[0], im.size[1]))
return bad
def validate(directory, expect=EXPECT):
reds = []
for name, (kind, size) in expect.items():
p = os.path.join(directory, name)
if not os.path.exists(p):
reds.append("%s 缺失" % name)
continue
if os.path.getsize(p) == 0:
reds.append("%s 为 0 字节" % name)
continue
errs = check_svg(p) if kind == "svg" else check_png(p, size)
reds.extend("%s: %s" % (name, e) for e in errs)
return reds
def negative_selftest():
"""反向自证:三类明知违规的样本,必须全部被抓。返回未被抓的项。"""
misses = []
with tempfile.TemporaryDirectory() as d:
# ① SVG 含 <text> + 外部引用
p1 = os.path.join(d, "logo.svg")
open(p1, "w").write('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
'<text x="0" y="10">睿</text>'
'<image href="https://fonts.gstatic.com/x.woff2"/></svg>')
if not any("<text" in e or "http" in e for e in check_svg(p1)):
misses.append("SVG 含 <text>/外链 未被判红")
# ② SVG 缺 viewBox + 色值越界
p2 = os.path.join(d, "favicon.svg")
open(p2, "w").write('<svg xmlns="http://www.w3.org/2000/svg">'
'<path fill="#FF0000" d="M0 0h1v1z"/></svg>')
if not any(("viewBox" in e) or ("色值越界" in e) for e in check_svg(p2)):
misses.append("SVG 缺 viewBox/越界色 未被判红")
# ③ PNG 尺寸不符(造一张 12x13)
p3 = os.path.join(d, "logo.png")
Image.new("RGBA", (12, 13), (196, 30, 58, 255)).save(p3)
if not any("尺寸" in e for e in check_png(p3, (512, 512))):
misses.append("PNG 尺寸不符未被判红")
# ④ 清单里声明的文件不在盘上,也必须判红(防止「少产出=通过」)
if not any("缺失" in e for e in validate(d, {"nope.png": ("png", (1, 1))})):
misses.append("文件缺失未被判红")
return misses
def main():
if len(sys.argv) != 2:
print("用法: /usr/bin/python3 check-assets.py <img 目录>")
return 2
target = sys.argv[1]
if not os.path.isdir(target):
print("RED: 目录不存在 %s" % target)
return 1
reds = validate(target)
misses = negative_selftest()
for line in sorted(os.listdir(target)):
p = os.path.join(target, line)
print(" %-24s %8d B" % (line, os.path.getsize(p)))
if misses:
print("\n反向自证失败(校验本身是空的):")
for m in misses:
print(" ✗ %s" % m)
if reds:
print("\n判红 %d 项:" % len(reds))
for r in reds:
print(" ✗ %s" % r)
if misses or reds:
return 1
print("\n全绿:%d 个资产回读通过,反向自证 4/4 全部被抓" % len(EXPECT))
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except Exception:
import traceback
traceback.print_exc()
sys.exit(2)