-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.ps1
More file actions
28 lines (21 loc) · 1.28 KB
/
deploy.ps1
File metadata and controls
28 lines (21 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env pwsh
# deploy.ps1 — Build e deploy da Discovery API no servidor de produção
# Uso: .\deploy.ps1
$ErrorActionPreference = "Stop"
$Server = "root@192.168.1.148"
$RemoteDir = "/opt/discovery-api"
$Project = "src/Discovery.Api/Discovery.Api.csproj"
$OutDir = "artifacts/publish/discovery-api"
$Service = "discovery-api"
Write-Host "==> [1/3] Publicando para linux-x64..." -ForegroundColor Cyan
dotnet publish $Project -c Release -r linux-x64 --self-contained false -o $OutDir /p:UseAppHost=true
if ($LASTEXITCODE -ne 0) { Write-Error "Publish falhou."; exit 1 }
# Remove appsettings do artefato para nao sobrescrever a config do servidor
Remove-Item -Force -ErrorAction SilentlyContinue "$OutDir/appsettings.json", "$OutDir/appsettings.*.json"
Write-Host "==> [2/3] Copiando arquivos para $Server`:$RemoteDir ..." -ForegroundColor Cyan
scp -r "$OutDir/*" "${Server}:${RemoteDir}/"
if ($LASTEXITCODE -ne 0) { Write-Error "Copia falhou."; exit 1 }
Write-Host "==> [3/3] Reiniciando servico $Service ..." -ForegroundColor Cyan
ssh $Server "chmod +x $RemoteDir/Discovery.Api; systemctl restart $Service; sleep 3; systemctl is-active $Service"
if ($LASTEXITCODE -ne 0) { Write-Error "Reinicio falhou."; exit 1 }
Write-Host "==> Deploy concluido com sucesso!" -ForegroundColor Green