nomadweb/scripts/deploy_pay_env.py
eric ff7b721acb feat: NomadCNA community layer, social matching, payments, and ebook
Port meetups, discussions, gigs, dating/chat, VIP pay (ZPay/XorPay), MiroTalk live, digital academy, and ebook reader. Add persistent community_store, git-first deploy docs, and env template for production secrets.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 09:38:13 -05:00

96 lines
2.9 KiB
Python

"""Upload payment + env config to production and restart API."""
from __future__ import annotations
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "107.173.30.245"
USER = "root"
PASS = "Xiao4669805"
REMOTE = "/opt/nomadweb"
FILES = [
"backend/app/services/auth.py",
"backend/app/services/social_store.py",
"backend/app/services/payment_providers.py",
"backend/app/services/payment_service.py",
"backend/app/services/meetup_live.py",
"backend/app/routers/payment.py",
"frontend/src/app/tools/page.tsx",
"frontend/src/components/ToolsStrip.tsx",
"frontend/src/lib/i18n/dictionaries.ts",
"deploy/nomadro-api.env",
"deploy/systemd/nomadro-api.service",
]
RESTART = """
set -euo pipefail
chmod 640 /opt/nomadweb/deploy/nomadro-api.env
install -m 644 /opt/nomadweb/deploy/systemd/nomadro-api.service /etc/systemd/system/nomadro-api.service
systemctl daemon-reload
systemctl restart nomadro-api
cd /opt/nomadweb/frontend
export NEXT_TELEMETRY_DISABLED=1 NEXT_PUBLIC_API_URL=https://nomadweb.nomadro.com/api/v1 NEXT_PUBLIC_SITE_URL=https://nomadweb.nomadro.com NODE_ENV=production
rm -rf .next
NPM_CONFIG_PRODUCTION=false npm run build
mkdir -p .next/standalone/.next
rm -rf .next/standalone/public .next/standalone/.next/static
cp -a public .next/standalone/public
cp -a .next/static .next/standalone/.next/static
rm -rf .next/standalone/content && mkdir -p .next/standalone/content && cp -a content .next/standalone/content
systemctl restart nomadro-web
sleep 3
systemctl is-active nomadro-api nomadro-web
curl -s http://127.0.0.1:8055/api/v1/health
"""
def ensure_dir(sftp, path: str) -> None:
parts = path.strip("/").split("/")
cur = ""
for p in parts:
cur += "/" + p
try:
sftp.stat(cur)
except FileNotFoundError:
try:
sftp.mkdir(cur)
except OSError:
pass
def main() -> int:
root = Path(__file__).resolve().parents[1]
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("Connecting...")
client.connect(HOST, username=USER, password=PASS, timeout=30)
sftp = client.open_sftp()
for rel in FILES:
local = root / rel
remote = f"{REMOTE}/{rel}"
print(f"UPLOAD {rel}")
ensure_dir(sftp, str(Path(remote).parent).replace("\\", "/"))
sftp.put(str(local), remote)
sftp.close()
_, stdout, stderr = client.exec_command(RESTART, timeout=60)
out = stdout.read().decode("utf-8", errors="replace")
err = stderr.read().decode("utf-8", errors="replace")
code = stdout.channel.recv_exit_status()
print(out)
if err.strip():
print("ERR:", err)
client.close()
print("exit:", code)
return code
if __name__ == "__main__":
raise SystemExit(main())