Fix webhook deployment endpoint - use local script
This commit is contained in:
parent
f54467436a
commit
de9963c702
|
|
@ -162,31 +162,46 @@ def webhook_deploy():
|
||||||
"""Gitea webhook for auto-deployment"""
|
"""Gitea webhook for auto-deployment"""
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
# Verify webhook (optional: add secret validation)
|
# Get webhook data
|
||||||
data = request.json
|
data = request.json or {}
|
||||||
|
|
||||||
# Log webhook event
|
# 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:
|
try:
|
||||||
result = subprocess.run(
|
# Run deployment script asynchronously
|
||||||
['/opt/hosting-platform/deploy.sh'],
|
process = subprocess.Popen(
|
||||||
capture_output=True,
|
['/opt/hosting-platform/deploy-local.sh'],
|
||||||
text=True,
|
stdout=subprocess.PIPE,
|
||||||
timeout=300
|
stderr=subprocess.PIPE,
|
||||||
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Don't wait for completion, return immediately
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"message": "Deployment triggered",
|
"message": "Deployment triggered successfully",
|
||||||
"output": result.stdout
|
"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:
|
except Exception as e:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"status": "error",
|
"status": "error",
|
||||||
"message": str(e)
|
"message": f"Failed to trigger deployment: {str(e)}"
|
||||||
}), 500
|
}), 500
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue