Files
kefu/deploy/token-ui-restore-20260924/03-rollback.py
T
2026-09-28 10:02:50 +08:00

15 lines
1.1 KiB
Python

import json,shutil,subprocess
from pathlib import Path
release=Path('/home/ps/token-ui-restore-20260924');target=Path('/opt/im-admin')
base=json.loads((release/'baseline.json').read_text())['im-admin-api-1']['image']
expected=subprocess.check_output(['docker','image','inspect','zyt/wecom-admin:token-ui-20260924','--format','{{.Id}}'],text=True).strip()
active=json.loads(subprocess.check_output(['docker','inspect','im-admin-api-1']))[0]['Image']
assert active==expected,'A later release is active; refusing to roll it back'
for row in json.loads((release/'restore-files.json').read_text()):
dest=(target/row['path']).resolve();assert target in dest.parents
if row['existed']:shutil.copyfile(release/'source-before'/row['path'],dest)
# Leave new hashed assets in place for browsers that loaded the new index.
subprocess.run(['docker','tag',base,'zyt/wecom-admin:current'],check=True)
subprocess.run(['docker','compose','up','-d','--no-deps','--no-build','--wait','--wait-timeout','120','api'],cwd=target/'deploy/im-admin',check=True)
print('Previous frontend restored; database and gateway/worker unchanged.')