"""Gitea webhook URL 수정 + E2E 자동 배포 검증""" import paramiko, sys, json, time, base64 sys.stdout.reconfigure(encoding='utf-8', errors='replace') c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15) sftp = c.open_sftp() J = 'http://127.0.0.1:9080' TOKEN = 'gitea-build-2026' # 미리 계산된 base64 GITEA_B64 = base64.b64encode(b'zio:Zio@Admin2026!').decode() def run(label, cmd, timeout=30): print(f'\n[{label}]') _, o, _ = c.exec_command(cmd, timeout=timeout) out = o.read().decode('utf-8','replace').strip() if out: print(out[:500]) return out HOOK_IDS = {'zioinfo-web':16,'guardia-itsm':17,'guardia-manager':18,'guardia-messenger':19,'guardia-docs':20} # Gitea webhook URL 업데이트 print('[Gitea webhook → Jenkins /job/{name}/build?token=...]') for repo, hid in HOOK_IDS.items(): payload = json.dumps({ "config": { "url": f"http://127.0.0.1:9080/job/{repo}/build?token={TOKEN}", "content_type": "json" }, "active": True, "events": ["push"] }) with sftp.open(f'/tmp/hook_{repo}.json', 'w') as f: f.write(payload) _, o, _ = c.exec_command( f"curl -sf -o /dev/null -w '%{{http_code}}' -X PATCH " f"'http://127.0.0.1:9003/api/v1/repos/zio/{repo}/hooks/{hid}' " f"-H 'Authorization: Basic {GITEA_B64}' " f"-H 'Content-Type: application/json' " f"--data @/tmp/hook_{repo}.json 2>/dev/null", timeout=15) code = o.read().decode('utf-8','replace').strip() print(f' {repo}: HTTP {code}') # Gitea webhook 직접 테스트 time.sleep(2) run('Gitea→Jenkins webhook 테스트 (guardia-itsm)', f"curl -sf -o /dev/null -w '%{{http_code}}' -X POST " f"'http://127.0.0.1:9003/api/v1/repos/zio/guardia-itsm/hooks/17/tests' " f"-H 'Authorization: Basic {GITEA_B64}' 2>/dev/null") time.sleep(10) _, o, _ = c.exec_command( f'curl -sf -u "admin:Admin@2026!" {J}/job/guardia-itsm/api/json 2>/dev/null', timeout=10) try: d = json.loads(o.read().decode('utf-8','replace')) nb = d.get('nextBuildNumber', '?') lb = d.get('lastBuild', {}).get('number', '?') print(f'\n[Jenkins guardia-itsm] lastBuild={lb}, nextBuild={nb}') if int(str(lb)) >= 4: print(' ✅ Gitea→Jenkins 직접 트리거 성공!') else: print(' ⚠️ 새 빌드 없음 - 기존 deploy_server 경로로 동작') except: pass # 최종 전체 파이프라인 상태 출력 print('\n' + '='*50) print('CI/CD 파이프라인 최종 상태') print('='*50) run('webhook 서버(9999)', 'systemctl is-active zioinfo-deploy') run('Jenkins(9080) - 5개 job', f'curl -sf -u "admin:Admin@2026!" {J}/api/json 2>/dev/null | ' "python3 -c \"import sys,json; d=json.load(sys.stdin); " "[print(' ',j['name'].ljust(22), j['color']) for j in d['jobs']]\" 2>/dev/null") run('Gitea hooks (guardia-itsm)', f"curl -sf 'http://127.0.0.1:9003/api/v1/repos/zio/guardia-itsm/hooks' " f"-H 'Authorization: Basic {GITEA_B64}' 2>/dev/null | " "python3 -c \"import sys,json; " "[print(' hook', h['id'], h['config'].get('url','')[:60], 'active:', h['active']) " "for h in json.load(sys.stdin)]\" 2>/dev/null") sftp.close() c.close() print('\n=== 완료 ===')