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 共用服务→文件映射)