From defe711ce69df08f064cab322b4274d190995741 Mon Sep 17 00:00:00 2001 From: ximenchuifeng Date: Tue, 8 Sep 2026 13:13:29 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(ci):=20promote.sh=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=BB=84=E4=BB=B6=E6=9D=A1=E7=9B=AE=E2=80=94?= =?UTF-8?q?=E2=80=94=E7=AC=AC=E4=B8=89=E6=96=B9=E9=95=9C=E5=83=8F(postgres?= =?UTF-8?q?/redis/mqttx=20=E7=AD=89)=E9=9A=8F=20PLAN=20=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=20values=20=E9=87=8C=E7=9A=84=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PLAN 组件条目:{"component":true,"name":..,"acrTag":..,"valuesFile":..,"imageName":..} - 登记制:映射随 PLAN 动态携带,流水线零改动即可认识新组件 - pin 精确替换客户 values 文件里该镜像的 tag,兼容整行(image: ...:tag) 与拆分(repository:+相邻 tag:)两种 values 形态 - 组件也算正式发布:分配版本号+chart bump;release-notes 如实记 from→to - CHART_ONLY 与组件互斥(防御) 本地 PROMOTE_DRY_RUN 双形态演练通过(mqttx latest→v2.0.0 拆分态、 redis 8.6→8.7 整行态,mxlexus) --- ci/promote.sh | 79 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/ci/promote.sh b/ci/promote.sh index 7d922f5..cc91c43 100755 --- a/ci/promote.sh +++ b/ci/promote.sh @@ -208,8 +208,8 @@ if raw_plan: if not isinstance(plan, list): die('PLAN 应为 JSON 数组,每服务一条 {"service":..., "action":...}') for i, e in enumerate(plan): - if not isinstance(e, dict) or "service" not in e: - die(f"PLAN[{i}] 应为对象且含 service 字段") + if not isinstance(e, dict) or ("service" not in e and not e.get("component")): + die(f"PLAN[{i}] 应为对象且含 service 字段(或 component 组件条目)") entries.append(dict(e)) else: selected = {} @@ -235,9 +235,23 @@ else: # 全部缺省 = 6 服务全 deliver demo 当前 tag(行为与改造前一致) entries = [{"service": s, "action": "deliver"} for s in ALL] -# ── 2. 校验 + 规范化为全量 6 服务计划 ── +# ── 2. 校验 + 规范化(六服务计划 + 组件条目)── norm, seen = {}, set() +component_entries = [] for e in entries: + if e.get("component"): + name = str(e.get("name") or "").strip() + tag = str(e.get("acrTag") or "").strip() + vfile = str(e.get("valuesFile") or "").strip() + iname = str(e.get("imageName") or "").strip() + if not (name and tag and vfile and iname): + die(f"组件条目缺字段(name/acrTag/valuesFile/imageName): {e}") + if name in seen: + die(f"条目名重复: {name}") + seen.add(name) + component_entries.append({"component": True, "name": name, "action": "pin-acr", + "acrTag": tag, "valuesFile": vfile, "imageName": iname}) + continue svc = e.get("service") if svc not in ALL: die(f"非法服务名: {svc}(合法值: {', '.join(ALL)})") @@ -266,12 +280,12 @@ for e in entries: norm[svc] = n plan_out = [norm.get(s) or {"service": s, "action": "keep", "repos": REPOS[s], "keys": KEYS[s], "appFile": APPFILE[s]} - for s in ALL] + for s in ALL] + component_entries has_deliver = any(e["action"] in ("deliver", "ci-now", "pin-acr") for e in plan_out) # ── 3. DB_CHANGE 校验:逗号分隔服务名,须为本次非 keep 服务的子集 ── db_change = [s.strip() for s in (os.environ.get("DB_CHANGE") or "").split(",") if s.strip()] -nonkeep = {e["service"] for e in plan_out if e["action"] != "keep"} +nonkeep = {e["service"] for e in plan_out if e["action"] != "keep" and not e.get("component")} for s in db_change: if s not in ALL: die(f"DB_CHANGE 含非法服务名: {s}(合法值: {', '.join(ALL)})") @@ -338,7 +352,9 @@ open(plantxt_path, "w", encoding="utf-8").write(raw_plan or json.dumps(plan_out, for e in plan_out: if e["action"] == "keep": continue - print(f"[promote] 计划: {e['service']:<8} {e['action']:<8} {e.get('harborTag') or e.get('version') or e.get('acrTag') or ''}") + svc_label = e.get("service") or e.get("name") or "" + extra = "(组件)" if e.get("component") else "" + print(f"[promote] 计划: {svc_label:<10} {e['action']:<8} {extra}{e.get('harborTag') or e.get('version') or e.get('acrTag') or ''}") print(f"[promote] DB 变更服务: {', '.join(db_change) or '无'}") PY . "$FACTS_FILE" # HAS_DELIVER=true|false @@ -501,6 +517,9 @@ do_pin() { git fetch -q origin release || die "release 分支不存在,请先推送初始 release 分支(改造清单 B1)" git checkout -q -B release origin/release + if [ "$CHART_ONLY" = "true" ] && [ -s "$PLAN_FILE" ] && grep -q '"component": *true' "$PLAN_FILE"; then + die "CHART_ONLY 与组件条目互斥(仅 chart 发布不动任何镜像)" + fi ENVDIR="environments/$CUSTOMER" APPDIR="applications/$CUSTOMER" @@ -525,7 +544,8 @@ NOTES = os.environ.get("RELEASE_NOTES", "") DB_CHANGE = [s for s in os.environ.get("DB_CHANGE", "").split(",") if s] plan = json.load(open(plan_path, encoding="utf-8")) -actions = [e for e in plan if e["action"] != "keep"] +actions = [e for e in plan if e["action"] != "keep" and not e.get("component")] +components = [e for e in plan if e.get("component")] has_deliver = any(e["action"] in ("deliver", "ci-now") for e in plan) # 平台 Application(infra/mqttx)不属于 PLAN 服务映射,跟随每次新 chart tag @@ -576,6 +596,39 @@ if not CHART_ONLY: else: print("[promote] CHART_ONLY=true:image-version.yaml 不动") +# ── 1.5) 系统组件:精确替换 values 文件里该镜像的 tag ── +# 兼容两种 values 形态:A. image: /:(整行) +# B. repository: / + 相邻 tag: (拆分) +for c in components: + vpath = os.path.join(envdir, c["valuesFile"]) + if not os.path.exists(vpath): + sys.exit(f"[promote] 错误: 缺少组件 values 文件 {vpath}") + lines = open(vpath, encoding="utf-8").readlines() + old_tag, hit_idx, hit_kind = None, None, None + pat_a = re.compile("(" + re.escape(c["imageName"]) + r"):([A-Za-z0-9][\w.\-]*)") + pat_b = re.compile(r"^(\s*tag:\s*)(\S+)\s*$") + for idx, line in enumerate(lines): + if c["imageName"] not in line: + continue + m = pat_a.search(line) + if m: # 形态 A:同行 + old_tag, hit_idx, hit_kind = m.group(2), idx, "A" + lines[idx] = pat_a.sub(lambda _m: _m.group(1) + ":" + c["acrTag"], line) + break + for j in range(idx + 1, min(idx + 4, len(lines))): # 形态 B:邻近 tag: 字段 + mb = pat_b.match(lines[j]) + if mb: + old_tag, hit_idx, hit_kind = mb.group(2), j, "B" + lines[j] = mb.group(1) + c["acrTag"] + "\n" + break + if hit_idx is not None: + break + if hit_idx is None: + sys.exit(f"[promote] 错误: {vpath} 中未找到镜像 {c['imageName']} 的 tag 引用(整行或拆分形态)") + open(vpath, "w", encoding="utf-8").write("".join(lines)) + from_tags[c["name"]], to_tags[c["name"]] = old_tag, c["acrTag"] + print(f"[promote] 组件 {c['name']}: {c['imageName']} {old_tag} → {c['acrTag']}({c['valuesFile']},{hit_kind})") + # ── 2) applications chart targetRevision:只处理非 keep 服务对应的文件 ── # (语义等价于按文件 sed,用 python 实现以便与 PLAN 共用服务→文件映射) chart_from, chart_to = {}, {} @@ -635,8 +688,16 @@ def find_reuse_source(svc, version): return "", "" svc_entries, src_tags = [], {} -for e in actions: - svc, action = e["service"], e["action"] +for e in actions + components: + svc, action = e.get("service") or e.get("name"), e["action"] + if e.get("component"): + # 组件:替换 values 文件里的镜像 tag(已做),chart 无关,如实记账 + frm, to = from_tags.get(svc, ""), to_tags.get(svc, "") + src_tags[svc] = e.get("acrTag", "") + svc_entries.append({"name": svc, "action": action, "from": frm, "to": to, + "sourceTag": e.get("acrTag", ""), "digest": "", + "dbChange": False, "component": True}) + continue if CHART_ONLY: # CHART_ONLY 条目:from/to 记 chart tag 变化,sourceTag/digest 留空 frm, to = chart_from.get(svc, ""), chart_to.get(svc, "") From 86b4aa0b279bf10fd62154e093803cae4b81b166 Mon Sep 17 00:00:00 2001 From: ximenchuifeng Date: Tue, 8 Sep 2026 13:32:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(ci):=20=E7=BB=84=E4=BB=B6=E6=9D=A1?= =?UTF-8?q?=E7=9B=AE=20valuesFiles=20=E5=A4=9A=E6=96=87=E4=BB=B6=E2=80=94?= =?UTF-8?q?=E2=80=94=E4=B8=80=E4=B8=AA=E9=95=9C=E5=83=8F=E6=95=A3=E5=9C=A8?= =?UTF-8?q?=E5=A4=9A=E4=B8=AA=20values=20=E6=97=B6=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E5=85=A8=E6=9B=BF=E6=8D=A2(=E5=A6=82=20postgres=20=E5=9C=A8=20?= =?UTF-8?q?4=20=E4=B8=AA=E6=96=87=E4=BB=B6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 逐文件替换,客户目录没有的文件跳过并记录,全部未命中才 fail; from 汇总各文件旧值(多数相同,不同则如实并列)。 --- ci/promote.sh | 63 ++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/ci/promote.sh b/ci/promote.sh index cc91c43..b2dc06d 100755 --- a/ci/promote.sh +++ b/ci/promote.sh @@ -242,15 +242,15 @@ for e in entries: if e.get("component"): name = str(e.get("name") or "").strip() tag = str(e.get("acrTag") or "").strip() - vfile = str(e.get("valuesFile") or "").strip() + vfiles = [str(x).strip() for x in (e.get("valuesFiles") or []) if str(x).strip()] iname = str(e.get("imageName") or "").strip() - if not (name and tag and vfile and iname): - die(f"组件条目缺字段(name/acrTag/valuesFile/imageName): {e}") + if not (name and tag and vfiles and iname): + die(f"组件条目缺字段(name/acrTag/valuesFiles/imageName): {e}") if name in seen: die(f"条目名重复: {name}") seen.add(name) component_entries.append({"component": True, "name": name, "action": "pin-acr", - "acrTag": tag, "valuesFile": vfile, "imageName": iname}) + "acrTag": tag, "valuesFiles": vfiles, "imageName": iname}) continue svc = e.get("service") if svc not in ALL: @@ -596,38 +596,45 @@ if not CHART_ONLY: else: print("[promote] CHART_ONLY=true:image-version.yaml 不动") -# ── 1.5) 系统组件:精确替换 values 文件里该镜像的 tag ── +# ── 1.5) 系统组件:逐 values 文件精确替换该镜像的 tag ── # 兼容两种 values 形态:A. image: /:(整行) # B. repository: / + 相邻 tag: (拆分) +# 该客户没有的文件(目录结构差异)跳过并记录;全部未命中才报错。 for c in components: - vpath = os.path.join(envdir, c["valuesFile"]) - if not os.path.exists(vpath): - sys.exit(f"[promote] 错误: 缺少组件 values 文件 {vpath}") - lines = open(vpath, encoding="utf-8").readlines() - old_tag, hit_idx, hit_kind = None, None, None pat_a = re.compile("(" + re.escape(c["imageName"]) + r"):([A-Za-z0-9][\w.\-]*)") pat_b = re.compile(r"^(\s*tag:\s*)(\S+)\s*$") - for idx, line in enumerate(lines): - if c["imageName"] not in line: + hits = [] # (文件, 旧tag) + for vf in c["valuesFiles"]: + vpath = os.path.join(envdir, vf) + if not os.path.exists(vpath): + print(f"[promote] 组件 {c['name']}: {vf} 在客户目录不存在,跳过") continue - m = pat_a.search(line) - if m: # 形态 A:同行 - old_tag, hit_idx, hit_kind = m.group(2), idx, "A" - lines[idx] = pat_a.sub(lambda _m: _m.group(1) + ":" + c["acrTag"], line) - break - for j in range(idx + 1, min(idx + 4, len(lines))): # 形态 B:邻近 tag: 字段 - mb = pat_b.match(lines[j]) - if mb: - old_tag, hit_idx, hit_kind = mb.group(2), j, "B" - lines[j] = mb.group(1) + c["acrTag"] + "\n" + lines = open(vpath, encoding="utf-8").readlines() + old_tag, hit_idx = None, None + for idx, line in enumerate(lines): + if c["imageName"] not in line: + continue + m = pat_a.search(line) + if m: # 形态 A:同行 + old_tag, hit_idx = m.group(2), idx + lines[idx] = pat_a.sub(lambda _m: _m.group(1) + ":" + c["acrTag"], line) + break + for j in range(idx + 1, min(idx + 4, len(lines))): # 形态 B:邻近 tag: 字段 + mb = pat_b.match(lines[j]) + if mb: + old_tag, hit_idx = mb.group(2), j + lines[j] = mb.group(1) + c["acrTag"] + "\n" + break + if hit_idx is not None: break if hit_idx is not None: - break - if hit_idx is None: - sys.exit(f"[promote] 错误: {vpath} 中未找到镜像 {c['imageName']} 的 tag 引用(整行或拆分形态)") - open(vpath, "w", encoding="utf-8").write("".join(lines)) - from_tags[c["name"]], to_tags[c["name"]] = old_tag, c["acrTag"] - print(f"[promote] 组件 {c['name']}: {c['imageName']} {old_tag} → {c['acrTag']}({c['valuesFile']},{hit_kind})") + open(vpath, "w", encoding="utf-8").write("".join(lines)) + hits.append((vf, old_tag)) + print(f"[promote] 组件 {c['name']}: {vf} {c['imageName']} {old_tag} → {c['acrTag']}") + if not hits: + sys.exit(f"[promote] 错误: 组件 {c['name']}({c['imageName']})在 {', '.join(c['valuesFiles'])} 中均未找到引用") + from_tags[c["name"]] = " / ".join(t for _, t in hits) + to_tags[c["name"]] = c["acrTag"] # ── 2) applications chart targetRevision:只处理非 keep 服务对应的文件 ── # (语义等价于按文件 sed,用 python 实现以便与 PLAN 共用服务→文件映射) From 1e4ff720d13a267aa55885e52f3f4686d2a6bf34 Mon Sep 17 00:00:00 2001 From: ximenchuifeng Date: Tue, 8 Sep 2026 13:35:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(ci):=20=E7=BB=84=E4=BB=B6=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E7=9A=84=E6=97=A7=20tag=20=E5=89=A5=E5=BC=95=E5=8F=B7?= =?UTF-8?q?(=E5=B8=A6=E5=BC=95=E5=8F=B7=E5=86=99=E6=B3=95=E5=A6=82?= =?UTF-8?q?=E5=AE=9E=E5=85=A5=E8=B4=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci/promote.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/promote.sh b/ci/promote.sh index b2dc06d..47395da 100755 --- a/ci/promote.sh +++ b/ci/promote.sh @@ -616,13 +616,13 @@ for c in components: continue m = pat_a.search(line) if m: # 形态 A:同行 - old_tag, hit_idx = m.group(2), idx + old_tag, hit_idx = m.group(2).strip("\"'"), idx lines[idx] = pat_a.sub(lambda _m: _m.group(1) + ":" + c["acrTag"], line) break for j in range(idx + 1, min(idx + 4, len(lines))): # 形态 B:邻近 tag: 字段 mb = pat_b.match(lines[j]) if mb: - old_tag, hit_idx = mb.group(2), j + old_tag, hit_idx = mb.group(2).strip("\"'"), j lines[j] = mb.group(1) + c["acrTag"] + "\n" break if hit_idx is not None: