Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ Spring Boot application for case management with a Thymeleaf UI, PostgreSQL, and

## Start the application (local development)

<<<<<<< issue/69
### Quick start (recommended on Windows)

Run one command to perform all startup steps:

```powershell
.\start-local.ps1
```

Show full command output instead of fun/quiet mode:

```powershell
.\start-local.ps1 --serious
```

The script will:
- Verify Docker is available and the engine is running
- Start infrastructure with `docker compose up -d`
- Start Spring Boot with profile `local`

=======
>>>>>>> main
### 0) Verify Docker is running (Windows)

Before running `docker compose up -d`, make sure Docker Desktop is started and the Linux engine is running.
Expand Down Expand Up @@ -112,8 +134,14 @@ docker compose up -d
```

- If you want to keep your local PostgreSQL running, map Docker PostgreSQL to another host port:
<<<<<<< issue/69
1. Edit `docker-compose.yml` PostgreSQL ports from `"5432:5432"` to `"5433:5432"`.
2. Edit `src/main/resources/application.properties` database URL from `localhost:5432` to `localhost:5433`.
3. Run `docker compose up -d` again.
=======
1. Edit `docker-compose.yml` PostgreSQL ports from `"5432:5432"` to `"5433:5432"`.
2. Edit `src/main/resources/application.properties` database URL from `localhost:5432` to `localhost:5433`.
3. Run `docker compose up -d` again.
>>>>>>> main
- App starts but login fails:
- Confirm you started Spring with profile `local` so `data-local.sql` is loaded.
209 changes: 209 additions & 0 deletions start-local.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
param(
[switch]$NoDockerCheck,
[switch]$Serious
)

$ErrorActionPreference = "Stop"

if ($args -contains "--serious") {
$Serious = $true
}

function Assert-CommandExists {
param([string]$CommandName)

if (-not (Get-Command $CommandName -ErrorAction SilentlyContinue)) {
throw "Command '$CommandName' was not found. Install it and try again."
}
}

function Invoke-CommandWithMode {
param(
[scriptblock]$Command
)

$previousErrorActionPreference = $ErrorActionPreference
$tempLog = $null

try {
$ErrorActionPreference = "Continue"

if ($Serious) {
& $Command 2>&1
}
else {
$tempLog = [System.IO.Path]::GetTempFileName()
& $Command *> $tempLog

if ($LASTEXITCODE -ne 0) {
Write-Host "Command failed in quiet mode (exit code: $LASTEXITCODE)." -ForegroundColor Red
Write-Host "Recent output from $tempLog:" -ForegroundColor DarkRed
Get-Content -Path $tempLog -Tail 25 | ForEach-Object { Write-Host $_ -ForegroundColor DarkGray }
}
}

return $LASTEXITCODE
}
finally {
if ($tempLog -and (Test-Path $tempLog)) {
Remove-Item -Path $tempLog -Force -ErrorAction SilentlyContinue
}
$ErrorActionPreference = $previousErrorActionPreference
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

function Write-FunStatus {
param(
[string[]]$Messages,
[ConsoleColor]$Color = [ConsoleColor]::Cyan
)

if ($Messages -and $Messages.Count -gt 0) {
$index = Get-Random -Minimum 0 -Maximum $Messages.Count
Write-Host $Messages[$index] -ForegroundColor $Color
}
}

function Pause-ForEnjoyment {
if (-not $Serious) {
Start-Sleep -Seconds 2
}
}

if ($Serious) {
Write-Host "Starting local development environment (serious mode)..." -ForegroundColor Cyan
}
else {
Write-FunStatus -Messages @(
"Waking up the dev servers..."
"Turning caffeine into deployment energy..."
"Calibrating keyboard clicks and backend magic..."
) -Color Cyan
}
Pause-ForEnjoyment

Assert-CommandExists -CommandName "docker"

if (-not $NoDockerCheck) {
if ($Serious) {
Write-Host "Checking Docker engine..." -ForegroundColor Yellow
}
else {
Write-FunStatus -Messages @(
"Knocking on Docker's front door..."
"Asking Docker politely to wake up..."
"Reading Docker's morning mood..."
) -Color Yellow
}
Pause-ForEnjoyment
$engineReady = $false
$maxAttempts = 12

for ($attempt = 1; $attempt -le $maxAttempts; $attempt++) {
$dockerInfoExitCode = Invoke-CommandWithMode -Command { docker info }
if ($dockerInfoExitCode -eq 0) {
$engineReady = $true
break
}

if ($attempt -lt $maxAttempts) {
Write-FunStatus -Messages @(
"Fetching coffee for the engineers... Docker not ready yet ($attempt/$maxAttempts). Retrying in 5 seconds..."
"Asking the marketing department to leave... Docker still booting ($attempt/$maxAttempts). Retrying in 5 seconds..."
"Negotiating with the container gods... still waiting ($attempt/$maxAttempts). Retrying in 5 seconds..."
) -Color DarkYellow
Start-Sleep -Seconds 5
}
}

if (-not $engineReady) {
throw @"
Docker engine is not available yet.
Start Docker Desktop, wait until 'Engine running', then run this script again.
Tip: verify manually with 'docker info' (it should return without daemon errors).
"@
}
}

if ($Serious) {
Write-Host "Starting infrastructure services (PostgreSQL + MinIO)..." -ForegroundColor Yellow
}
else {
Write-FunStatus -Messages @(
"Summoning PostgreSQL and MinIO..."
"Spinning up databases and object storage wizardry..."
"Hiring tiny container elves for infrastructure..."
) -Color Yellow
}
Pause-ForEnjoyment
$composeExitCode = Invoke-CommandWithMode -Command { docker compose up -d }

if ($composeExitCode -ne 0) {
throw "docker compose failed. Fix the error above and retry."
}

if ($Serious) {
Write-Host "Starting Spring Boot with profile 'local'..." -ForegroundColor Yellow
}
else {
Write-FunStatus -Messages @(
"Launching Spring Boot thrusters..."
"Convincing Java to do something useful..."
"Whispering encouragement to the JVM..."
) -Color Yellow
}
Write-Host "App URL: http://localhost:8080" -ForegroundColor Green
Write-Host "Press Ctrl+C to stop the application." -ForegroundColor Green
Write-Host "Admin login (local profile):" -ForegroundColor Magenta
Write-Host "Username: admin@traumateam.com" -ForegroundColor Magenta
Write-Host "Password: password" -ForegroundColor Magenta
Write-Host "Starting web browser for your lazy a**" -ForegroundColor Green
Write-Host "Opening browser at http://localhost:8080 ..." -ForegroundColor Green
if (-not $Serious) {
Write-Host "Quiet mode active: app logs are hidden while running." -ForegroundColor DarkGreen
Write-Host "If the prompt does not return, the app is still running in this terminal." -ForegroundColor DarkGreen
Write-Host "Use --serious to see full startup logs." -ForegroundColor DarkGreen
}
Pause-ForEnjoyment

$browserOpenTimeoutSeconds = 90
$browserPollIntervalSeconds = 2
$browserReadyJob = Start-Job -ScriptBlock {
param(
[int]$TimeoutSeconds,
[int]$PollIntervalSeconds
)

$uri = "http://localhost:8080"
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)

while ((Get-Date) -lt $deadline) {
try {
$response = Invoke-WebRequest -Uri $uri -Method GET -TimeoutSec 3 -ErrorAction Stop
if ($response.StatusCode -ge 200 -and $response.StatusCode -lt 400) {
Start-Process $uri
return
}
}
catch {
# App not ready yet; continue polling until timeout.
}

Start-Sleep -Seconds $PollIntervalSeconds
}
} -ArgumentList $browserOpenTimeoutSeconds, $browserPollIntervalSeconds

$mavenExitCode = Invoke-CommandWithMode -Command { .\mvnw spring-boot:run "-Dspring-boot.run.profiles=local" }

if ($mavenExitCode -ne 0) {
if ($browserReadyJob) {
Stop-Job -Job $browserReadyJob -ErrorAction SilentlyContinue
Remove-Job -Job $browserReadyJob -Force -ErrorAction SilentlyContinue
}
if ($mavenExitCode -in @(130, 1)) {
Write-Warning "Spring Boot terminated by user (Ctrl+C)"
}
else {
throw "Spring Boot failed with exit code $mavenExitCode. Re-run with --serious to see detailed logs."
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.