Merge branch 'feat/pin-component'
This commit is contained in:
commit
d06612cb2f
1 file changed
+77
-9
+77
-9
@@ -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()
|
||||
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 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, "valuesFiles": vfiles, "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,46 @@ if not CHART_ONLY:
|
||||
else:
|
||||
print("[promote] CHART_ONLY=true:image-version.yaml 不动")
|
||||
|
||||
# ── 1.5) 系统组件:逐 values 文件精确替换该镜像的 tag ──
|
||||
# 兼容两种 values 形态:A. image: <registry>/<imageName>:<tag>(整行)
|
||||
# B. repository: <registry>/<imageName> + 相邻 tag: <tag>(拆分)
|
||||
# 该客户没有的文件(目录结构差异)跳过并记录;全部未命中才报错。
|
||||
for c in components:
|
||||
pat_a = re.compile("(" + re.escape(c["imageName"]) + r"):([A-Za-z0-9][\w.\-]*)")
|
||||
pat_b = re.compile(r"^(\s*tag:\s*)(\S+)\s*$")
|
||||
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
|
||||
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).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).strip("\"'"), j
|
||||
lines[j] = mb.group(1) + c["acrTag"] + "\n"
|
||||
break
|
||||
if hit_idx is not None:
|
||||
break
|
||||
if hit_idx is not None:
|
||||
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 共用服务→文件映射)
|
||||
chart_from, chart_to = {}, {}
|
||||
@@ -635,8 +695,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, "")
|
||||
|
||||
Reference in new issue
Block a user