#!/usr/bin/env python3 """ Ekeepa 360 Agile Cockpit Builder & Deployer Integrates Jira data, PRD files, compiles index.html from template, and deploys to https://ekeepa.zebellkhan.com/prds/ """ import os import sys import json import subprocess BASE_DIR = "/workspace/prds" TEMPLATE_PATH = os.path.join(BASE_DIR, "index_template.html") INDEX_PATH = os.path.join(BASE_DIR, "index.html") COCKPIT_JSON = os.path.join(BASE_DIR, "data", "cockpit_data.json") PRDS_JSON = os.path.join(BASE_DIR, "data", "prds.json") SYNC_SCRIPT = os.path.join(BASE_DIR, "sync_all_boards.py") KEY_HOST = os.path.expanduser("~/.ssh/id_ed25519") HOST_IP = "10.0.9.1" REMOTE_DIR = "/data/dashboards/ekeepa/prds/" def safe_json_for_script(data): """Safely encodes JSON for inclusion inside an HTML collision.""" raw = json.dumps(data, ensure_ascii=False) return raw.replace("<", "\\u003c").replace(">", "\\u003e").replace("&", "\\u0026") def main(): print("🔨 Step 1: Syncing fresh Jira data...") res = subprocess.run([sys.executable, SYNC_SCRIPT], capture_output=True, text=True) print(res.stdout) if res.returncode != 0: print(f"Sync Warning: {res.stderr}") print("📖 Step 2: Loading data files...") with open(COCKPIT_JSON, "r", encoding="utf-8") as f: cockpit_data = json.load(f) with open(PRDS_JSON, "r", encoding="utf-8") as f: prds_data = json.load(f) for item in prds_data: fpath = os.path.join(BASE_DIR, item["filePath"]) if os.path.exists(fpath): with open(fpath, "r", encoding="utf-8") as mf: item["rawContent"] = mf.read() else: item["rawContent"] = f"# {item.get('title', '')}\n\nŲØ§ÛŒŲ„ ÛŒØ§ŲØĒ Ų†Ø´Ø¯." cockpit_json_str = safe_json_for_script(cockpit_data) prds_json_str = safe_json_for_script(prds_data) print("🎨 Step 3: Compiling index.html from template...") with open(TEMPLATE_PATH, "r", encoding="utf-8") as f: html = f.read() # Replace placeholders marker_cockpit_start = "/* __COCKPIT_DATA_START__ */" marker_cockpit_end = "/* __COCKPIT_DATA_END__ */" cockpit_block = f"{marker_cockpit_start}\n window.__COCKPIT_DATA__ = {cockpit_json_str};\n {marker_cockpit_end}" marker_prds_start = "/* __PRDS_DATA_START__ */" marker_prds_end = "/* __PRDS_DATA_END__ */" prds_block = f"{marker_prds_start}\n window.__PRDS_DATA__ = {prds_json_str};\n {marker_prds_end}" idx1_s = html.find(marker_cockpit_start) idx1_e = html.find(marker_cockpit_end) if idx1_s != -1 and idx1_e != -1: html = html[:idx1_s] + cockpit_block + html[idx1_e + len(marker_cockpit_end):] idx2_s = html.find(marker_prds_start) idx2_e = html.find(marker_prds_end) if idx2_s != -1 and idx2_e != -1: html = html[:idx2_s] + prds_block + html[idx2_e + len(marker_prds_end):] with open(INDEX_PATH, "w", encoding="utf-8") as f: f.write(html) print(f"✅ index.html compiled successfully ({len(html)} bytes).") print("🚀 Step 4: Deploying to production server (ekeepa.zebellkhan.com/prds)...") cmd_scp = f"scp -i {KEY_HOST} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r {BASE_DIR}/* root@{HOST_IP}:{REMOTE_DIR}" subprocess.run(cmd_scp, shell=True, check=True) cmd_perm = f"ssh -i {KEY_HOST} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@{HOST_IP} 'chmod -R 755 {REMOTE_DIR}'" subprocess.run(cmd_perm, shell=True, check=True) print("🎉 DEPLOY COMPLETE: Verified live on https://ekeepa.zebellkhan.com/prds/") if __name__ == "__main__": main()