Include hub Next API routes and admin module select so the China-only Hub ship can build and mount on nomadro.com. Co-authored-by: Cursor <cursoragent@cursor.com>
97 lines
3.0 KiB
Python
97 lines
3.0 KiB
Python
"""SSH to US VPS: ensure hub_* PB collections on same-box :8090."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HOST, USER, PASSWORD = "108.174.50.68", "root", "Xiao4669805"
|
|
|
|
# Upload schemas + ensure script pieces and run against local PB on US.
|
|
REMOTE_PY = r'''
|
|
import sys
|
|
sys.path.insert(0, "/var/www/nomadro.cn/apps/api")
|
|
sys.path.insert(0, "/var/www/nomadro.cn/apps/api/services")
|
|
import os
|
|
os.environ.setdefault("PB_URL", "http://127.0.0.1:8090")
|
|
os.environ.setdefault("POCKETBASE_URL", "http://127.0.0.1:8090")
|
|
# admin from existing env files if present
|
|
for p in ("/var/www/nomadro.cn/apps/api/.env", "/var/www/nomadro.cn/apps/api/.env.local"):
|
|
try:
|
|
from dotenv import load_dotenv
|
|
load_dotenv(p, override=False)
|
|
except Exception:
|
|
pass
|
|
|
|
# Prefer inline credentials from service env
|
|
import subprocess, re
|
|
try:
|
|
out = subprocess.check_output(
|
|
"systemctl show nomadro-social -p Environment --value",
|
|
shell=True, text=True, stderr=subprocess.DEVNULL,
|
|
)
|
|
for part in out.replace("\n", " ").split():
|
|
if "=" in part:
|
|
k, _, v = part.partition("=")
|
|
if k.startswith("PB_") or k.startswith("POCKETBASE_"):
|
|
os.environ.setdefault(k, v)
|
|
except Exception:
|
|
pass
|
|
|
|
from nomadro_pb.ensure import ensure_selected
|
|
NAMES = {
|
|
"hub_roster","hub_liveness_audits","hub_skill_posts","hub_meetup_reviews",
|
|
"hub_blocks","hub_reports","hub_messages","hub_channel_meta","hub_channel_reads",
|
|
"hub_files","hub_trips","hub_cafe_reviews","hub_feedback","hub_join_leads",
|
|
"hub_gig_apps","hub_archives",
|
|
}
|
|
# Schemas may not include hub_* on server yet — inject from local upload
|
|
ok = False
|
|
try:
|
|
ok = ensure_selected(NAMES)
|
|
except ValueError as e:
|
|
print("schema_missing_on_server", e)
|
|
raise
|
|
print("RESULT", ok)
|
|
'''
|
|
|
|
|
|
def main() -> int:
|
|
# First upload updated schemas.py so server knows hub_* specs
|
|
local_schemas = ROOT / "apps/api/services/nomadro_pb/schemas.py"
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=25, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
remote_schemas = "/var/www/nomadro.cn/apps/api/services/nomadro_pb/schemas.py"
|
|
# backup
|
|
try:
|
|
sftp.stat(remote_schemas)
|
|
stdin, stdout, stderr = c.exec_command(
|
|
f"cp -a {remote_schemas} {remote_schemas}.bak-hub-$(date +%Y%m%d%H%M%S)"
|
|
)
|
|
stdout.channel.recv_exit_status()
|
|
except IOError:
|
|
print("remote schemas missing — portal path may differ")
|
|
sftp.put(str(local_schemas), remote_schemas)
|
|
print("uploaded schemas.py")
|
|
|
|
# Also need ensure.py if older — skip; ensure_selected already there
|
|
sftp.close()
|
|
|
|
stdin, stdout, stderr = c.exec_command("python3 - <<'PY'\n" + REMOTE_PY + "\nPY")
|
|
code = stdout.channel.recv_exit_status()
|
|
out = stdout.read().decode("utf-8", "replace")
|
|
err = stderr.read().decode("utf-8", "replace")
|
|
print(out)
|
|
if err:
|
|
print("STDERR", err[-2000:])
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|