-
Notifications
You must be signed in to change notification settings - Fork 0
Startup script #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Startup script #70
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
|
|
||
| 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." | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.