Files
Place-Order-Trading-Bot/deploy.ps1
T
cbazza 17e6fb83e5
Deploy to Windows VPS / deploy (push) Has been cancelled
added GITEA Actions and setup
2025-12-17 08:34:55 +01:00

163 lines
5.8 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ========================================
# Trading Bot Deployment Script
# Windows VPS Deployment Automation
# ========================================
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Trading Bot Deployment Script v1.0" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Deployment-Verzeichnis
$deployPath = "C:\TradingBot\placeorder"
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$backupPath = "C:\TradingBot\backups\backup_$timestamp"
# ========================================
# SCHRITT 1: Backup erstellen
# ========================================
Write-Host "[1/5] Creating backup..." -ForegroundColor Yellow
# Erstelle Backup-Verzeichnis falls nicht vorhanden
if (!(Test-Path "C:\TradingBot\backups")) {
New-Item -ItemType Directory -Path "C:\TradingBot\backups" -Force | Out-Null
}
# Backup kritischer Dateien
$filesToBackup = @(
"trading_bot.db",
"telegram_config.json"
)
New-Item -ItemType Directory -Path $backupPath -Force | Out-Null
foreach ($file in $filesToBackup) {
if (Test-Path $file) {
Copy-Item $file -Destination "$backupPath\$file" -Force
Write-Host " ✓ Backed up: $file" -ForegroundColor Green
}
}
Write-Host " ✓ Backup created at: $backupPath" -ForegroundColor Green
Write-Host ""
# ========================================
# SCHRITT 2: Git Pull (bereits von Workflow erledigt)
# ========================================
Write-Host "[2/5] Verifying Git repository..." -ForegroundColor Yellow
if (Test-Path ".git") {
$branch = git rev-parse --abbrev-ref HEAD
$commit = git rev-parse --short HEAD
Write-Host " ✓ Branch: $branch" -ForegroundColor Green
Write-Host " ✓ Commit: $commit" -ForegroundColor Green
} else {
Write-Host " ✗ No Git repository found!" -ForegroundColor Red
exit 1
}
Write-Host ""
# ========================================
# SCHRITT 3: Python Dependencies prüfen/aktualisieren
# ========================================
Write-Host "[3/5] Checking Python dependencies..." -ForegroundColor Yellow
# Prüfe ob requirements.txt existiert
if (Test-Path "requirements.txt") {
Write-Host " Installing/Updating dependencies from requirements.txt..." -ForegroundColor Cyan
pip install --upgrade -r requirements.txt --quiet
if ($LASTEXITCODE -eq 0) {
Write-Host " ✓ Dependencies installed successfully" -ForegroundColor Green
} else {
Write-Host " ⚠ Some dependencies might have failed" -ForegroundColor Yellow
}
} else {
Write-Host " No requirements.txt found, installing common packages..." -ForegroundColor Cyan
pip install --upgrade streamlit plotly pandas MetaTrader5 --quiet
Write-Host " ✓ Common packages installed" -ForegroundColor Green
}
Write-Host ""
# ========================================
# SCHRITT 4: Services neu starten
# ========================================
Write-Host "[4/5] Restarting services..." -ForegroundColor Yellow
# Trading Dashboard Service
$dashboardService = Get-Service -Name "TradingDashboard" -ErrorAction SilentlyContinue
if ($dashboardService) {
Write-Host " Restarting TradingDashboard service..." -ForegroundColor Cyan
Restart-Service -Name "TradingDashboard" -Force
Start-Sleep -Seconds 3
$status = (Get-Service -Name "TradingDashboard").Status
if ($status -eq "Running") {
Write-Host " ✓ TradingDashboard is running" -ForegroundColor Green
} else {
Write-Host " ✗ TradingDashboard failed to start!" -ForegroundColor Red
}
} else {
Write-Host " TradingDashboard service not installed (manual start required)" -ForegroundColor Yellow
}
# Optional: Prozesse neustarten falls kein Service installiert
$streamlitProcesses = Get-Process | Where-Object {$_.ProcessName -like "*streamlit*"}
if ($streamlitProcesses) {
Write-Host " Found running Streamlit processes, restarting..." -ForegroundColor Cyan
$streamlitProcesses | Stop-Process -Force
Start-Sleep -Seconds 2
# Starte Streamlit neu (im Hintergrund)
Start-Process powershell -ArgumentList "-NoExit", "-Command", "cd '$deployPath'; streamlit run trading_dashboard.py --server.port 8501 --server.address 0.0.0.0" -WindowStyle Minimized
Write-Host " ✓ Streamlit restarted" -ForegroundColor Green
}
Write-Host ""
# ========================================
# SCHRITT 5: Deployment-Verifikation
# ========================================
Write-Host "[5/5] Verifying deployment..." -ForegroundColor Yellow
$criticalFiles = @(
"TradingBot_V1.6_Adaptive_Complete_CORRECTED.ipynb",
"trading_dashboard.py",
"trading_database.py"
)
$allFilesExist = $true
foreach ($file in $criticalFiles) {
if (Test-Path $file) {
Write-Host " ✓ $file" -ForegroundColor Green
} else {
Write-Host " ✗ $file missing!" -ForegroundColor Red
$allFilesExist = $false
}
}
Write-Host ""
# ========================================
# DEPLOYMENT SUMMARY
# ========================================
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " DEPLOYMENT SUMMARY" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
if ($allFilesExist) {
Write-Host "Status: SUCCESS" -ForegroundColor Green
Write-Host "Timestamp: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" -ForegroundColor White
Write-Host "Backup Location: $backupPath" -ForegroundColor White
Write-Host "Dashboard URL: http://localhost:8501" -ForegroundColor Cyan
Write-Host ""
Write-Host "✓ Deployment completed successfully!" -ForegroundColor Green
exit 0
} else {
Write-Host "Status: FAILED" -ForegroundColor Red
Write-Host "Some critical files are missing!" -ForegroundColor Red
Write-Host "Check the logs above for details." -ForegroundColor Yellow
exit 1
}