Fix:auto-déploiement & commentaire gitlab
This commit is contained in:
parent
ca5c966c9c
commit
ed6e25c219
3 changed files with 38 additions and 10 deletions
|
|
@ -1,11 +1,15 @@
|
|||
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 datetime import datetime, timezone
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# --- CONFIGURATION ---
|
||||
PROJECT_PATH = "/home/discord/Bot/Kuby_V2"
|
||||
PROJECT_PATH = "/home/discord/Bot/Kuby"
|
||||
WEBHOOK_SECRET = "Nois2"
|
||||
PROCESS_NAME = "kuby"
|
||||
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)
|
||||
|
||||
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
|
||||
subprocess.run(["git", "fetch", "origin"], 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()
|
||||
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)
|
||||
|
||||
# 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)
|
||||
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue