-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathdeploy.ps1
More file actions
101 lines (86 loc) · 3.45 KB
/
Copy pathdeploy.ps1
File metadata and controls
101 lines (86 loc) · 3.45 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# JobSync Deployment Script (Windows / PowerShell)
# Usage: .\deploy.ps1 [branch-name]
# Example: .\deploy.ps1 main
# Example: .\deploy.ps1 develop
#
# PowerShell equivalent of deploy.sh, for Windows hosts without WSL/Git Bash.
# Requires: Docker Desktop and Git for Windows.
param([string]$Branch = "main")
$ErrorActionPreference = "Stop"
# We check $LASTEXITCODE for native commands, so don't let them auto-throw
# (PowerShell 7.3+ would otherwise abort the reachability retry loop).
$PSNativeCommandUseErrorActionPreference = $false
function Assert-LastExit($msg) {
if ($LASTEXITCODE -ne 0) {
Write-Host $msg -ForegroundColor Red
exit $LASTEXITCODE
}
}
Write-Host "========================================" -ForegroundColor Yellow
Write-Host "JobSync Deployment Script" -ForegroundColor Yellow
Write-Host "========================================" -ForegroundColor Yellow
Write-Host ""
Set-Location -Path $PSScriptRoot
Write-Host "[1/5] Current directory: $PSScriptRoot" -ForegroundColor Green
Write-Host ""
# Detect Docker Compose (v2 plugin or v1 standalone)
docker compose version *> $null
$UseV2 = ($LASTEXITCODE -eq 0)
if (-not $UseV2) {
docker-compose version *> $null
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Docker Compose not found" -ForegroundColor Red
exit 1
}
}
function Compose {
if ($UseV2) { & docker compose @args } else { & docker-compose @args }
}
Write-Host "Using: $(if ($UseV2) { 'docker compose' } else { 'docker-compose' })" -ForegroundColor Yellow
Write-Host ""
if (-not (Test-Path ".git")) {
Write-Host "Error: Not a git repository" -ForegroundColor Red
exit 1
}
Write-Host "[2/5] Fetching latest changes from GitHub..." -ForegroundColor Green
git fetch origin
Assert-LastExit "git fetch failed"
Write-Host "[3/5] Checking out branch: $Branch" -ForegroundColor Green
git checkout $Branch
Assert-LastExit "git checkout failed"
git pull origin $Branch
Assert-LastExit "git pull failed"
Write-Host "[4/5] Stopping existing containers..." -ForegroundColor Green
Compose down
Assert-LastExit "docker compose down failed"
Write-Host "[5/5] Pulling latest images and starting containers..." -ForegroundColor Green
Compose pull
Assert-LastExit "docker compose pull failed"
Compose up -d --force-recreate
Assert-LastExit "docker compose up failed"
# Poll the app until it actually responds, so the success message below only
# prints once the app is reachable in a browser — not just "container started".
# The probe runs inside the container (busybox wget is always in the image),
# so the only host dependency is Docker itself. The loop exits the instant the
# app answers; the 5-minute deadline is only a ceiling for a boot that never
# comes up.
Write-Host "Waiting for app to become reachable..." -ForegroundColor Yellow
$deadline = (Get-Date).AddMinutes(5)
while ($true) {
Compose exec -T app wget --spider -q http://127.0.0.1:3737 *> $null
if ($LASTEXITCODE -eq 0) { break }
if ((Get-Date) -ge $deadline) {
Write-Host "App did not become reachable within 5 minutes." -ForegroundColor Red
Compose logs --tail=40
exit 1
}
Start-Sleep -Seconds 2
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Green
Write-Host "Deployment completed successfully!" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green
Write-Host ""
Write-Host "Branch: $Branch" -ForegroundColor Yellow
Write-Host ""
Compose ps