Simplify webhook to use direct git pull

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-10 12:10:18 +00:00
parent b7e6c25080
commit 869b41b84d
2 changed files with 27 additions and 20 deletions

View File

@@ -530,28 +530,32 @@ def gitea_webhook(request):
logger.info(f"[Webhook] Processing push: {commit_count} commit(s) by {pusher} to {repo_full_name}") logger.info(f"[Webhook] Processing push: {commit_count} commit(s) by {pusher} to {repo_full_name}")
# Pull latest code - run git pull directly in the mounted repo # Pull latest code - trigger systemd service on host
try: try:
import subprocess import socket
logger.info(f"[Webhook] Pulling latest code...") logger.info(f"[Webhook] Triggering git pull...")
result = subprocess.run( sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
['git', '-C', '/data/app/igny8', 'config', '--global', '--add', 'safe.directory', '/data/app/igny8'], sock.settimeout(5)
capture_output=True, sock.connect(('127.0.0.1', 9999))
text=True, sock.close()
timeout=5 logger.info(f"[Webhook] Git pull triggered successfully")
)
result = subprocess.run(
['git', '-C', '/data/app/igny8', 'pull', 'origin', 'main'],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
logger.info(f"[Webhook] Git pull successful: {result.stdout}")
else:
logger.error(f"[Webhook] Git pull failed: {result.stderr}")
except Exception as e: except Exception as e:
logger.error(f"[Webhook] Git pull error: {e}") logger.error(f"[Webhook] Failed to trigger git pull: {e}")
# Fallback: try direct git pull
try:
import subprocess
result = subprocess.run(
['git', '-C', '/data/app/igny8', 'pull', 'origin', 'main'],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
logger.info(f"[Webhook] Git pull successful (fallback)")
else:
logger.error(f"[Webhook] Git pull failed: {result.stderr}")
except Exception as e2:
logger.error(f"[Webhook] Fallback git pull also failed: {e2}")
# Trigger deployment - restart containers # Trigger deployment - restart containers
deployment_success = False deployment_success = False

3
scripts/auto-pull.sh Normal file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
cd /data/app/igny8
git pull origin main