flnxi-Wu/scripts/deploy/rebuild-and-restart.ps1
WuYongJie f646b71813
Some checks failed
CI Check / check (push) Has been cancelled
chore: 初始化本地仓库并同步最近改动
2025-11-18 17:50:16 +08:00

48 lines
1.6 KiB
PowerShell

# Rebuild and restart containers with latest code
param(
[string]$Server = "45.249.208.118",
[string]$User = "root",
[string]$Password = "lxvhNYFZ4160",
[string]$ProjectPath = "/root/youyidian-3d"
)
$plinkPath = "C:\Program Files\PuTTY\plink.exe"
Write-Host "Rebuilding and restarting containers..." -ForegroundColor Yellow
Write-Host "This may take several minutes..." -ForegroundColor Gray
Write-Host ""
# Stop and remove containers
Write-Host "1. Stopping containers..." -ForegroundColor Cyan
$cmd = "cd $ProjectPath; docker compose down"
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" $cmd
Write-Host ""
# Rebuild and start
Write-Host "2. Rebuilding and starting containers..." -ForegroundColor Cyan
$cmd = "cd $ProjectPath; docker compose up -d --build --force-recreate 2>&1"
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" $cmd
Write-Host ""
# Wait for startup
Write-Host "3. Waiting for containers to start..." -ForegroundColor Cyan
Start-Sleep -Seconds 10
# Check status
Write-Host "4. Checking container status..." -ForegroundColor Cyan
$cmd = "cd $ProjectPath; docker compose ps"
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" $cmd
Write-Host ""
# Check logs
Write-Host "5. Application logs (last 30 lines):" -ForegroundColor Cyan
$cmd = "cd $ProjectPath; docker compose logs app --tail=30 2>&1"
& $plinkPath -ssh -pw $Password -batch "${User}@${Server}" $cmd
Write-Host ""
Write-Host "Rebuild complete!" -ForegroundColor Green
Write-Host ""
Write-Host "Application should be running at:" -ForegroundColor Yellow
Write-Host " http://45.249.208.118:4320" -ForegroundColor White
Write-Host ""