58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Deploy chatwoot_proxy.py cable fix + verify on remote."""
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
pw = os.environ["DEPLOY_PASSWORD"]
|
|
STACK = Path(__file__).resolve().parent
|
|
FILES = [
|
|
("flask/chatwoot_proxy.py", "/opt/guest-cs/chatwoot_proxy.py"),
|
|
("flask/app.py", "/opt/guest-cs/app.py"),
|
|
("flask/maxkb_chatwoot_bridge.py", "/opt/guest-cs/maxkb_chatwoot_bridge.py"),
|
|
]
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("20.191.152.26", username="wakka", password=pw, timeout=30)
|
|
sftp = c.open_sftp()
|
|
|
|
for local_rel, container_path in FILES:
|
|
local = STACK / local_rel
|
|
remote_tmp = f"/home/wakka/{Path(local_rel).name}.patch"
|
|
data = local.read_bytes().replace(b"\r\n", b"\n")
|
|
with sftp.file(remote_tmp, "wb") as rf:
|
|
rf.write(data)
|
|
cmd = f"sudo docker cp {remote_tmp} guest-chat:{container_path}"
|
|
print(">>>", cmd)
|
|
_, o, e = c.exec_command(cmd, timeout=60)
|
|
out, err = o.read().decode(), e.read().decode()
|
|
if out:
|
|
print(out)
|
|
if err:
|
|
print("ERR:", err)
|
|
|
|
sftp.close()
|
|
|
|
verify = r"""
|
|
sudo docker exec guest-chat supervisorctl restart gunicorn 2>/dev/null || sudo docker restart guest-chat
|
|
sleep 12
|
|
echo '=== CABLE_ORIGIN via Host 20.191.152.26:7777 ==='
|
|
curl -s 'http://127.0.0.1:7777/cw/widget?website_token=j1UAjqBgZMWQ8WfczgJSymQx' \
|
|
-H 'Host: 20.191.152.26:7777' | grep -o 'CABLE_ORIGIN = "[^"]*"' | head -1
|
|
echo
|
|
echo '=== guest page base_url ==='
|
|
curl -s 'http://127.0.0.1:7777/guest-customer-service' -H 'Host: 20.191.152.26:7777' \
|
|
| grep -oE 'base_url[^,}]+' | head -1
|
|
echo
|
|
echo '=== health ==='
|
|
curl -s -o /dev/null -w 'guest: %{http_code}\n' http://127.0.0.1:7777/guest-customer-service
|
|
"""
|
|
print(">>> restart + verify")
|
|
_, o, e = c.exec_command(verify, timeout=120)
|
|
print(o.read().decode())
|
|
err = e.read().decode()
|
|
if err:
|
|
print("ERR:", err[:500])
|
|
c.close()
|