46 lines
2.1 KiB
Bash
46 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
|
# 恢复 remote_api.py 和原 /m/ 目录,切回旧镜像(mobile-remote-20260928),只重建 api。不涉及数据库。
|
|
set -euo pipefail
|
|
test "${REMOTE_RELEASE_APPROVED:-}" = mobile-http-20260928
|
|
release=/home/ps/mobile-http-20260928
|
|
cd /opt/im-admin/deploy/im-admin
|
|
test -d "$release/source-before"
|
|
test "$(docker image inspect zyt/wecom-admin:before-mobile-http-20260928 --format '{{.Id}}')" = "$(cat "$release/image-before.txt")"
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
import hashlib, json, os, shutil
|
|
r = Path('/home/ps/mobile-http-20260928'); 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()
|
|
for name in plan['backendFiles'] + plan['deployFiles']:
|
|
data = (r / 'source-before' / name).read_bytes(); assert sha(data) == base['expected'][name]
|
|
target = project / name; tmp = target.with_name(target.name + '.rollback-http.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)
|
|
frontend = plan['frontendDir']
|
|
saved = r / 'source-before' / frontend
|
|
for name, wanted in base['expected'].items():
|
|
if name.startswith(frontend + '/'):
|
|
assert sha((saved / name[len(frontend) + 1:]).read_bytes()) == wanted, name
|
|
restore = project / (frontend + '.rollback-http.tmp')
|
|
if restore.exists():
|
|
shutil.rmtree(restore)
|
|
shutil.copytree(saved, restore)
|
|
for leftover in [project / frontend, project / (frontend + '.mobile-http.tmp')]:
|
|
if leftover.exists():
|
|
shutil.rmtree(leftover)
|
|
old = project / (frontend + '.mobile-http.old')
|
|
if old.exists():
|
|
shutil.rmtree(old)
|
|
os.replace(restore, project / frontend)
|
|
PY
|
|
docker tag zyt/wecom-admin:before-mobile-http-20260928 zyt/wecom-admin:current
|
|
docker compose up -d --no-deps --no-build --wait --wait-timeout 180 api
|
|
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, remote_api.py and /m/ restored.'
|