feat: Add webhook endpoint for auto-deploy on git push

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
eric 2026-02-21 17:38:00 +00:00
parent c3438beed1
commit 5b4b698064
2 changed files with 24 additions and 0 deletions

View file

@ -2,6 +2,7 @@
# App Login Password # App Login Password
# ───────────────────────────────────────────────────────────────────────────── # ─────────────────────────────────────────────────────────────────────────────
APP_PASSWORD=change-me APP_PASSWORD=change-me
DEPLOY_SECRET=your-webhook-secret
# Email Integration Configuration # Email Integration Configuration
# Gmail Example: # Gmail Example:

23
app.py
View file

@ -405,6 +405,7 @@ app.permanent_session_lifetime = timedelta(days=7)
# ── App Password ───────────────────────────────────────────────────────────── # ── App Password ─────────────────────────────────────────────────────────────
APP_PASSWORD = os.getenv('APP_PASSWORD', '') APP_PASSWORD = os.getenv('APP_PASSWORD', '')
DEPLOY_SECRET = os.getenv('DEPLOY_SECRET', '')
def login_required(f): def login_required(f):
@wraps(f) @wraps(f)
@ -3335,6 +3336,28 @@ def distribute_tasks():
}) })
@app.route('/api/webhook/deploy', methods=['POST'])
def webhook_deploy():
"""Gitea Webhook: git pull + restart service on push to main."""
if not DEPLOY_SECRET:
return jsonify({'error': 'Deploy not configured'}), 403
# Verify secret from Gitea webhook
token = request.headers.get('Authorization', '').replace('Bearer ', '')
if not token:
# Gitea can also send secret in payload
data = request.get_json(silent=True) or {}
token = data.get('secret', '')
if token != DEPLOY_SECRET:
return jsonify({'error': 'Invalid secret'}), 403
# Run git pull, then restart service in background (detached so response returns first)
repo_dir = os.path.dirname(os.path.abspath(__file__))
subprocess.Popen(
['bash', '-c', f'cd {repo_dir} && git pull && sleep 1 && sudo systemctl restart frankenbot'],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
return jsonify({'success': True, 'message': 'Deploy triggered'})
def init_default_team_members(): def init_default_team_members():
"""Fügt Standard-Team-Members hinzu, falls keine existieren.""" """Fügt Standard-Team-Members hinzu, falls keine existieren."""
existing = get_team_members(active_only=False) existing = get_team_members(active_only=False)