47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Build Next.js on production and restart cnomadcna.service."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
from load_dev_env import ssh_config
|
|
|
|
HOST, USER, PASSWORD = ssh_config()
|
|
|
|
|
|
REPO = "/home/ubuntu/gitlab-instance-0a899031_cnomadcna"
|
|
BUILD_CMD = (
|
|
f"cd {REPO} && "
|
|
"APP_ENV=production NEXT_PUBLIC_APP_ENV=production NODE_ENV=production "
|
|
"pnpm build && systemctl restart cnomadcna.service && "
|
|
"systemctl is-active cnomadcna.service"
|
|
)
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, username=USER, password=PASSWORD, timeout=30)
|
|
try:
|
|
_, o, e = c.exec_command(
|
|
f"echo '{PASSWORD}' | sudo -S bash -lc \"{BUILD_CMD}\"",
|
|
timeout=900,
|
|
get_pty=True,
|
|
)
|
|
out = o.read().decode("utf-8", errors="replace")
|
|
err = e.read().decode("utf-8", errors="replace")
|
|
code = o.channel.recv_exit_status()
|
|
if out:
|
|
sys.stdout.buffer.write(out.encode("utf-8", errors="replace"))
|
|
if err:
|
|
sys.stdout.buffer.write(err.encode("utf-8", errors="replace"))
|
|
return code
|
|
finally:
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|