diff --git a/scripts/setup.ps1 b/scripts/setup.ps1 index 1c0b0e798..ba20b65d0 100644 --- a/scripts/setup.ps1 +++ b/scripts/setup.ps1 @@ -410,9 +410,13 @@ function Test-HostsFile { } $content = Get-Content $hostsPath -Raw - $sourceLines = Get-Content $hostsSource | Where-Object { + $sourceLines = Get-Content $hostsSource | ForEach-Object { $trimmed = $_.Trim() - $trimmed -and -not $trimmed.StartsWith('#') + # Skip blank lines and full-line comments + if (-not $trimmed -or $trimmed.StartsWith('#')) { return } + # Strip inline comments (e.g. "127.1.0.14 host.local # alias note") + $noComment = ($trimmed -replace '\s+#.*$', '').Trim() + if ($noComment) { $noComment } } $missingLines = @() @@ -465,12 +469,29 @@ function Test-HostsFile { } } else { Write-Host '' - Write-Host ' Stella Ops needs ~50 hosts file entries for local development.' -ForegroundColor Yellow - Write-Host ' To install them, run this command in an elevated (Administrator) PowerShell:' -ForegroundColor Yellow + Write-Warn '*** Stella Ops needs ~50 hosts file entries for local development. ***' + Write-Warn "*** $($missingHosts.Count) host alias(es) are missing -- the platform will NOT work without them. ***" Write-Host '' - Write-Host " Get-Content '$hostsSource' | Add-Content '$hostsPath'" -ForegroundColor White + Write-Host ' Option 1: Re-run this script as Administrator to install them automatically.' -ForegroundColor Yellow Write-Host '' - Write-Host ' Or re-run this script as Administrator to install them automatically.' -ForegroundColor Yellow + Write-Host ' Option 2: Run the following in an elevated (Administrator) PowerShell:' -ForegroundColor Yellow + Write-Host '' + # Build a single-line PowerShell command that appends only the missing entries + $escapedLines = ($missingLines | ForEach-Object { "`"$_`"" }) -join ', ' + Write-Host " @($escapedLines) | Add-Content -Path '$hostsPath'" -ForegroundColor White + Write-Host '' + + # Offer clipboard copy + $copyAnswer = $null + try { $copyAnswer = Read-Host ' Copy the missing entries to clipboard? (Y/n)' } catch {} + if ($null -eq $copyAnswer -or $copyAnswer -eq '' -or $copyAnswer -match '^[Yy]') { + try { + ($missingLines -join [Environment]::NewLine) | Set-Clipboard + Write-Ok 'Missing host entries copied to clipboard. Paste them into the hosts file (run Notepad as Administrator).' + } catch { + Write-Warn 'Could not copy to clipboard. Please copy manually from above.' + } + } } } @@ -521,33 +542,42 @@ function Get-FrontdoorNetworkName { return 'stellaops_frontdoor' } -function Ensure-FrontdoorNetwork { - $networkName = Get-FrontdoorNetworkName +function Ensure-DockerNetwork([string]$networkName, [string]$label) { if ([string]::IsNullOrWhiteSpace($networkName)) { - Write-Fail 'Unable to resolve the frontdoor Docker network name.' + Write-Fail "Unable to resolve the $label Docker network name." exit 1 } $existingNetworks = @(docker network ls --format '{{.Name}}' 2>$null) if ($existingNetworks -contains $networkName) { - Write-Ok "Frontdoor network available ($networkName)" + Write-Ok "$label network available ($networkName)" return } - Write-Warn "Frontdoor network missing ($networkName); creating it now." + Write-Warn "$label network missing ($networkName); creating it now." docker network create $networkName | Out-Null if ($LASTEXITCODE -ne 0) { - Write-Fail "Failed to create frontdoor network ($networkName)." + Write-Fail "Failed to create $label network ($networkName)." exit 1 } - Write-Ok "Created frontdoor network ($networkName)" + Write-Ok "Created $label network ($networkName)" +} + +function Ensure-StellaOpsNetwork { + Ensure-DockerNetwork 'stellaops' 'Stellaops' +} + +function Ensure-FrontdoorNetwork { + $networkName = Get-FrontdoorNetworkName + Ensure-DockerNetwork $networkName 'Frontdoor' } # ─── 4. Start infrastructure ─────────────────────────────────────────────── function Start-Infrastructure { Write-Step 'Starting infrastructure containers (docker-compose.dev.yml)' + Ensure-StellaOpsNetwork Push-Location $ComposeDir try { docker compose -f docker-compose.dev.yml up -d @@ -607,6 +637,7 @@ function Build-Images([switch]$PublishNoRestore) { function Start-Platform { Write-Step 'Starting full Stella Ops platform' + Ensure-StellaOpsNetwork Ensure-FrontdoorNetwork Push-Location $ComposeDir try { diff --git a/scripts/setup.sh b/scripts/setup.sh index e4b8aa11c..b3bbdcf1f 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -341,7 +341,13 @@ check_hosts() { local source_lines=() while IFS= read -r line; do [[ -z "${line// }" ]] && continue + # Skip full-line comments [[ "$line" =~ ^[[:space:]]*# ]] && continue + # Strip inline comments (e.g. "127.1.0.14 host.local # alias note") + line="${line%%#*}" + # Trim trailing whitespace left after stripping the comment + line="${line%"${line##*[![:space:]]}"}" + [[ -z "$line" ]] && continue source_lines+=("$line") done < "$hosts_source" @@ -445,24 +451,35 @@ get_frontdoor_network_name() { printf '%s\n' 'stellaops_frontdoor' } -ensure_frontdoor_network() { - local network_name - network_name="$(get_frontdoor_network_name)" +ensure_docker_network() { + local network_name="$1" + local label="$2" if docker network inspect "$network_name" >/dev/null 2>&1; then - ok "Frontdoor network available ($network_name)" + ok "$label network available ($network_name)" return fi - warn "Frontdoor network missing ($network_name); creating it now." + warn "$label network missing ($network_name); creating it now." docker network create "$network_name" >/dev/null - ok "Created frontdoor network ($network_name)" + ok "Created $label network ($network_name)" +} + +ensure_stellaops_network() { + ensure_docker_network 'stellaops' 'Stellaops' +} + +ensure_frontdoor_network() { + local network_name + network_name="$(get_frontdoor_network_name)" + ensure_docker_network "$network_name" 'Frontdoor' } # ─── 4. Start infrastructure ─────────────────────────────────────────────── start_infra() { step 'Starting infrastructure containers (docker-compose.dev.yml)' + ensure_stellaops_network cd "$COMPOSE_DIR" docker compose -f docker-compose.dev.yml up -d @@ -509,6 +526,7 @@ build_images() { start_platform() { step 'Starting full Stella Ops platform' + ensure_stellaops_network ensure_frontdoor_network cd "$COMPOSE_DIR" docker compose -f docker-compose.stella-ops.yml up -d