Files
kefu/deploy/review-gate-20260930/server-bundle/rollback.sh
T
2026-09-30 19:28:13 +08:00

40 lines
2.3 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 先切回旧镜像、重建 api 和 gateway(容器只从镜像读代码,先恢复服务),再恢复宿主上的 5 个后端文件和
# 管理后台 index.html、删除新增的前端文件。宿主文件恢复失败不影响已经回滚的服务,只会报错留待人工处理。
# gateway 回到 before-review-gate-20260930(与 api 同一镜像):它和原来的 8299aac 相比只差
# admin_api / remote_* / zyt_auth,gateway 进程不导入这几个模块。不涉及数据库。
set -euo pipefail
test "${REMOTE_RELEASE_APPROVED:-}" = review-gate-20260930
release=/home/ps/review-gate-20260930
cd /opt/im-admin/deploy/im-admin
test -d "$release/source-before"
test "$(docker image inspect zyt/wecom-admin:before-review-gate-20260930 --format '{{.Id}}')" = "$(cat "$release/image-before.txt")"
docker tag zyt/wecom-admin:before-review-gate-20260930 zyt/wecom-admin:current
docker compose up -d --no-deps --no-build --wait --wait-timeout 180 api gateway
curl -fsS -o /dev/null http://127.0.0.1:18766/api/v2/health
curl -fsS -o /dev/null http://127.0.0.1:18770/health
printf '%s\n' 'Previous image restored for api and gateway.'
python3 - <<'PY'
from pathlib import Path
import hashlib, json, os
r = Path('/home/ps/review-gate-20260930'); project = Path('/opt/im-admin')
base = json.loads((r / 'server-baseline.json').read_text())
plan = json.loads((r / 'release-plan.json').read_text())
sha = lambda data: hashlib.sha256(data).hexdigest()
replaced = plan['backendFiles'] + [plan['frontendDir'] + '/' + rel for rel in plan['frontendReplaced']]
for name in replaced:
data = (r / 'source-before' / name).read_bytes(); assert sha(data) == base['expected'][name], name
target = project / name; tmp = target.with_name(target.name + '.rollback-review-gate.tmp')
if tmp.exists():
tmp.unlink()
with tmp.open('xb') as f:
f.write(data)
os.chmod(tmp, target.stat().st_mode & 0o777); os.replace(tmp, target)
added = [project / plan['frontendDir'] / rel for rel in plan['frontendAdded']]
for path in added + [project / name for name in replaced]:
for leftover in ((path,) if path in added else ()) + (path.with_name(path.name + '.review-gate.tmp'),):
if leftover.exists():
leftover.unlink()
PY
printf '%s\n' 'Host backend files and admin index.html restored.'