Ship Operations console polish, PocketBase social fixtures, and portal join-leads without local DBs or probe scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.7 KiB
Python
31 lines
1.7 KiB
Python
"""Publish locally built admin assets before atomically replacing HTML."""
|
|
import json
|
|
import runpy
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
root = Path(__file__).resolve().parents[1]
|
|
client = runpy.run_path(str(root / 'apps/admin/deploy/_upload_next_us.py'))['connect']()
|
|
remote = '/www/wwwroot/admin.nomadro.com'
|
|
release = datetime.now(timezone.utc).strftime('%Y%m%dT%H%M%SZ')
|
|
try:
|
|
_, output, error = client.exec_command(f'mkdir -p /var/backups/nomadro-upgrade/admin-{release} && cp {remote}/index.html /var/backups/nomadro-upgrade/admin-{release}/index.html')
|
|
if output.channel.recv_exit_status(): raise RuntimeError(error.read().decode())
|
|
with client.open_sftp() as sftp:
|
|
for path in (root / 'apps/com/admin/dist').rglob('*'):
|
|
if not path.is_file() or path.name == 'index.html': continue
|
|
target = remote + '/' + path.relative_to(root / 'apps/com/admin/dist').as_posix()
|
|
try: sftp.mkdir(str(Path(target).parent).replace('\\', '/'))
|
|
except OSError: pass
|
|
sftp.put(str(path), target)
|
|
sftp.put(str(root / 'apps/com/admin/dist/index.html'), remote + '/index.html.next')
|
|
_, output, error = client.exec_command(f'mv {remote}/index.html.next {remote}/index.html && curl -fsS --max-time 15 https://admin.nomadro.com/ >/dev/null')
|
|
if output.channel.recv_exit_status(): raise RuntimeError(error.read().decode())
|
|
path = root / 'artifacts/platform-upgrade/deployment.json'
|
|
report = json.loads(path.read_text())
|
|
report['adminFollowup'] = {'release': release, 'backup': f'/var/backups/nomadro-upgrade/admin-{release}', 'deployed': True}
|
|
path.write_text(json.dumps(report, indent=2), encoding='utf-8')
|
|
print('Admin deployed', release)
|
|
finally:
|
|
client.close()
|