#!/usr/bin/env python3 import io import os import tarfile import paramiko HOST = "10.10.0.10" USER = "localadministrator" PASS = "Bbt9115xty9176!" GITEA_TOKEN = "5c323b8ea677d78b201341f6833d57156a607008" APP = "ira4bw4nhbvm87o7s3fgqu6v" PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) GIT_AUTH = f"https://{USER}:{GITEA_TOKEN}@gitea.onsethost.com/localadministrator/exposedgays.git" c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, username=USER, password=PASS, timeout=20, allow_agent=False, look_for_keys=False) def run(cmd, t=300): print("$", cmd[:150]) _, o, e = c.exec_command(cmd, timeout=t) code = o.channel.recv_exit_status() out = (o.read() + e.read()).decode(errors="replace") print(out[-10000:]) print("exit", code, "\n") return code, out # Upload updated tarball buf = io.BytesIO() with tarfile.open(fileobj=buf, mode="w:gz") as tar: for root, dirs, files in os.walk(PROJECT_ROOT): dirs[:] = [d for d in dirs if d not in (".next", "node_modules", ".git")] for f in files: if f in (".env.local",): continue full = os.path.join(root, f) arc = os.path.relpath(full, PROJECT_ROOT) tar.add(full, arcname=arc) buf.seek(0) sftp = c.open_sftp() sftp.putfo(buf, "/tmp/exposedgays.tar.gz") sftp.close() run("rm -rf /tmp/exposedgays && mkdir -p /tmp/exposedgays && tar -xzf /tmp/exposedgays.tar.gz -C /tmp/exposedgays") run( "cd /tmp/exposedgays && git add -A && " "git commit -m 'Fix Dockerfile: npm install fallback when no lockfile' || true && " f"git push origin main" ) # Get latest deployment log run( f"TOKEN=$(cat /home/localadministrator/.coolify-token | tail -1); " f"curl -sS 'http://127.0.0.1:8000/api/v1/applications/{APP}/deployments' " f'-H "Authorization: Bearer $TOKEN" | python3 -c "import sys,json;d=json.load(sys.stdin); ' f'items=d if isinstance(d,list) else d.get(\\\"deployments\\\",d); ' f'[print(x.get(\\\"deployment_uuid\\\"),x.get(\\\"status\\\"),x.get(\\\"failure_reason\\\")) for x in items[:3]]" 2>/dev/null' ) run( "TOKEN=$(cat /home/localadministrator/.coolify-token | tail -1); " f"curl -sS -X POST 'http://127.0.0.1:8000/api/v1/deploy?uuid={APP}&force_rebuild=true' " '-H "Authorization: Bearer $TOKEN"' ) for i in range(30): _, out = run("docker exec coolify php artisan queue:work --queue=high,default --once --timeout=900 2>&1", t=920) if "ApplicationDeploymentJob" in out and "DONE" in out: print("DEPLOY DONE") break if "ApplicationDeploymentJob" in out and "FAIL" in out: print("DEPLOY FAIL - fetching logs") break run("docker ps --format '{{.Names}} {{.Status}}' | grep -i ira4 || docker ps --format '{{.Names}} {{.Status}}' | grep -i exposed || true") c.close()