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

41 lines
1.8 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
# 替换 5 个后端文件、管理后台入口 index.html 并新增 6 个带哈希的文件;切换镜像,只重建 api 和 gateway
# (knowledge-worker 不动)。任何一步失败自动调用 rollback.sh。
set -euo pipefail
test "${REMOTE_RELEASE_APPROVED:-}" = review-gate-20260930
release=/home/ps/review-gate-20260930
cd "$release"
test -f candidate-passed
python3 remote_server_guard.py baseline > /dev/null
cd /opt/im-admin/deploy/im-admin
docker compose config --quiet
rollback_on_error() { rc=$?; trap - ERR; bash "$release/rollback.sh"; exit "$rc"; }
trap rollback_on_error ERR
python3 - <<'PY'
from pathlib import Path
import json, hashlib, os
r = Path('/home/ps/review-gate-20260930'); target = Path('/opt/im-admin')
plan = json.loads((r / 'release-plan.json').read_text())
added = {plan['frontendDir'] + '/' + rel for rel in plan['frontendAdded']}
rows = [row for row in json.loads((r / 'manifest.json').read_text()) if row['path'].startswith('payload/')]
for row in rows:
rel = row['path'][len('payload/'):]
data = (r / row['path']).read_bytes(); assert hashlib.sha256(data).hexdigest() == row['sha256'], rel
dest = (target / rel).resolve(); assert dest.is_relative_to(target)
if rel in added:
assert not dest.exists(), rel
mode = 0o644
else:
assert dest.exists(), rel
mode = dest.stat().st_mode & 0o777
tmp = dest.with_name(dest.name + '.review-gate.tmp'); assert not tmp.exists()
with tmp.open('xb') as f:
f.write(data)
os.chmod(tmp, mode); os.replace(tmp, dest)
PY
docker tag zyt/wecom-admin:review-gate-20260930 zyt/wecom-admin:current
docker compose up -d --no-deps --no-build --wait --wait-timeout 180 api gateway
bash "$release/04-verify.sh"
trap - ERR
printf '%s\n' 'review-gate-20260930 deployed and verified (api + gateway).'