Fix webhook deployment endpoint - use local script

This commit is contained in:
oguz ozturk 2026-01-10 15:36:22 +03:00
parent f54467436a
commit de9963c702
1 changed files with 28 additions and 13 deletions

View File

@ -162,31 +162,46 @@ def webhook_deploy():
"""Gitea webhook for auto-deployment"""
import subprocess
import os
from datetime import datetime
# Verify webhook (optional: add secret validation)
data = request.json
# Get webhook data
data = request.json or {}
# Log webhook event
print(f"📥 Webhook received: {data.get('repository', {}).get('name', 'unknown')}")
repo_name = data.get('repository', {}).get('name', 'unknown')
pusher = data.get('pusher', {}).get('username', 'unknown')
# Trigger deployment script
print(f"📥 Webhook received from {repo_name} by {pusher} at {datetime.now()}")
# Trigger deployment script in background
try:
result = subprocess.run(
['/opt/hosting-platform/deploy.sh'],
capture_output=True,
text=True,
timeout=300
# Run deployment script asynchronously
process = subprocess.Popen(
['/opt/hosting-platform/deploy-local.sh'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# Don't wait for completion, return immediately
return jsonify({
"status": "success",
"message": "Deployment triggered",
"output": result.stdout
})
"message": "Deployment triggered successfully",
"repository": repo_name,
"pusher": pusher,
"timestamp": datetime.now().isoformat(),
"note": "Check /var/log/auto-deploy.log for deployment progress"
}), 202 # 202 Accepted
except FileNotFoundError:
return jsonify({
"status": "error",
"message": "Deployment script not found at /opt/hosting-platform/deploy-local.sh"
}), 500
except Exception as e:
return jsonify({
"status": "error",
"message": str(e)
"message": f"Failed to trigger deployment: {str(e)}"
}), 500