====== Coolify API Guide - Automatisches Deployment ====== Diese Anleitung beschreibt die Nutzung der Coolify API für automatisierte Deployments der Telegram-Bots. ===== Übersicht ===== **Coolify Instanz:** https://app.coolify.io **API Version:** v1 **Authentifizierung:** Bearer Token ===== Authentifizierung ===== ==== API Token ==== Das API Token wird in den Benutzereinstellungen von Coolify generiert: - Einloggen auf https://app.coolify.io - Settings → API - „Generate New Token" klicken - Token kopieren und sicher speichern - **Token niemals öffentlich teilen!** ==== API Requests ==== Alle API-Requests benötigen den Header: Authorization: Bearer $COOLIFY_API_TOKEN Content-Type: application/json **Hinweis:** Das Token sollte als Umgebungsvariable ($COOLIFY_API_TOKEN) gespeichert werden, niemals hardcoded. ===== Wichtige Endpoints ===== ==== 1. Projekt-Übersicht ==== GET /api/v1/projects **Beispiel:** curl -s "https://app.coolify.io/api/v1/projects" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Content-Type: application/json" **Response:** [ { "id": 1038, "uuid": "bso4sss", "name": "Anti Spam ohne Vornamenprüfung" } ] ==== 2. Application Deploy ==== POST /api/v1/applications/{uuid}/restart **Beispiel - AntiSpam-ohneVorname:** # Application UUID: x4wco4k curl -s -X POST \ "https://app.coolify.io/api/v1/applications/x4wco4k/restart" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Content-Type: application/json" **Response:** { "message": "Restart request queued", "deployment_uuid": "..." } ==== 3. Deployment Status prüfen ==== GET /api/v1/deployments/{uuid} **Beispiel:** curl -s \ "https://app.coolify.io/api/v1/deployments/DEPLOYMENT_UUID" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Content-Type: application/json" | \ python3 -m json.tool ===== Wichtige Application UUIDs ===== ^ Bot ^ Application UUID ^ Projekt ID ^ | Anti Spam ohne Vornamenprüfung | ''x4wco4k'' | 1038 | | AntiSpamBot Recode V2.0 | ''uokcw80'' | - | | AntiSpamMessageScanBot | ''wgcs8ss'' | - | | Anti Deleted Account System | ''bsosk48'' | 834 | **Eigene UUIDs finden:** curl -s "https://app.coolify.io/api/v1/applications" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Content-Type: application/json" | \ python3 -c "import sys,json; [print(f\"{a['name']}: {a['uuid']}\") for a in json.load(sys.stdin)]" ===== Automatisierung mit Git Webhooks ===== ==== Gitea Webhook einrichten ==== **URL:** https://git.thepain.dev/ThePain/AntiSpam-ohneVorname/settings/hooks **Konfiguration:** - **Target URL:** https://app.coolify.io/api/v1/applications/x4wco4k/restart - **HTTP Method:** POST - **Content Type:** application/json - **Events:** Push Events - **Branch Filter:** main - **Is Active:** ✅ Ja **Wichtig:** Der Webhook benötigt KEIN Bearer Token, da Coolify den Request intern verarbeitet. ==== Shell Script für manuelles Deploy ==== #!/bin/bash # deploy-bot.sh - Manuelles Deployment eines Bots # Benötigt: COOLIFY_API_TOKEN als Umgebungsvariable APPLICATION_UUID="$1" # z.B. x4wco4k if [ -z "$COOLIFY_API_TOKEN" ]; then echo "❌ Fehler: COOLIFY_API_TOKEN nicht gesetzt" echo "export COOLIFY_API_TOKEN='dein-token-hier'" exit 1 fi if [ -z "$APPLICATION_UUID" ]; then echo "Usage: $0 " echo "Beispiel: $0 x4wco4k" exit 1 fi echo "Starting deployment for $APPLICATION_UUID..." RESPONSE=$(curl -s -X POST \ "https://app.coolify.io/api/v1/applications/$APPLICATION_UUID/restart" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Content-Type: application/json") DEPLOYMENT_UUID=$(echo $RESPONSE | python3 -c "import sys,json; print(json.load(sys.stdin)['deployment_uuid'])") echo "Deployment queued: $DEPLOYMENT_UUID" # Warte auf Abschluss (optional) echo "Warte auf Deployment..." for i in {1..30}; do STATUS=$(curl -s \ "https://app.coolify.io/api/v1/deployments/$DEPLOYMENT_UUID" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Content-Type: application/json" | \ python3 -c "import sys,json; print(json.load(sys.stdin)['status'])") echo "Status: $STATUS" if [ "$STATUS" = "finished" ]; then echo "✅ Deployment erfolgreich!" exit 0 elif [ "$STATUS" = "failed" ]; then echo "❌ Deployment fehlgeschlagen!" exit 1 fi sleep 5 done echo "⚠️ Timeout - prüfe manuell in Coolify Dashboard" ===== Fehlerbehebung ===== ==== 401 Unauthorized ==== - Token ist abgelaufen → Neu generieren in Coolify Settings - Token falsch kopiert → Nochmal prüfen - Umgebungsvariable nicht gesetzt → ''export COOLIFY_API_TOKEN=...'' ==== 404 Not Found ==== - Application UUID falsch → Mit ''/api/v1/applications'' prüfen - Projekt existiert nicht mehr ==== Deployment Failed ==== - Logs in Coolify Dashboard prüfen - Häufige Ursachen: * Git nicht erreichbar * Docker Build Fehler * Environment Variables fehlen ===== Sicherheitshinweise ===== ==== Token-Schutz ==== - **Niemals** das Token im Code hardcoden - **Niemals** das Token in öffentlichen Repositories committen - **Niemals** das Token in öffentlichen Wikis posten - Verwende immer Umgebungsvariablen - Lokal: ''export COOLIFY_API_TOKEN="..."'' in ''~/.bashrc'' oder ''~/.zshrc'' - CI/CD: Verwende Secrets/Environment Variables ==== Token erneuern ==== Falls das Token kompromittiert wurde: 1. In Coolify: Settings → API → Token löschen 2. Neuen Token generieren 3. Alte Umgebungsvariablen aktualisieren ---- **Letzte Aktualisierung:** 2026-02-17\\ **Autor:** Klaus 🦞\\ **Hinweis:** Diese Anleitung enthält **keine** sensible Daten. Token müssen lokal gesetzt werden.