Merge branch 'dev' into 'main'
Fix:auto-déploiement & commentaire gitlab See merge request Omega_Kube/kuby!27
This commit is contained in:
commit
b03fd69169
3 changed files with 38 additions and 10 deletions
4
bot.py
4
bot.py
|
|
@ -1,4 +1,8 @@
|
||||||
import os
|
import os
|
||||||
|
# Nettoyer les variables de certificats SSL corrompues ou obsolètes pour éviter les crashs TLS
|
||||||
|
os.environ.pop("REQUESTS_CA_BUNDLE", None)
|
||||||
|
os.environ.pop("SSL_CERT_FILE", None)
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,17 +178,22 @@ class BugReport(commands.Cog):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
async def cog_load(self):
|
async def cog_load(self):
|
||||||
# ❌ DÉSACTIVÉ : Le webhook est géré par serveur_flask.py (port 5000)
|
kuby_logger.info("BugReport cog chargé. Démarrage du serveur de relais interne (port 5001)...")
|
||||||
# Le serveur Flask proxyfie déjà les webhooks GitLab vers ce cog via /bot_event
|
|
||||||
kuby_logger.info("BugReport cog chargé (webhook géré par serveur_flask.py)")
|
|
||||||
# Créer le dossier pour REPORTS_FILE s'il n'existe pas
|
|
||||||
REPORTS_DIR = os.path.dirname(REPORTS_FILE)
|
REPORTS_DIR = os.path.dirname(REPORTS_FILE)
|
||||||
os.makedirs(REPORTS_DIR, exist_ok=True)
|
os.makedirs(REPORTS_DIR, exist_ok=True)
|
||||||
|
await self._start_webhook_server()
|
||||||
|
|
||||||
async def _start_webhook_server(self):
|
async def _start_webhook_server(self):
|
||||||
# ❌ FONCTION DÉSACTIVÉE (voir cog_load)
|
try:
|
||||||
kuby_logger.warning("Tentative d'appel à _start_webhook_server() - cette fonction est désactivée")
|
app = web.Application()
|
||||||
return
|
app.router.add_post('/bot_event', self.handle_bot_event)
|
||||||
|
self.runner = web.AppRunner(app)
|
||||||
|
await self.runner.setup()
|
||||||
|
self.site = web.TCPSite(self.runner, '127.0.0.1', 5001)
|
||||||
|
await self.site.start()
|
||||||
|
kuby_logger.info("Internal Bot Webhook Server started on 127.0.0.1:5001")
|
||||||
|
except Exception as e:
|
||||||
|
kuby_logger.error(f"Failed to start Internal Bot Webhook Server: {e}")
|
||||||
|
|
||||||
def cog_unload(self):
|
def cog_unload(self):
|
||||||
if hasattr(self, 'runner'):
|
if hasattr(self, 'runner'):
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
import os, subprocess, threading, requests
|
import os, subprocess, threading, requests
|
||||||
|
# Nettoyer les variables de certificats SSL corrompues ou obsolètes pour éviter les crashs TLS
|
||||||
|
os.environ.pop("REQUESTS_CA_BUNDLE", None)
|
||||||
|
os.environ.pop("SSL_CERT_FILE", None)
|
||||||
|
|
||||||
from flask import Flask, request, abort
|
from flask import Flask, request, abort
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# --- CONFIGURATION ---
|
# --- CONFIGURATION ---
|
||||||
PROJECT_PATH = "/home/discord/Bot/Kuby_V2"
|
PROJECT_PATH = "/home/discord/Bot/Kuby"
|
||||||
WEBHOOK_SECRET = "Nois2"
|
WEBHOOK_SECRET = "Nois2"
|
||||||
PROCESS_NAME = "kuby"
|
PROCESS_NAME = "kuby"
|
||||||
DISCORD_LOG_URL = "https://discord.com/api/webhooks/1482148910888652910/IA9CcOWtjGswbuxMaOu_6uaclv5zojZo4ttxtV6RYyZzJ9gW7BF7xp_Zv3oPIjYEuh8o"
|
DISCORD_LOG_URL = "https://discord.com/api/webhooks/1482148910888652910/IA9CcOWtjGswbuxMaOu_6uaclv5zojZo4ttxtV6RYyZzJ9gW7BF7xp_Zv3oPIjYEuh8o"
|
||||||
|
|
@ -38,17 +42,32 @@ def run_mep_logic(author, commit_msg, branch="main"):
|
||||||
send_discord_log("EN COURS", f"Déploiement branch **{branch}** lancé sur la machine de guerre...", 3447003, author, commit_msg)
|
send_discord_log("EN COURS", f"Déploiement branch **{branch}** lancé sur la machine de guerre...", 3447003, author, commit_msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.chdir(PROJECT_PATH)
|
target_path = PROJECT_PATH
|
||||||
|
use_rsync = False
|
||||||
|
if not os.path.exists(os.path.join(target_path, ".git")):
|
||||||
|
alt_path = "/home/discord/Bot/Kuby"
|
||||||
|
if os.path.exists(os.path.join(alt_path, ".git")):
|
||||||
|
print(f"[!] {target_path} n'est pas un dépôt Git. Utilisation du dépôt {alt_path} et rsync.")
|
||||||
|
target_path = alt_path
|
||||||
|
use_rsync = True
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"Aucun dépôt Git trouvé dans {target_path} ou {alt_path}")
|
||||||
|
|
||||||
|
os.chdir(target_path)
|
||||||
|
|
||||||
# 1. GIT
|
# 1. GIT
|
||||||
subprocess.run(["git", "fetch", "origin"], check=True)
|
subprocess.run(["git", "fetch", "origin"], check=True)
|
||||||
subprocess.run(["git", "reset", "--hard", f"origin/{branch}"], check=True)
|
subprocess.run(["git", "reset", "--hard", f"origin/{branch}"], check=True)
|
||||||
|
|
||||||
|
# 2. RSYNC (si on utilise le fallback de dépôt)
|
||||||
|
if use_rsync:
|
||||||
|
subprocess.run(["rsync", "-a", "--exclude=.git", "--exclude=venv", "--exclude=.venv", "--exclude=__pycache__", f"{target_path}/", f"{PROJECT_PATH}/"], check=True)
|
||||||
|
|
||||||
duration = (datetime.now() - start_time).total_seconds()
|
duration = (datetime.now() - start_time).total_seconds()
|
||||||
msg = f"✅ **Déploiement réussi en {duration:.2f}s**\nLe bot est à jour et redémarré."
|
msg = f"✅ **Déploiement réussi en {duration:.2f}s**\nLe bot est à jour et redémarré."
|
||||||
send_discord_log("VALIDÉ", msg, 3066993, author, commit_msg)
|
send_discord_log("VALIDÉ", msg, 3066993, author, commit_msg)
|
||||||
|
|
||||||
# 2. PM2 (Appelé après le message pour éviter que le kill du serv ne bloque l'envoi)
|
# 3. PM2 (Appelé après le message pour éviter que le kill du serv ne bloque l'envoi)
|
||||||
subprocess.run(f"pm2 restart {PROCESS_NAME}", shell=True, check=True, capture_output=True)
|
subprocess.run(f"pm2 restart {PROCESS_NAME}", shell=True, check=True, capture_output=True)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue