40 lines
2.0 KiB
Bash
40 lines
2.0 KiB
Bash
#!/usr/bin/env bash
|
|
# 恢复 2 个后端文件和 Dockerfile,删除新增文件与 /m/ 前端,切回旧镜像,只重建 api。
|
|
# 数据库保留:新增的 4 张表旧代码不会读写,留着不影响回滚后的运行。
|
|
set -euo pipefail
|
|
test "${REMOTE_RELEASE_APPROVED:-}" = mobile-remote-20260928
|
|
release=/home/ps/mobile-remote-20260928
|
|
cd /opt/im-admin/deploy/im-admin
|
|
test -d "$release/source-before"
|
|
test "$(docker image inspect zyt/wecom-admin:before-mobile-remote-20260928 --format '{{.Id}}')" = "$(cat "$release/image-before.txt")"
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
import hashlib, json, os, shutil
|
|
r = Path('/home/ps/mobile-remote-20260928'); project = Path('/opt/im-admin')
|
|
base = json.loads((r / 'server-baseline.json').read_text())
|
|
plan = json.loads((r / 'release-plan.json').read_text())
|
|
for name in plan['backendFiles'] + plan['deployFiles']:
|
|
data = (r / 'source-before' / name).read_bytes(); assert hashlib.sha256(data).hexdigest() == base['expected'][name]
|
|
target = project / name; tmp = target.with_name(target.name + '.rollback-mobile.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)
|
|
for name in plan['newBackendFiles']:
|
|
target = project / name
|
|
if target.exists():
|
|
target.unlink()
|
|
for path in [project / plan['frontendDir'], project / (plan['frontendDir'] + '.mobile-remote.tmp')]:
|
|
if path.exists():
|
|
shutil.rmtree(path)
|
|
mobile_app = project / 'admin-web/apps/mobile-h5'
|
|
if mobile_app.exists() and not any(mobile_app.iterdir()):
|
|
mobile_app.rmdir()
|
|
PY
|
|
docker tag zyt/wecom-admin:before-mobile-remote-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 and source files restored; live database retained (new tables unused).'
|