# Gitea Actions - Automatisches Deployment Setup Diese Anleitung zeigt dir, wie du **Gitea Actions** mit einem **Self-hosted Runner** auf deinem Windows VPS einrichtest, um automatische Deployments bei jedem Git Push zu ermöglichen. ## Übersicht **Was wird eingerichtet:** 1. Gitea Actions auf deiner Synology NAS (Gitea Server) 2. Self-hosted Runner auf deinem Windows VPS 3. Automatisches Deployment bei jedem Push auf `main` Branch **Workflow:** ``` [Git Push auf NAS] → [Gitea Webhook] → [Runner auf Windows VPS] → [Deploy Skript ausführen] → [Bot aktualisiert] ``` --- ## TEIL 1: Gitea Actions auf Synology NAS aktivieren ### Schritt 1: Gitea Konfiguration prüfen **Via SSH auf Synology:** ```bash # SSH zur Synology ssh admin@your-synology-ip # Navigiere zu Gitea-Konfiguration # (Pfad variiert je nach Installation) cd /volume1/docker/gitea # ODER cd /var/packages/gitea/target # Finde app.ini find / -name "app.ini" 2>/dev/null | grep gitea ``` ### Schritt 2: Gitea Actions aktivieren **Bearbeite `app.ini`:** ```ini [actions] ENABLED = true DEFAULT_ACTIONS_URL = https://gitea.com ``` **Gitea neustarten:** ```bash # Docker Gitea docker restart gitea # ODER via Synology Package Manager # Stoppe und starte Gitea über die Web-Oberfläche ``` ### Schritt 3: Gitea Actions im Web-UI prüfen 1. Öffne deine Gitea-Instanz im Browser 2. Gehe zu deinem Repository `placeorder` 3. Klicke auf **Settings** → **Actions** 4. Aktiviere Actions für das Repository --- ## TEIL 2: Gitea Runner auf Windows VPS installieren ### Schritt 1: Runner-Binary herunterladen **Öffne PowerShell als Administrator auf deinem Windows VPS:** ```powershell # Erstelle Verzeichnis für Runner New-Item -ItemType Directory -Path "C:\Gitea-Runner" -Force Set-Location "C:\Gitea-Runner" # Download Gitea Runner (Windows AMD64) # Prüfe aktuelle Version: https://dl.gitea.com/act_runner/ $runnerVersion = "0.2.11" # Passe Version an $downloadUrl = "https://dl.gitea.com/act_runner/$runnerVersion/act_runner-$runnerVersion-windows-amd64.exe" Invoke-WebRequest -Uri $downloadUrl -OutFile "act_runner.exe" Write-Host "Gitea Runner downloaded successfully!" -ForegroundColor Green ``` **Alternative: Manueller Download** 1. Gehe zu: https://dl.gitea.com/act_runner/ 2. Wähle neueste Version 3. Download: `act_runner-{version}-windows-amd64.exe` 4. Umbenennen zu `act_runner.exe` 5. Kopiere nach `C:\Gitea-Runner\` ### Schritt 2: Runner registrieren **1. Registration Token von Gitea holen:** Gehe zu deiner Gitea-Instanz: - **Repository Settings** → **Actions** → **Runners** → **Create new Runner** - Kopiere den **Registration Token** **2. Runner registrieren:** ```powershell Set-Location "C:\Gitea-Runner" # Runner registrieren .\act_runner.exe register ` --instance "http://your-synology-ip:3000" ` --token "YOUR_REGISTRATION_TOKEN_HERE" ` --name "windows-vps-runner" ` --labels "windows-latest" # Bei Erfolg wird eine .runner Datei erstellt ``` **Interaktive Fragen während Registration:** - **Runner name:** `windows-vps-runner` - **Runner labels:** `windows-latest` - **Custom labels:** (leer lassen) **Wichtig:** Ersetze: - `your-synology-ip:3000` mit deiner Gitea-URL (z.B. `http://192.168.1.50:3000`) - `YOUR_REGISTRATION_TOKEN_HERE` mit dem Token aus Gitea ### Schritt 3: Runner konfigurieren **Bearbeite `.runner` (optional):** ```bash notepad .runner ``` Standard-Konfiguration ist meist ausreichend. ### Schritt 4: Runner als Windows Service einrichten (EMPFOHLEN) **Mit NSSM (Non-Sucking Service Manager):** **1. NSSM herunterladen:** ```powershell # Download NSSM $nssmUrl = "https://nssm.cc/ci/nssm-2.24-101-g897c7ad.zip" Invoke-WebRequest -Uri $nssmUrl -OutFile "C:\Gitea-Runner\nssm.zip" # Entpacke NSSM Expand-Archive -Path "C:\Gitea-Runner\nssm.zip" -DestinationPath "C:\Gitea-Runner\nssm" # Navigiere zu NSSM Binary Set-Location "C:\Gitea-Runner\nssm\nssm-2.24-101-g897c7ad\win64" ``` **2. Service erstellen:** ```powershell # Service installieren .\nssm.exe install GiteaRunner # Im NSSM GUI konfigurieren: # - Path: C:\Gitea-Runner\act_runner.exe # - Startup directory: C:\Gitea-Runner # - Arguments: daemon ``` **NSSM GUI Konfiguration:** - **Application Tab:** - Path: `C:\Gitea-Runner\act_runner.exe` - Startup directory: `C:\Gitea-Runner` - Arguments: `daemon` - **Details Tab:** - Display name: `Gitea Runner` - Description: `Gitea Actions Self-hosted Runner for Windows VPS` - **Log on Tab:** - Account: Dein Windows User (mit Admin-Rechten) - **I/O Tab:** - Output (stdout): `C:\Gitea-Runner\runner_stdout.log` - Error (stderr): `C:\Gitea-Runner\runner_stderr.log` **3. Service starten:** ```powershell # Service starten Start-Service GiteaRunner # Service Status prüfen Get-Service GiteaRunner # Logs prüfen Get-Content "C:\Gitea-Runner\runner_stdout.log" -Tail 20 ``` **Alternative: Runner manuell starten (nur zum Testen):** ```powershell Set-Location "C:\Gitea-Runner" .\act_runner.exe daemon ``` --- ## TEIL 3: Repository für Deployment vorbereiten ### Schritt 1: Code auf Windows VPS klonen **Auf Windows VPS (PowerShell):** ```powershell # Erstelle TradingBot Verzeichnis New-Item -ItemType Directory -Path "C:\TradingBot" -Force Set-Location "C:\TradingBot" # Git Repository klonen git clone http://your-synology-ip:3000/your-username/placeorder.git # Navigiere ins Repo cd placeorder # Prüfe Status git status ``` **Wichtig:** Ersetze: - `your-synology-ip:3000` mit deiner Gitea-URL - `your-username` mit deinem Gitea-Username ### Schritt 2: Git Credentials speichern (optional) **Damit Git nicht jedes Mal nach Passwort fragt:** ```powershell # Git Credential Helper aktivieren git config --global credential.helper store # Beim nächsten Pull/Push Credentials eingeben git pull # Username: dein-gitea-username # Password: dein-gitea-password # Credentials werden gespeichert ``` **Oder mit SSH Keys (empfohlen):** ```powershell # SSH Key generieren ssh-keygen -t ed25519 -C "your_email@example.com" # Speichere unter: C:\Users\YourUser\.ssh\id_ed25519 # Public Key anzeigen Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub" # Kopiere den Key und füge ihn in Gitea ein: # Gitea → Settings → SSH / GPG Keys → Add Key ``` Dann ändere Remote-URL: ```powershell git remote set-url origin git@your-synology-ip:your-username/placeorder.git ``` --- ## TEIL 4: Testen und Troubleshooting ### Test 1: Workflow manuell triggern 1. Gehe zu Gitea → Repository `placeorder` 2. Klicke auf **Actions** 3. Wähle den Workflow **"Deploy to Windows VPS"** 4. Klicke auf **Run workflow** → **Run** Prüfe die Logs in Echtzeit. ### Test 2: Deployment via Git Push **Auf deinem Mac (oder lokal):** ```bash cd "/Users/sebastianfrohlich/Library/Mobile Documents/com~apple~CloudDocs/Jupyter Notebooks/FinancialTrading/PlaceOrder/placeorder" # Kleine Änderung machen echo "# Test" >> README.md # Commit & Push git add README.md git commit -m "Test: Trigger Gitea Actions" git push origin main ``` **Auf Gitea (Web-UI):** - Gehe zu **Actions** Tab - Du solltest den Workflow laufen sehen **Auf Windows VPS:** - Prüfe Logs: `C:\Gitea-Runner\runner_stdout.log` ### Troubleshooting #### Problem: Runner erscheint nicht in Gitea **Lösung:** ```powershell # Prüfe Runner Service Get-Service GiteaRunner # Prüfe Logs Get-Content "C:\Gitea-Runner\runner_stdout.log" -Tail 50 # Neustart Restart-Service GiteaRunner ``` #### Problem: Workflow startet nicht **Lösung:** 1. Prüfe ob Runner online ist: - Gitea → Repository → Settings → Actions → Runners - Sollte "Online" zeigen 2. Prüfe Workflow-Syntax: - `.gitea/workflows/deploy.yml` auf Syntax-Fehler prüfen 3. Prüfe Labels: - Workflow verwendet `runs-on: windows-latest` - Runner muss Label `windows-latest` haben #### Problem: Git Pull schlägt fehl **Lösung:** ```powershell # Prüfe Git-Konfiguration cd C:\TradingBot\placeorder git remote -v git status # Setze Origin URL neu git remote set-url origin http://your-synology-ip:3000/your-username/placeorder.git # Teste Pull git pull origin main ``` #### Problem: Permission Denied **Lösung:** 1. NSSM Service unter richtigem User-Account laufen lassen 2. User muss Schreibrechte auf `C:\TradingBot\placeorder` haben 3. PowerShell als Administrator ausführen --- ## TEIL 5: Workflow-Anpassungen ### Custom Deployment-Pfade **Falls dein Trading Bot woanders liegt:** Bearbeite `.gitea/workflows/deploy.yml`: ```yaml - name: Deploy to VPS shell: powershell run: | Set-Location "D:\MyCustomPath\placeorder" # Ändere hier git pull origin main .\deploy.ps1 ``` ### Deployment nur auf bestimmten Branches ```yaml on: push: branches: - main - production # Füge weitere Branches hinzu ``` ### Notifications bei Fehler Füge Schritt hinzu: ```yaml - name: Notify on Failure if: failure() shell: powershell run: | # Sende Telegram-Nachricht oder Email Write-Host "Deployment failed! Sending notification..." -ForegroundColor Red # Dein Notification-Code hier ``` --- ## Checkliste - [ ] Gitea Actions auf Synology aktiviert - [ ] Gitea Runner Binary heruntergeladen (`C:\Gitea-Runner\act_runner.exe`) - [ ] Runner registriert mit Gitea - [ ] Runner als Windows Service installiert (NSSM) - [ ] Service läuft (`Get-Service GiteaRunner` zeigt "Running") - [ ] Repository auf Windows VPS geklont (`C:\TradingBot\placeorder`) - [ ] Git Credentials konfiguriert (Store oder SSH) - [ ] Workflow-Datei committed (`.gitea/workflows/deploy.yml`) - [ ] Deployment-Skript vorhanden (`deploy.ps1`) - [ ] Test-Push durchgeführt und Workflow erfolgreich - [ ] Runner erscheint als "Online" in Gitea --- ## Nützliche Befehle **Windows VPS (PowerShell):** ```powershell # Runner Status Get-Service GiteaRunner Get-Content "C:\Gitea-Runner\runner_stdout.log" -Tail 50 # Runner neustarten Restart-Service GiteaRunner # Deployment manuell triggern cd C:\TradingBot\placeorder git pull origin main .\deploy.ps1 # Prozesse prüfen Get-Process | Where-Object {$_.ProcessName -like "*act_runner*"} ``` **Synology NAS:** ```bash # Gitea Logs prüfen docker logs gitea -f # Gitea neustarten docker restart gitea ``` --- ## Weiterführende Links - **Gitea Actions Docs:** https://docs.gitea.com/next/usage/actions/overview - **Act Runner Releases:** https://dl.gitea.com/act_runner/ - **NSSM Download:** https://nssm.cc/download --- ## Support & Hilfe Bei Problemen: 1. Prüfe Runner-Logs: `C:\Gitea-Runner\runner_stdout.log` 2. Prüfe Workflow-Logs in Gitea Web-UI (Actions Tab) 3. Prüfe Windows Event Viewer für Service-Fehler --- Du bist jetzt bereit für automatische Deployments! Bei jedem `git push` wird dein Trading Bot auf dem Windows VPS automatisch aktualisiert.