40 lines
2.4 KiB
Bash
40 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
||
# 先切回旧镜像、重建 api、gateway、knowledge-worker(容器只从镜像读代码,先恢复服务),再恢复宿主上的
|
||
# 5 个知识模块和管理后台 index.html、删除新增的前端文件。三个服务都回到 before-knowledge-batch-20261007
|
||
# (= knowledge-wash-20261007 镜像)。无数据库结构变化;正在退避重试的任务(options 里的 retry_after)旧版不认,
|
||
# 会立即被领取继续;旧版遇到超时会再把任务标为失败。发布前知识表行数在 knowledge-before.json。
|
||
set -euo pipefail
|
||
test "${REMOTE_RELEASE_APPROVED:-}" = knowledge-batch-20261007
|
||
release=/home/ps/knowledge-batch-20261007
|
||
cd /opt/im-admin/deploy/im-admin
|
||
test -d "$release/source-before"
|
||
test "$(docker image inspect zyt/wecom-admin:before-knowledge-batch-20261007 --format '{{.Id}}')" = "$(cat "$release/image-before.txt")"
|
||
docker tag zyt/wecom-admin:before-knowledge-batch-20261007 zyt/wecom-admin:current
|
||
docker compose up -d --no-deps --no-build --wait --wait-timeout 180 api gateway knowledge-worker
|
||
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, gateway and knowledge-worker.'
|
||
python3 - <<'PY'
|
||
from pathlib import Path
|
||
import hashlib, json, os
|
||
r = Path('/home/ps/knowledge-batch-20261007'); 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-knowledge-batch.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 + '.knowledge-batch.tmp'),):
|
||
if leftover.exists():
|
||
leftover.unlink()
|
||
PY
|
||
printf '%s\n' 'Host backend files and admin index.html restored.'
|