Repository navigation
Expand file tree
/
Copy pathdocker-start.ps1
More file actions
127 lines (116 loc) · 4.21 KB
/
Copy pathdocker-start.ps1
File metadata and controls
127 lines (116 loc) · 4.21 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Write-Host "========================================"
Write-Host " Docker Smart Launcher"
Write-Host "========================================"
Write-Host ""
# ── [1/3] Network check ──────────────────────────
Write-Host "[1/3] Checking network environment..."
Write-Host "Testing Docker Hub connectivity..."
docker pull hello-world:latest --quiet 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
Write-Host "[OK] Docker Hub is reachable"
Write-Host "[2/3] Using Docker Hub official registry..."
$registryPrefix = ""
} else {
Write-Host "[FAIL] Docker Hub unreachable"
Write-Host "[2/3] Switching to dockerproxy.com mirror..."
$registryPrefix = "dockerproxy.com/library/"
}
# ── [3/3] Launch options ─────────────────────────
Write-Host ""
Write-Host "[3/3] Launch options"
Write-Host "========================================"
Write-Host " [1] Quick start (no rebuild)"
Write-Host " [2] Full build (--build)"
Write-Host " [3] Auto detect (build only if image missing)"
Write-Host "========================================"
Write-Host ""
$choice = Read-Host "Select option (1/2/3) [default: 1]"
if ($choice -eq "") { $choice = "1" }
Write-Host ""
# ── Determine compose args ────────────────────────
function Get-NeedsBuild {
$b = docker images -q codepulse-backend 2>$null
$f = docker images -q codepulse-frontend 2>$null
return (-not $b -or -not $f)
}
# ── Build sandbox image (not in compose, must be built separately) ──
$sandboxImg = docker images -q codepulse-sandbox 2>$null
if (-not $sandboxImg) {
Write-Host "[INFO] codepulse-sandbox image not found, building..."
docker build -t codepulse-sandbox -f backend/docker/Dockerfile backend/
if ($LASTEXITCODE -ne 0) {
Write-Host "[FAIL] Failed to build codepulse-sandbox"
Read-Host "Press Enter to exit"
exit 1
}
Write-Host "[OK] codepulse-sandbox built"
} else {
Write-Host "[OK] codepulse-sandbox image exists"
}
$buildFlag = switch ($choice) {
"1" {
Write-Host ">> docker compose up"
$false
}
"2" {
Write-Host ">> Rebuilding codepulse-sandbox..."
docker build -t codepulse-sandbox -f backend/docker/Dockerfile backend/
Write-Host ">> docker compose up --build"
$true
}
"3" {
Write-Host "Checking image status..."
if (Get-NeedsBuild) {
Write-Host "[WARN] Image missing, build required"
Write-Host ">> docker compose up --build"
$true
} else {
Write-Host "[OK] Images exist, quick start"
Write-Host "Note: select [2] if Dockerfile or dependencies changed"
Write-Host ">> docker compose up"
$false
}
}
default {
Write-Host "[WARN] Invalid option, falling back to auto detect"
Get-NeedsBuild
}
}
Write-Host ""
# ── Run (try/finally catches Ctrl+C) ─────────────
try {
if ($buildFlag) {
docker compose up --build
} else {
docker compose up
}
} finally {
Write-Host ""
Write-Host "========================================"
Write-Host "Service stopped or interrupted"
Write-Host "========================================"
Write-Host ""
$downChoice = Read-Host "Run 'docker compose down' to clean up? (y/N)"
if ($downChoice -ieq "y") {
Write-Host ""
Write-Host ">> docker compose down"
docker compose down
if ($LASTEXITCODE -eq 0) {
Write-Host "[OK] Containers removed"
} else {
Write-Host "[FAIL] docker compose down failed"
}
$poolIds = docker ps -aq --filter "label=codepulse-pool=1"
if ($poolIds) {
Write-Host ">> Removing sandbox pool containers..."
docker rm -f $poolIds
Write-Host "[OK] Pool containers removed"
}
} else {
Write-Host ""
Write-Host "Containers kept. Run 'docker compose down' manually when done."
}
Write-Host ""
Write-Host "========================================"
Read-Host "Press Enter to exit"
}