Skip to content

Commit e5db912

Browse files
committed
add startup scripts for automated Docker setup on macOS/Linux and Windows
1 parent a6fd2ea commit e5db912

2 files changed

Lines changed: 178 additions & 2 deletions

File tree

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,40 @@ Harmonia is built as a Java/Spring-based monolith, prioritizing stability and jo
4747

4848
## 🐳 Run Harmonia with Docker
4949

50+
### Quick Start with Startup Scripts
51+
52+
Use the provided startup scripts for an automated setup:
53+
54+
**macOS/Linux:**
55+
```bash
56+
./start.sh
57+
```
58+
59+
**Windows (PowerShell):**
60+
```powershell
61+
.\start.ps1
62+
```
63+
64+
The scripts will:
65+
- Check if Docker is running
66+
- Clean up any existing containers
67+
- Build and start all services (database, server, client)
68+
- Wait for services to be ready
69+
- Display access URLs and helpful commands
70+
5071
### Full stack (database + server + client)
5172

52-
1. Build and launch everything:
73+
Alternatively, you can manually build and launch everything:
74+
75+
Alternatively, you can manually build and launch everything:
76+
77+
1. Build and launch:
5378

5479
```bash
5580
docker compose -f docker/docker-compose.yml up --build
5681
```
5782

58-
3. Access the services:
83+
2. Access the services:
5984
* Client (served by nginx): http://localhost:5173
6085
* Spring Boot server: http://localhost:8080
6186
* PostgreSQL: localhost:5432 (user `postgres`, password `harmonia`)

start.ps1

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# Harmonia Startup Script (Windows PowerShell)
2+
# This script starts all services using Docker containers
3+
4+
$ErrorActionPreference = "Stop"
5+
6+
# Colors for output
7+
function Write-Green { Write-Host $args -ForegroundColor Green }
8+
function Write-Blue { Write-Host $args -ForegroundColor Blue }
9+
function Write-Yellow { Write-Host $args -ForegroundColor Yellow }
10+
function Write-Red { Write-Host $args -ForegroundColor Red }
11+
12+
Write-Blue "========================================"
13+
Write-Blue " Starting Harmonia Application"
14+
Write-Blue " (Containerized Version)"
15+
Write-Blue "========================================"
16+
Write-Host ""
17+
18+
# Step 1: Check Docker is running
19+
Write-Green "[1/4] Checking Docker..."
20+
try {
21+
docker info | Out-Null
22+
Write-Green "✓ Docker is running"
23+
Write-Host ""
24+
} catch {
25+
Write-Red "✗ Docker is not running. Please start Docker Desktop."
26+
exit 1
27+
}
28+
29+
# Step 2: Clean up any existing containers
30+
Write-Green "[2/4] Cleaning up existing containers..."
31+
docker compose -f docker/docker-compose.yml down --remove-orphans 2>$null
32+
Write-Green "✓ Cleanup completed"
33+
Write-Host ""
34+
35+
# Step 3: Build and start all services
36+
Write-Green "[3/4] Building and starting all services..."
37+
Write-Yellow "This may take several minutes for the first run..."
38+
Write-Yellow "Building Docker images and starting containers..."
39+
Write-Host ""
40+
41+
docker compose -f docker/docker-compose.yml up --build -d
42+
43+
if ($LASTEXITCODE -eq 0) {
44+
Write-Green "✓ All services started successfully"
45+
Write-Host ""
46+
} else {
47+
Write-Red "✗ Failed to start services"
48+
Write-Yellow "Check logs with: docker compose -f docker/docker-compose.yml logs"
49+
exit 1
50+
}
51+
52+
# Step 4: Wait for services to be ready
53+
Write-Green "[4/4] Waiting for services to be ready..."
54+
Write-Yellow "Checking service health..."
55+
56+
# Wait for postgres to be healthy
57+
Write-Yellow "• Waiting for PostgreSQL..."
58+
$timeout = 60
59+
$postgresReady = $false
60+
while ($timeout -gt 0) {
61+
$status = docker compose -f docker/docker-compose.yml ps postgres 2>$null | Select-String "healthy"
62+
if ($status) {
63+
Write-Green " ✓ PostgreSQL is ready"
64+
$postgresReady = $true
65+
break
66+
}
67+
Start-Sleep -Seconds 2
68+
$timeout -= 2
69+
}
70+
71+
if (-not $postgresReady) {
72+
Write-Red " ✗ PostgreSQL failed to start within 60 seconds"
73+
exit 1
74+
}
75+
76+
# Wait for server to be responding
77+
Write-Yellow "• Waiting for Spring Boot server..."
78+
$timeout = 120
79+
$serverReady = $false
80+
while ($timeout -gt 0) {
81+
try {
82+
$response = Invoke-WebRequest -Uri "http://localhost:8080/actuator/health" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
83+
if ($response.StatusCode -eq 200 -or $response.StatusCode -eq 401) {
84+
Write-Green " ✓ Server is ready"
85+
$serverReady = $true
86+
break
87+
}
88+
} catch {
89+
# Server not ready yet
90+
}
91+
Start-Sleep -Seconds 3
92+
$timeout -= 3
93+
}
94+
95+
if (-not $serverReady) {
96+
Write-Yellow " ⚠ Server may still be starting (timeout reached)"
97+
}
98+
99+
# Check if client is responding
100+
Write-Yellow "• Waiting for React client..."
101+
$timeout = 30
102+
$clientReady = $false
103+
while ($timeout -gt 0) {
104+
try {
105+
$response = Invoke-WebRequest -Uri "http://localhost:5173" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
106+
if ($response.StatusCode -eq 200) {
107+
Write-Green " ✓ Client is ready"
108+
$clientReady = $true
109+
break
110+
}
111+
} catch {
112+
# Client not ready yet
113+
}
114+
Start-Sleep -Seconds 2
115+
$timeout -= 2
116+
}
117+
118+
if (-not $clientReady) {
119+
Write-Yellow " ⚠ Client may still be starting (timeout reached)"
120+
}
121+
122+
# Summary
123+
Write-Host ""
124+
Write-Blue "========================================"
125+
Write-Green "✓ Harmonia is now running!"
126+
Write-Blue "========================================"
127+
Write-Yellow "Server:" -NoNewline
128+
Write-Host " http://localhost:8080"
129+
Write-Yellow "Client:" -NoNewline
130+
Write-Host " http://localhost:5173"
131+
Write-Yellow "Database:" -NoNewline
132+
Write-Host " PostgreSQL on localhost:5432"
133+
Write-Host ""
134+
Write-Yellow "Useful commands:"
135+
Write-Yellow "• View logs:" -NoNewline
136+
Write-Host " docker compose -f docker/docker-compose.yml logs -f"
137+
Write-Yellow "• Stop services:" -NoNewline
138+
Write-Host " docker compose -f docker/docker-compose.yml down"
139+
Write-Yellow "• Restart services:" -NoNewline
140+
Write-Host " docker compose -f docker/docker-compose.yml restart"
141+
Write-Host ""
142+
Write-Yellow "Press Ctrl+C to stop all services"
143+
Write-Host ""
144+
145+
# Keep script running and handle Ctrl+C
146+
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
147+
148+
# Cleanup on exit
149+
Write-Host ""
150+
Write-Red "Shutting down all services..."
151+
docker compose -f docker/docker-compose.yml down

0 commit comments

Comments
 (0)