#!/bin/sh # ============================================================================ # ci/promote.sh — 交付晋级脚本(release-promote 流水线的执行体)— ADR-0067 # 按服务计划(PLAN)部分交付,设计见 hub docs/adr/0074 # # 子命令(由 .drone.yml 的四个 step 分别调用;状态经 $WS 下的 .release-env / # .baseline / .digests / .plan.json 文件在 step 间传递,WS=${DRONE_WORKSPACE:-/drone/src}): # # prepare 解析 PLAN/RELEASE_VERSION/CUSTOMER,生成交付基线(.baseline)与规范化 # 计划(.plan.json),克隆 chart 仓库核对交付镜像清单 # retag 基线镜像 pull 119 → tag ACR:vX.Y.Z → push(bit 级复制,不重新构建), # 逐镜像记录 digest(.digests,供 release-notes 反向追踪) # chart chart 仓库 Chart.yaml bump + commit + tag chart-vX.Y.Z + push # (tag 已存在则复用跳过;纯复用发布整步跳过) # pin release 分支:按 PLAN 逐服务钉 image tag(image-version keys 与/或 # valuesFiles 里的 image.tag)与 chart targetRevision(appFile 非空时), # 追加 release-notes.yaml(最新在前),push # # 服务计划 PLAN(JSON 数组,每服务一条;未出现的服务 = keep): # [{"service":"sso","action":"deliver","harborTag":"develop-v.1.0.1-202608250629-41"}, # {"service":"agent","action":"reuse","version":"v1.0.1"}, # {"service":"ultra","action":"keep"}, # {"service":"wifi","action":"pin-acr","acrTag":"develop-v.1.0.1-202609080530-26", # "repos":["network-agent"],"keys":[],"appFile":"", # "valuesFiles":["network-agent-values.yaml"]}] # service: 任意服务名(六内置 + 带映射的自定义服务,见下) # action : keep(缺省,不动) # reuse(复用已交付版本 version,镜像已在 ACR 不重推) # deliver(harborTag 为未交付过的 Harbor tag,缺省取 demo 当前,retag 到新版本号) # ci-now(行为同 deliver,仅 release-notes 如实记录为 ci-now) # pin-acr(acrTag 为 ACR 上已有 tag,原样钉进客户目录,不搬运不 retag—— # 镜像搬运已剥离给门户「直推 ACR」;版本号即所选 tag 名, # chart 引用保持不变,ArgoCD 由 values 变更触发 sync) # 交付映射(PLAN 条目自带,带任一字段即整体信任,缺省字段视为空): # repos Harbor 镜像仓列表(retag/pin 的镜像来源;自带映射时必填) # keys environments/<客户>/image-version.yaml 的行名(空 = 不进版本表) # appFile applications/<客户>/ 下的 Application 文件(空 = 不随统一 chart, # 即独立 chart 服务,Application 引用其自有 chart 的 master) # valuesFiles environments/<客户>/ 下的 values 文件列表(钉版落点:替换其中 # image.tag;形态兼容 整行 registry/repo:tag / repository+tag 拆分 / # image: 块下 tag:) # 未带映射的条目回退 REPOS/KEYS/APPFILE 三张缺省字典(六内置服务); # 非 keep 动作必须能落点:keys 与 valuesFiles 至少一项非空。 # 组件条目(component:true + name/acrTag/valuesFiles/imageName):第三方镜像 # (postgres/redis 等)精确替换客户 values 里的 tag,只支持 pin-acr/keep。 # 兼容参数: SERVICES=sso,agent(=这些服务 deliver,其余 keep) # IMAGES=sso=tagX(=该服务 deliver 且显式 harborTag;逗号分隔多个) # PLAN 存在时优先;全部缺省 = 6 内置服务全 deliver demo 当前 tag(与改造前一致) # protocol mock 不进 PLAN,保留 PROMOTE_PROTOCOLS 独立开关 # # 版本号分配: # 有 deliver/ci-now/pin-acr(或 CHART_ONLY=true)→ 需要新版本号(RELEASE_VERSION 缺省 auto-bump); # chart tag 已存在不再拒绝,记 CHART_TAG_EXISTS=true 复用(幂等,可同参数重跑/同版本发多客户) # 全部 keep/reuse(纯复用发布)→ 不分配新版本号,chart 步骤跳过, # reuse 服务 chart targetRevision 各指已有 chart- # pin-acr 也算正式发布:分配新版本号并 bump chart(应用引用跟随),镜像钉所选 tag 名 # # 其他参数: # CHART_ONLY=true 只发 chart:prepare 跳过镜像基线与 Harbor 校验,retag 整步跳过, # pin 只动 chart targetRevision 与 release-notes # ASSIGN_VERSION 是否分配新版本号(缺省 true)。false = 纯钉版发布: # 不分配版本号、不 bump chart、不动平台 Application, # 只钉 values/image-version 与 release-notes;此时 PLAN 中 # 不得有 deliver/ci-now(镜像 retag 的目标名就是版本号,必须有号) # RELEASE_NOTES 发布说明,写入 release-notes.yaml 条目 # DB_CHANGE 逗号分隔服务名(须为本次非 keep 服务子集),条目 dbChange 标 true # (仅作 release-notes/commit 标记,提示运维本次含数据库变更; # 迁移脚本不由 CI 产出,运维自行生成并执行) # OPERATOR 发布操作人,默认 drone # PROMOTE_DRY_RUN=true 本地演练:docker 与 git push 仅打印不执行 # # 原则: # - 交付基线 = demo 正在跑且回归过的 develop tag 组合(只读 master,不改 master) # - 客户目录只允许本流水线写(release 分支受保护,ADR-0068) # - 全流程幂等:ACR 重推无害、chart tag 存在即复用、pin 幂等重写,失败可同参数重跑 # ============================================================================ set -eu WS="${DRONE_WORKSPACE:-/drone/src}" ENV_FILE="$WS/.release-env" BASELINE_FILE="$WS/.baseline" DIGESTS_FILE="$WS/.digests" PLAN_FILE="$WS/.plan.json" PLAN_TXT_FILE="$WS/.plan.txt" FACTS_FILE="$WS/.plan-facts" COMMIT_MSG_FILE="$WS/.commit-msg" CHART_DIR="$WS/.ci/chart" DEPLOY_REPO="${DEPLOY_REPO:-http://git.mixingx.local/trace/mixingx.deploy.git}" CHART_REPO="${CHART_REPO:-http://git.mixingx.local/trace/mixingx.hub.chart.git}" CHARTS_DIR="release-charts" HARBOR_HOST="${HARBOR_HOST:-192.168.1.119:8888}" DRY_RUN="${PROMOTE_DRY_RUN:-false}" log() { echo "[promote] $*"; } die() { echo "[promote] 错误: $*" >&2; exit 1; } # 任意字符串 → shell source 安全的单引号字面量(内部 ' 转义为 '\'' ) shq() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"; } # 外部副作用命令(推镜像/推 git)统一走这里:PROMOTE_DRY_RUN=true 时只打印 run() { if [ "$DRY_RUN" = "true" ]; then log "[dry-run] $*" else "$@" fi } git_setup() { git config --global url."http://git.mixingx.local/".insteadOf "git@git.mixingx.local:" 2>/dev/null || true # 身份必须 --global:chart 步骤在克隆出的 chart 仓里 commit(pin 在 deploy 仓), # 本地 config 只落在当前仓,克隆仓会因无 user.name/email 而 "unable to auto-detect email" git config --global user.name "Drone Release" git config --global user.email "drone-release@mixingx.local" } require_env() { [ -f "$ENV_FILE" ] || die "缺少 $ENV_FILE,请先运行 prepare 步骤" . "$ENV_FILE" [ -n "${CUSTOMER:-}" ] || die "$ENV_FILE 内容不完整(缺 CUSTOMER)" CHART_ONLY="${CHART_ONLY:-false}" PURE_REUSE="${PURE_REUSE:-false}" OPERATOR="${OPERATOR:-drone}" RELEASE_NOTES="${RELEASE_NOTES:-}" DB_CHANGE="${DB_CHANGE:-}" PLAN="${PLAN:-}" # 纯复用发布没有新版本号,RELEASE_VERSION/CHART_TAG 允许为空 if [ "$PURE_REUSE" != "true" ]; then [ -n "${RELEASE_VERSION:-}" ] && [ -n "${CHART_TAG:-}" ] \ || die "$ENV_FILE 内容不完整(缺 RELEASE_VERSION/CHART_TAG)" fi } # ───────────────────────────────────────────── # prepare # ───────────────────────────────────────────── do_prepare() { # 客户解析:客户目录在 release 分支上(工作区是 master,不含客户目录) # 唯一客户目录时可省略 CUSTOMER;多客户时不填即拒绝(防发错现场) git fetch -q origin release || die "release 分支不存在,请先推送初始 release 分支" CUSTOMERS=$(git ls-tree --name-only "origin/release" environments/ 2>/dev/null \ | sed 's#^environments/##' | sed 's#/$##' | grep -vE '^(_common|demo|dev)$' || true) C_COUNT=$(printf '%s\n' "$CUSTOMERS" | grep -c . || true) if [ -z "${CUSTOMER:-}" ]; then if [ "$C_COUNT" = "1" ]; then CUSTOMER="$CUSTOMERS" log "未指定 CUSTOMER,唯一客户目录: $CUSTOMER" else die "检测到 ${C_COUNT} 个客户目录,不填 CUSTOMER 无法确定发给谁。现有客户: $(printf '%s ' $CUSTOMERS)" fi fi printf '%s\n' "$CUSTOMERS" | grep -qx "$CUSTOMER" \ || die "environments/$CUSTOMER 不在 release 分支上。现有客户: $(printf '%s ' $CUSTOMERS)" CHART_ONLY="${CHART_ONLY:-false}" case "$CHART_ONLY" in true|false) : ;; *) die "CHART_ONLY 只接受 true/false,收到: $CHART_ONLY" ;; esac export CHART_ONLY # ── 解析服务计划(PLAN / 兼容参数 SERVICES、IMAGES / 缺省全量 deliver)── # 产物:.plan.json(规范化全量计划,pin 步骤消费)、.plan-facts(HAS_DELIVER)、 # .plan.txt(PLAN JSON 原文留痕)、.baseline(仅 deliver/ci-now 服务的 repo) python3 - "$WS/environments/demo/image-version.yaml" "$BASELINE_FILE" \ "$PLAN_FILE" "$FACTS_FILE" "$PLAN_TXT_FILE" <<'PY' import base64, json, os, re, sys, urllib.error, urllib.request import yaml demo_path, baseline_path, plan_path, facts_path, plantxt_path = sys.argv[1:6] CHART_ONLY = os.environ.get("CHART_ONLY", "false") == "true" WITH_PROTOCOLS = os.environ.get("PROMOTE_PROTOCOLS", "false") == "true" HARBOR_HOST = os.environ.get("HARBOR_HOST", "192.168.1.119:8888") # ── 交付映射:PLAN 条目自带映射优先(信任 + 格式校验),三张字典是未带时的缺省 ── # (pin 步骤经 .plan.json 继承每条目解析后的映射,勿另起副本) DEFAULT_SERVICES = ["gateway", "sso", "ultra", "audit", "agent", "edge"] ACTIONS = ["keep", "reuse", "deliver", "ci-now", "pin-acr"] # 缺省服务 → 镜像 repo 列表(前后端共用同一 tag) REPOS = { "gateway": ["gateway"], "sso": ["sso", "sso-web"], "ultra": ["ultra", "ultra-web"], "audit": ["audit", "audit-web"], "agent": ["agent", "agent-web"], "edge": ["edge", "edge-web"], } # 缺省服务 → image-version.yaml 中 images 下的 key 列表 KEYS = { "gateway": ["gateway"], "sso": ["sso", "ssoWeb"], "ultra": ["ultra", "ultraWeb"], "audit": ["audit", "auditWeb"], "agent": ["agent", "agentWeb"], "edge": ["edge", "edgeWeb"], } # 缺省服务 → applications/<客户>/ 下的 Application 文件 APPFILE = { "gateway": "gateway.yaml", "sso": "sso.yaml", "ultra": "ultra.yaml", "audit": "audit.yaml", "agent": "agents.yaml", "edge": "edges.yaml", } MAPPING_FIELDS = ("repos", "keys", "appFile", "valuesFiles") def norm_mapping(svc, e): """PLAN 条目映射:带任一映射字段 = 整体信任(缺省字段视为空,不与字典合并); 未带映射 = 三张缺省字典;字典也没有 = None(keep 可无映射,非 keep 拒绝)""" if not any(f in e for f in MAPPING_FIELDS): if svc in REPOS: return {"repos": REPOS[svc], "keys": KEYS[svc], "appFile": APPFILE[svc], "valuesFiles": []} return None def field_list(name, pat, what): raw = e.get(name) or [] if not isinstance(raw, list): die(f"服务 {svc} 的映射字段 {name} 应为列表") vals = [] for x in raw: v = str(x).strip() if v: if not re.fullmatch(pat, v): die(f"服务 {svc} 的映射字段 {name} 含非法值: {v}(应为{what})") vals.append(v) return vals m = { "repos": field_list("repos", r"[a-z0-9][a-z0-9._-]*", "镜像仓名"), "keys": field_list("keys", r"[A-Za-z0-9][A-Za-z0-9_-]*", "image-version 行名"), "appFile": "", "valuesFiles": field_list("valuesFiles", r"[\w.-]+\.ya?ml", "values 文件名"), } app = str(e.get("appFile") or "").strip() if app: if not re.fullmatch(r"[\w.-]+\.ya?ml", app): die(f"服务 {svc} 的映射字段 appFile 含非法值: {app}(应为文件名)") m["appFile"] = app if not m["repos"]: die(f"服务 {svc} 自带映射缺 repos(Harbor 镜像仓,retag/pin 的镜像来源)") return m def die(msg): sys.exit("[promote] 错误: " + msg) data = yaml.safe_load(open(demo_path, encoding="utf-8")) or {} images = data.get("images") or {} def demo_tag(svc, mapping): """deliver/ci-now 缺省 harborTag = demo 当前 tag(前后端应共用同一 tag)。 有 keys 从 image-version 取;无 keys(独立 chart 服务)从 demo 的首个 values 文件取""" if not mapping["keys"]: p = os.path.join(os.path.dirname(demo_path), mapping["valuesFiles"][0]) if os.path.exists(p): t = re.search(r"tag:\s*[\"']?([\w.\-]+)", open(p, encoding="utf-8").read()) if t: return t.group(1) die(f"服务 {svc} 缺省 harborTag 无法从 demo 的 {mapping['valuesFiles'][0]} 读取,请显式指定") tags = [] for k in mapping["keys"]: node = images.get(k) if not isinstance(node, dict) or not node.get("tag"): die(f"demo image-version 缺少 images.{k}.tag,无法取 {svc} 的 demo 当前 tag") tags.append(str(node["tag"])) if len(set(tags)) != 1: die(f"demo image-version 中 {svc} 前后端 tag 不一致({', '.join(tags)}),请显式指定 harborTag") return tags[0] # ── 1. 解析 PLAN / 兼容参数 / 缺省 ── raw_plan = (os.environ.get("PLAN") or "").strip() entries = [] if raw_plan: try: plan = json.loads(raw_plan) except json.JSONDecodeError as e: die(f"PLAN JSON 解析失败: {e}") 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 and not e.get("component")): die(f"PLAN[{i}] 应为对象且含 service 字段(或 component 组件条目)") entries.append(dict(e)) else: selected = {} for s in (os.environ.get("SERVICES") or "").split(","): s = s.strip() if s: selected[s] = None # deliver,缺省 demo 当前 tag for item in (os.environ.get("IMAGES") or "").split(","): item = item.strip() if not item: continue if "=" not in item: die(f"IMAGES 条目应为 svc=harborTag,收到: {item}") s, t = item.split("=", 1) selected[s.strip()] = t.strip() or None if selected: for s, t in selected.items(): e = {"service": s, "action": "deliver"} if t: e["harborTag"] = t entries.append(e) else: # 全部缺省 = 6 内置服务全 deliver demo 当前 tag(行为与改造前一致) entries = [{"service": s, "action": "deliver"} for s in DEFAULT_SERVICES] # ── 2. 校验 + 规范化(缺省六服务 + PLAN 带映射的额外服务 + 组件条目)── norm, seen = {}, set() component_entries = [] extra_order = [] # 非缺省字典的服务(PLAN 出现序;keep 条目也进,留痕一致) for e in entries: if e.get("component"): # 系统组件(第三方镜像):映射随条目携带,只支持 pin-acr/keep 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 not isinstance(svc, str) or not svc.strip(): die(f"PLAN 条目缺 service 或非字符串: {e}") svc = svc.strip() if svc in seen: die(f"PLAN 中服务重复: {svc}") seen.add(svc) action = e.get("action", "keep") if action not in ACTIONS: die(f"非法 action: {action}(合法值: {', '.join(ACTIONS)})") mapping = norm_mapping(svc, e) if mapping is None: # keep 允许无映射(纯 no-op 留痕);非 keep 必须自带映射或命中缺省字典 if action != "keep": die(f"服务 {svc} 无交付映射(PLAN 未带映射,也不在缺省字典: {', '.join(DEFAULT_SERVICES)}),只能 keep") mapping = {"repos": [], "keys": [], "appFile": "", "valuesFiles": []} if action != "keep" and not mapping["keys"] and not mapping["valuesFiles"]: die(f"服务 {svc} 非 keep 动作但映射无钉版落点(keys/valuesFiles 均空)") if svc not in REPOS: extra_order.append(svc) n = {"service": svc, "action": action, **mapping} if action == "reuse": ver = str(e.get("version") or "") if not re.fullmatch(r"v\d+\.\d+\.\d+", ver): die(f"reuse 服务 {svc} 需提供 version(vX.Y.Z),收到: {ver or '(空)'}") n["version"] = ver elif action in ("deliver", "ci-now"): tag = str(e.get("harborTag") or "").strip() n["harborTag"] = tag or demo_tag(svc, mapping) n["harborTagExplicit"] = bool(tag) elif action == "pin-acr": tag = str(e.get("acrTag") or "").strip() if not tag: die(f"pin-acr 服务 {svc} 需提供 acrTag(ACR 上已有的 tag 名)") n["acrTag"] = tag norm[svc] = n plan_out = [norm.get(s) or {"service": s, "action": "keep", "repos": REPOS[s], "keys": KEYS[s], "appFile": APPFILE[s], "valuesFiles": []} for s in DEFAULT_SERVICES] plan_out += [norm.get(s) or {"service": s, "action": "keep", "repos": [], "keys": [], "appFile": "", "valuesFiles": []} for s in extra_order] plan_out += component_entries # 组件 pin-acr 也算正式发布(与门户 hasDeliver 同语义:分配版本号并 bump chart) 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()] known = {e["service"] for e in plan_out if not e.get("component")} 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 known: die(f"DB_CHANGE 含未在计划中的服务名: {s}(计划内: {', '.join(sorted(known))})") if s not in nonkeep: die(f"DB_CHANGE 服务 {s} 本次为 keep,不在交付范围内(非 keep 服务: {', '.join(sorted(nonkeep)) or '无'})") # ── 4. deliver/ci-now 显式 harborTag 的 Harbor 存在性校验 ── explicit = [e for e in plan_out if e["action"] in ("deliver", "ci-now") and e.get("harborTagExplicit")] h_user, h_pass = os.environ.get("HARBOR_USER"), os.environ.get("HARBOR_PASS") if explicit and not (h_user and h_pass): print("[promote] 警告: 未提供 HARBOR_USER/HARBOR_PASS,跳过显式 harborTag 的 Harbor 存在性校验") elif explicit: auth = base64.b64encode(f"{h_user}:{h_pass}".encode()).decode() for e in explicit: for repo in e["repos"]: url = f"http://{HARBOR_HOST}/v2/mixingx/{repo}/manifests/{e['harborTag']}" req = urllib.request.Request(url, headers={ "Accept": ("application/vnd.oci.image.index.v1+json, " "application/vnd.oci.image.manifest.v1+json, " "application/vnd.docker.distribution.manifest.v2+json, " "application/vnd.docker.distribution.manifest.list.v2+json"), "Authorization": f"Basic {auth}"}) try: with urllib.request.urlopen(req, timeout=15) as r: if r.status != 200: die(f"Harbor 校验 {repo}:{e['harborTag']} 返回 HTTP {r.status}") except urllib.error.HTTPError as ex: if ex.code == 404: die(f"Harbor 上不存在镜像 {repo}:{e['harborTag']}(服务 {e['service']}),请核对 harborTag") die(f"Harbor 校验 {repo}:{e['harborTag']} 失败: HTTP {ex.code}") except urllib.error.URLError as ex: die(f"无法连接 Harbor 校验 {repo}:{e['harborTag']}: {ex.reason}") print(f"[promote] Harbor 存在性校验通过({len(explicit)} 个显式 harborTag)") # ── 5. 交付基线(仅 deliver/ci-now 服务;CHART_ONLY 跳过)── if not CHART_ONLY: baseline = [] for e in plan_out: if e["action"] in ("deliver", "ci-now"): for repo in e["repos"]: baseline.append(f"{repo} {e['harborTag']}") # protocol mock 不进 PLAN,沿用 PROMOTE_PROTOCOLS 独立开关; # 纯复用发布没有新版本号可钉,protocol 一并跳过 if WITH_PROTOCOLS: if has_deliver: for name, node in (images.get("protocol") or {}).items(): if isinstance(node, dict) and node.get("repository") and node.get("tag"): baseline.append(f"{node['repository']} {node['tag']}") print("[promote] PROMOTE_PROTOCOLS=true:protocol 镜像一并晋级") else: print("[promote] 警告: 纯复用发布无新版本号,PROMOTE_PROTOCOLS 本次不生效") open(baseline_path, "w", encoding="utf-8").write("\n".join(baseline) + ("\n" if baseline else "")) if baseline: print(f"[promote] 交付基线 {len(baseline)} 个镜像: " + ", ".join(l.split()[0] for l in baseline)) else: print("[promote] 交付基线为空(无 deliver/ci-now 服务)") else: print("[promote] CHART_ONLY=true:跳过镜像基线生成") # ── 6. 落盘:.plan.json / .plan-facts / .plan.txt ── json.dump(plan_out, open(plan_path, "w", encoding="utf-8"), ensure_ascii=False, indent=1) open(facts_path, "w", encoding="utf-8").write("HAS_DELIVER=%s\n" % ("true" if has_deliver else "false")) # PLAN JSON 原文(未提供时写规范化后的等价 JSON),仅作审计留痕;pin 实际消费 .plan.json open(plantxt_path, "w", encoding="utf-8").write(raw_plan or json.dumps(plan_out, ensure_ascii=False)) for e in plan_out: if e["action"] == "keep": continue 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 # ── 版本号与 chart tag 分配 ── ASSIGN_VERSION="${ASSIGN_VERSION:-true}" case "$ASSIGN_VERSION" in true|false) : ;; *) die "ASSIGN_VERSION 只接受 true/false,收到: $ASSIGN_VERSION" ;; esac HAS_REAL_DELIVER=$(python3 -c " import json plan = json.load(open('$PLAN_FILE')) print('true' if any(e['action'] in ('deliver','ci-now') for e in plan) else 'false')") if [ "$ASSIGN_VERSION" = "false" ] && [ "$HAS_REAL_DELIVER" = "true" ]; then die "ASSIGN_VERSION=false 与 deliver/ci-now 互斥:镜像 retag 的目标名就是版本号,交付必须分配" fi GIVEN_VERSION="${RELEASE_VERSION:-}" if [ "$ASSIGN_VERSION" = "true" ] && { [ "$HAS_DELIVER" = "true" ] || [ "$CHART_ONLY" = "true" ]; }; then RELEASE_VERSION="${GIVEN_VERSION:-$(sh ci/auto-bump.sh)}" case "$RELEASE_VERSION" in v[0-9]*.[0-9]*.[0-9]*) : ;; *) die "RELEASE_VERSION 格式应为 vX.Y.Z,收到: $RELEASE_VERSION" ;; esac CHART_TAG="chart-$RELEASE_VERSION" # chart tag 已存在不再拒绝:幂等复用(同参数重跑/同一版本发多个客户) if git ls-remote --tags "$CHART_REPO" "refs/tags/$CHART_TAG" | grep -q .; then CHART_TAG_EXISTS=true log "$CHART_TAG 已存在于 chart 仓库,复用(幂等)" else CHART_TAG_EXISTS=false fi PURE_REUSE=false log "交付版本: $RELEASE_VERSION 客户: $CUSTOMER chart tag: $CHART_TAG" else # 无需新版本号(纯复用,或 ASSIGN_VERSION=false 的纯钉版):chart 步骤整体跳过 RELEASE_VERSION=""; CHART_TAG=""; CHART_TAG_EXISTS=false; PURE_REUSE=true [ -z "$GIVEN_VERSION" ] || log "警告: 本次发布不分配新版本号,已忽略传入的 $GIVEN_VERSION" log "本次发布不分配新版本号,chart 步骤将跳过" fi export ASSIGN_VERSION # 克隆 chart 仓库(供 chart 步骤复用)并核对交付镜像清单 rm -rf "$WS/.ci"; mkdir -p "$WS/.ci" git clone -q "$CHART_REPO" "$CHART_DIR" python3 - "$CHART_DIR/delivery/image-manifest.yaml" <<'PY' import sys, yaml m = yaml.safe_load(open(sys.argv[1], encoding="utf-8")) or {} missing = [e["acr"] for e in m.get("thirdParty", []) if not e.get("optional") and not e.get("pushed")] if missing: sys.exit("[promote] 错误: 交付镜像清单存在未推送 ACR 的非可选镜像: " + ", ".join(missing) + "\n 请先按 D2 用 cr_temp_user 临时 token 补推,再执行发布") print("[promote] 交付镜像清单核对通过(第三方镜像齐备)") PY OPERATOR="${OPERATOR:-drone}" RELEASE_NOTES="${RELEASE_NOTES:-}" DB_CHANGE="${DB_CHANGE:-}" # .release-env 是 shell source 的:自由文本值一律经 shq 单引号转义,防注入/断行 { echo "RELEASE_VERSION=$(shq "$RELEASE_VERSION")" echo "CUSTOMER=$(shq "$CUSTOMER")" echo "CHART_TAG=$(shq "$CHART_TAG")" echo "CHART_TAG_EXISTS=$CHART_TAG_EXISTS" echo "CHART_ONLY=$CHART_ONLY" echo "PURE_REUSE=$PURE_REUSE" echo "ASSIGN_VERSION=$ASSIGN_VERSION" echo "OPERATOR=$(shq "$OPERATOR")" echo "RELEASE_NOTES=$(shq "$RELEASE_NOTES")" echo "DB_CHANGE=$(shq "$DB_CHANGE")" echo "PLAN=$(shq "$(cat "$PLAN_TXT_FILE")")" } > "$ENV_FILE" log "prepare 完成" } # ───────────────────────────────────────────── # retag # ───────────────────────────────────────────── do_retag() { require_env if [ "$CHART_ONLY" = "true" ]; then log "CHART_ONLY=true,镜像晋级整步跳过" exit 0 fi if [ ! -s "$BASELINE_FILE" ]; then log "交付基线为空(纯复用发布或无 deliver/ci-now 服务),无镜像需晋级" exit 0 fi if [ "$DRY_RUN" = "true" ]; then ACR_REGISTRY="${ACR_REGISTRY:-acr.example.com}" HARBOR_REGISTRY="${HARBOR_REGISTRY:-harbor.example.com/mixingx}" log "[dry-run] 跳过 ACR 登录,docker 命令仅打印" else : "${ACR_REGISTRY:?缺少 ACR_REGISTRY}" : "${HARBOR_REGISTRY:?缺少 HARBOR_REGISTRY}" : "${ACR_USER:?缺少 acr_push_username secret}" : "${ACR_PASS:?缺少 acr_push_password secret}" # 推 ACR 必须用 docker(ctr 有 blob unknown 问题,见底座 runbook) printf %s "$ACR_PASS" | docker login "$ACR_REGISTRY" -u "$ACR_USER" --password-stdin \ || die "ACR 登录失败(检查 secrets 与实例访问授权)" fi : > "$DIGESTS_FILE" while IFS=' ' read -r repo tag; do [ -n "$repo" ] || continue log "晋级 $repo:$tag → mixingx/$repo:$RELEASE_VERSION" if [ "$DRY_RUN" = "true" ]; then run docker pull "$HARBOR_REGISTRY/$repo:$tag" run docker tag "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" run docker push "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" run docker rmi "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" digest="sha256:dryrun-$repo" else docker pull "$HARBOR_REGISTRY/$repo:$tag" || die "拉取失败: $repo:$tag(119 上是否存在?)" docker tag "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" docker push "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" || die "推送失败: $repo" docker rmi "$HARBOR_REGISTRY/$repo:$tag" "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" >/dev/null 2>&1 || true # 记录 ACR 镜像 digest(供 release-notes 反向追踪);取不到则写空并警告,不 fail digest=$(docker buildx imagetools inspect "$ACR_REGISTRY/mixingx/$repo:$RELEASE_VERSION" 2>/dev/null \ | awk '/^Digest:/ {print $2; exit}' || true) [ -n "$digest" ] || log "警告: 未取到 $repo:$RELEASE_VERSION 的 digest,release-notes 将留空" fi printf '%s %s\n' "$repo" "${digest:-}" >> "$DIGESTS_FILE" done < "$BASELINE_FILE" log "镜像晋级完成: $(wc -l < "$BASELINE_FILE" | tr -d ' ') 个 → $ACR_REGISTRY/mixingx/*:$RELEASE_VERSION" } # ───────────────────────────────────────────── # chart # ───────────────────────────────────────────── do_chart() { require_env git_setup if [ "$PURE_REUSE" = "true" ]; then log "纯复用发布(无 deliver/ci-now),不需要新 chart tag,chart 步骤跳过" exit 0 fi # 幂等:tag 已存在即复用,跳过整个 bump/tag/push(同参数重跑/同版本发多客户) if git ls-remote --tags "$CHART_REPO" "refs/tags/$CHART_TAG" | grep -q .; then log "$CHART_TAG 已存在于 chart 仓库,复用(幂等),跳过 bump/tag/push" exit 0 fi [ -d "$CHART_DIR/.git" ] || { rm -rf "$CHART_DIR"; git clone -q "$CHART_REPO" "$CHART_DIR"; } cd "$CHART_DIR" VER="${RELEASE_VERSION#v}" for f in $CHARTS_DIR/*/Chart.yaml; do python3 - "$f" "$VER" <<'PY' import sys, re path, ver = sys.argv[1], sys.argv[2] t = open(path, encoding="utf-8").read() t = re.sub(r'(?m)^version:\s*\S+', f'version: {ver}', t) t = re.sub(r'(?m)^appVersion:\s*"?[^"\n]+"?', f'appVersion: "{ver}"', t) open(path, "w", encoding="utf-8").write(t) PY done git add -A git diff --cached --quiet && die "Chart.yaml 无变化,异常(版本号相同?)" git commit -q -m "release: bump chart version to $RELEASE_VERSION" git tag "$CHART_TAG" run git push -q origin HEAD:master "refs/tags/$CHART_TAG" || die "chart 仓库 push 失败(netrc 凭证?)" N=$(ls -d $CHARTS_DIR/*/ | wc -l | tr -d ' ') log "chart 已发布: $CHART_TAG($N 个 chart version=$VER)" } # ───────────────────────────────────────────── # pin # ───────────────────────────────────────────── do_pin() { require_env git_setup cd "$WS" 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" [ -d "$ENVDIR" ] || die "客户目录不存在: $ENVDIR" [ -d "$APPDIR" ] || die "客户目录不存在: $APPDIR" [ -f "$PLAN_FILE" ] || die "缺少 $PLAN_FILE,请先运行 prepare 步骤" export CUSTOMER RELEASE_VERSION CHART_TAG CHART_ONLY PURE_REUSE OPERATOR RELEASE_NOTES DB_CHANGE python3 - "$ENVDIR" "$APPDIR" "$PLAN_FILE" "$DIGESTS_FILE" "$COMMIT_MSG_FILE" <<'PY' import json, os, re, sys from datetime import date as date_type, datetime, timedelta, timezone import yaml envdir, appdir, plan_path, digests_path, commit_msg_path = sys.argv[1:6] CUSTOMER = os.environ.get("CUSTOMER", "") RELEASE_VERSION = os.environ.get("RELEASE_VERSION", "") CHART_TAG = os.environ.get("CHART_TAG", "") CHART_ONLY = os.environ.get("CHART_ONLY", "false") == "true" PURE_REUSE = os.environ.get("PURE_REUSE", "false") == "true" OPERATOR = os.environ.get("OPERATOR", "drone") 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" 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 # (保持旧版全量 sed 行为:全量交付时与改造前逐字节一致;纯复用发布无新 tag 则不动) PLATFORM_APPFILES = ["infra.yaml", "mqttx.yaml"] # retag 步骤记录的 ACR 镜像 digest,repo → digest(取不到的行第二列为空) digests = {} if os.path.exists(digests_path): for line in open(digests_path, encoding="utf-8"): parts = line.split() if parts: digests[parts[0]] = parts[1] if len(parts) > 1 else "" iv_path = os.path.join(envdir, "image-version.yaml") rn_path = os.path.join(envdir, "release-notes.yaml") # ── 1) image-version.yaml:只钉有 keys 且非 keep 的服务(CHART_ONLY 不动镜像文件)── from_tags, to_tags = {}, {} def new_tag_of(e): if e["action"] in ("deliver", "ci-now"): return RELEASE_VERSION if e["action"] == "pin-acr": return e["acrTag"] # 所选 ACR tag 原样钉入,不 retag return e["version"] if not CHART_ONLY: data = yaml.safe_load(open(iv_path, encoding="utf-8")) or {} images = data.get("images") or {} for e in [x for x in actions if x["keys"]]: svc = e["service"] new_tag = new_tag_of(e) to_tags[svc] = new_tag for i, key in enumerate(e["keys"]): node = images.get(key) if not isinstance(node, dict) or "tag" not in node: sys.exit(f"[promote] 错误: {iv_path} 缺少 images.{key}.tag,无法为 {svc} 钉版") if i == 0: from_tags[svc] = str(node["tag"]) # 旧值留作 release-notes 的 from node["tag"] = new_tag print(f"[promote] {svc}: image {from_tags[svc]} → {new_tag}") # images.protocol 幂等清理(客户现场本不该有 protocol mock) images.pop("protocol", None) # 顶层 tag 只在有 deliver/ci-now 时跟随新版本号;纯复用保持原值 if has_deliver: data["tag"] = RELEASE_VERSION yaml.safe_dump(data, open(iv_path, "w", encoding="utf-8"), default_flow_style=False, sort_keys=False, allow_unicode=True) print(f"[promote] {iv_path} 钉版完成(未选中服务原样保留)") # ── 1.5) valuesFiles 服务:逐文件替换镜像 tag(独立 chart 服务的钉版落点)── # 三种形态:A. : 整行 B. repository: 行 + 相邻 tag: # C. image: 块下相邻 tag:(registry 由 _common/registry.yaml 提供、 # 仓名由 chart 缺省提供,客户 values 只钉 tag 时无 repo 行) def replace_values_tag(vpath, repo, new_tag): """就地替换 vpath 中服务镜像的 tag,返回旧 tag;三种形态均未命中返回 None""" lines = open(vpath, encoding="utf-8").readlines() pat_a = re.compile("(" + re.escape(repo) + r"):([A-Za-z0-9][\w.\-]*)") pat_b = re.compile(r"^(\s*tag:\s*)(\S+)\s*$") for idx, line in enumerate(lines): if not repo or repo not in line: continue m = pat_a.search(line) if m: # 形态 A old = m.group(2).strip("\"'") lines[idx] = pat_a.sub(lambda _m: _m.group(1) + ":" + new_tag, line) open(vpath, "w", encoding="utf-8").write("".join(lines)) return old for j in range(idx + 1, min(idx + 4, len(lines))): # 形态 B mb = pat_b.match(lines[j]) if mb: old = mb.group(2).strip("\"'") lines[j] = mb.group(1) + new_tag + "\n" open(vpath, "w", encoding="utf-8").write("".join(lines)) return old for idx, line in enumerate(lines): # 形态 C:首个 image: 块 if re.match(r"^image:\s*(#.*)?$", line): for j in range(idx + 1, min(idx + 4, len(lines))): mb = pat_b.match(lines[j]) if mb: old = mb.group(2).strip("\"'") lines[j] = mb.group(1) + new_tag + "\n" open(vpath, "w", encoding="utf-8").write("".join(lines)) return old break return None for e in [x for x in actions if x.get("valuesFiles")]: svc = e["service"] new_tag = new_tag_of(e) olds = [] for vf in e["valuesFiles"]: vpath = os.path.join(envdir, vf) if not os.path.exists(vpath): sys.exit(f"[promote] 错误: 客户目录缺 {vf}(服务 {svc} 的钉版 values 文件)") old = replace_values_tag(vpath, e["repos"][0], new_tag) if old is None: sys.exit(f"[promote] 错误: {vf} 中未找到服务 {svc} 的镜像 tag(整行/拆分/image 块三种形态均未命中)") olds.append(old) print(f"[promote] {svc}: {vf} {old} → {new_tag}") if svc not in from_tags: from_tags[svc] = " / ".join(olds) to_tags[svc] = new_tag # ── 1.6) 系统组件:逐 values 文件精确替换该镜像的 tag(CHART_ONLY 已互斥)── # 兼容两种 values 形态:A. image: /:(整行) # B. repository: / + 相邻 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"] else: print("[promote] CHART_ONLY=true:image-version.yaml 不动") # ── 2) applications chart targetRevision:只处理非 keep 服务对应的文件 ── # (语义等价于按文件 sed,用 python 实现以便与 PLAN 共用服务→文件映射) chart_from, chart_to = {}, {} def retarget(path, new_ref, required): if not os.path.exists(path): if required: sys.exit(f"[promote] 错误: 缺少 Application 文件 {path}") print(f"[promote] 警告: {path} 不存在,跳过") return None text = open(path, encoding="utf-8").read() m = re.search(r"chart-v\d+\.\d+\.\d+", text) if not m: if required: sys.exit(f"[promote] 错误: {path} 中未找到 chart-vX.Y.Z targetRevision") print(f"[promote] 警告: {path} 中未找到 chart-vX.Y.Z targetRevision,跳过") return None old_ref = m.group(0) new_text = re.sub(r"chart-v\d+\.\d+\.\d+", new_ref, text) if new_text != text: open(path, "w", encoding="utf-8").write(new_text) print(f"[promote] {path}: {old_ref} → {new_ref}") return old_ref, new_ref for e in actions: if not e["appFile"]: print(f"[promote] {e['service']}: 无 appFile 映射,chart 引用不动(独立 chart 服务)") continue if e["action"] == "pin-acr" and not CHART_TAG: # 未分配版本号(ASSIGN_VERSION=false):只钉镜像 tag,chart 引用不动 print(f"[promote] {e['service']}: 未分配版本号,chart 引用不动") continue new_ref = CHART_TAG if e["action"] in ("deliver", "ci-now", "pin-acr") else f"chart-{e['version']}" r = retarget(os.path.join(appdir, e["appFile"]), new_ref, required=True) if r: chart_from[e["service"]], chart_to[e["service"]] = r # 平台文件跟随新 chart tag(纯复用发布无新版本号,不动) if not PURE_REUSE: for f in PLATFORM_APPFILES: retarget(os.path.join(appdir, f), CHART_TAG, required=False) # ── 3) release-notes.yaml:追加日志,新条目插 releases 列表最前 ── rn = {} if os.path.exists(rn_path): rn = yaml.safe_load(open(rn_path, encoding="utf-8")) or {} if not isinstance(rn, dict): rn = {} releases = rn.get("releases") if not isinstance(releases, list): releases = [] # safe_load 会把 ISO8601 date 解析成 datetime,重新落盘前归一化回原字符串,保证幂等 for rel in releases: d = rel.get("date") if isinstance(rel, dict) else None if isinstance(d, datetime): rel["date"] = d.replace(microsecond=0).isoformat() elif isinstance(d, date_type): rel["date"] = d.isoformat() def find_reuse_source(svc, version): """reuse 服务的 sourceTag/digest 从既有 release-notes 中该服务该版本的条目拷贝""" for rel in releases: for s in (rel.get("services") or []): if s.get("name") == svc and str(s.get("to")) == version: return str(s.get("sourceTag") or ""), str(s.get("digest") or "") return "", "" svc_entries, src_tags = [], {} 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, "") source_tag = digest = "" elif action in ("deliver", "ci-now"): frm, to = from_tags.get(svc, ""), to_tags.get(svc, "") source_tag = e.get("harborTag", "") # 前后端共用同一 tag,digest 取首个 repo(后端) digest = digests.get(e["repos"][0], "") if not digest: print(f"[promote] 警告: {svc} 未取到镜像 digest,release-notes 留空") elif action == "pin-acr": # 源即 ACR 上所选 tag 本身,如实记;未搬运,无 digest frm, to = from_tags.get(svc, ""), to_tags.get(svc, "") source_tag = e.get("acrTag", "") digest = "" else: # reuse frm, to = from_tags.get(svc, ""), e["version"] source_tag, digest = find_reuse_source(svc, e["version"]) if not source_tag and not digest: print(f"[promote] 警告: 既往 release-notes 中未找到 {svc} {e['version']} 的交付记录," f"sourceTag/digest 留空") src_tags[svc] = source_tag svc_entries.append({"name": svc, "action": action, "from": frm, "to": to, "sourceTag": source_tag, "digest": digest, "dbChange": svc in DB_CHANGE}) if svc_entries or NOTES.strip(): now = datetime.now(timezone(timedelta(hours=8))).replace(microsecond=0).isoformat() releases.insert(0, {"date": now, "operator": OPERATOR, "notes": NOTES, "services": svc_entries}) rn["releases"] = releases yaml.safe_dump(rn, open(rn_path, "w", encoding="utf-8"), default_flow_style=False, sort_keys=False, allow_unicode=True) print(f"[promote] {rn_path} 已追加发布记录({len(svc_entries)} 个服务)") else: print("[promote] 全部服务 keep 且无 RELEASE_NOTES,release-notes 不变") # ── 5) commit message:服务清单(action/from→to)与 RELEASE_NOTES ── if PURE_REUSE: kind = "钉版发布" if svc_entries else "纯复用发布" title = f"release: {CUSTOMER} {kind}(无新版本号)" elif CHART_ONLY: title = f"release: {CUSTOMER} chart 交付 {CHART_TAG}(CHART_ONLY)" else: title = f"release: {CUSTOMER} 交付 {RELEASE_VERSION}({CHART_TAG})" lines = [title, "", "服务清单:"] for e in svc_entries: seg = f"- {e['name']}: {e['action']} {e['from']} → {e['to']}" if e["sourceTag"]: seg += f"(source: {e['sourceTag']})" if e["dbChange"]: seg += " [db-change]" lines.append(seg) if not svc_entries: lines.append("- (无服务变更)") kept = [e["service"] for e in plan if e["action"] == "keep"] if kept: lines.append(f"其余服务保持现状(keep): {', '.join(kept)}") if NOTES.strip(): lines += ["", f"release-notes: {NOTES}"] lines += ["", f"operator: {OPERATOR}"] open(commit_msg_path, "w", encoding="utf-8").write("\n".join(lines) + "\n") PY git add "$ENVDIR" "$APPDIR" if git diff --cached --quiet; then # 纯 keep(且无 release-notes 变化)是合法空操作,明确提示而非困惑报错 log "本次发布为空操作(全部服务 keep 且无 release-notes 等变化),release 分支未产生提交" exit 0 fi git commit -q -F "$COMMIT_MSG_FILE" run git push -q origin release || die "release 分支 push 失败(分支保护?netrc 凭证?)" log "交付分支已更新: environments/$CUSTOMER" log "" log "════════ 发布完成 ════════" if [ "$PURE_REUSE" = "true" ]; then log "纯复用发布(无新版本号)" else log "版本: $RELEASE_VERSION (chart: $CHART_TAG)" fi log "现场: ArgoCD 约 3 分钟内自动 sync" } case "${1:-}" in prepare) do_prepare ;; retag) do_retag ;; chart) do_chart ;; pin) do_pin ;; *) echo "用法: promote.sh prepare|retag|chart|pin" >&2; exit 1 ;; esac