schon/scripts/Windows/run.ps1
Egor fureunoir Gorbunov 7d1bcaa8d4 Features: 1) Added validation to ensure scripts execute from project root with 'evibes' directory check; 2) Introduced color formatting and ASCII art for enhanced script output; 3) Added RAM, CPU, and disk space verification to installation scripts; 4) Ensured Docker images existence before service startup; 5) Unified spinner-based progress display in Windows and Unix scripts.
Fixes: 1) Replaced hardcoded paths with script-relative paths for better portability; 2) Corrected CPU and memory calculation logic for system checks; 3) Replaced inconsistent script formatting and error handling; 4) Resolved redundant cleanup steps post service startup.

Extra: Refactored and cleaned up script logic for maintainability; added WISELESS branding across scripts for consistency; enhanced terminal output and user messaging.
2025-06-16 15:40:44 +03:00

91 lines
2.9 KiB
PowerShell

#!/usr/bin/env pwsh
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
if (-not (Test-Path -Path ".\evibes" -PathType Container))
{
Write-Host "❌ Please run this script from the project's root (where the 'evibes' directory lives)." -ForegroundColor Red
exit 1
}
$purple = "`e[38;2;121;101;209m"
$reset = "`e[0m"
$artPath = Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) '..\ASCII_ART_EVIBES'
if (-not (Test-Path $artPath))
{
Write-Host "❌ Could not find ASCII art at $artPath" -ForegroundColor Red
exit 1
}
$art = Get-Content -Raw -Path $artPath
$art -split "`r?`n" | ForEach-Object {
Write-Host "$purple$_$reset"
}
Write-Host "`nby WISELESS TEAM`n" -ForegroundColor Gray
Write-Host "Verifying all images are present…" -ForegroundColor Green
$config = docker compose config --format json | ConvertFrom-Json
foreach ($prop in $config.services.PSObject.Properties)
{
$svc = $prop.Value
if (-not ($svc.PSObject.Properties.Name -contains 'image'))
{
continue
}
$image = $svc.PSObject.Properties['image'].Value
if (-not (docker image inspect $image))
{
Write-Error "Required images not found. Please run install.ps1 first."
exit 1
}
Write-Host " • Found image: $image"
}
$Spinner = @('|', '/', '-', '\')
$Colors = @('White', 'Gray')
$Delay = 100
function Invoke-Spinner
{
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Arguments,
[Parameter(Mandatory)][string]$Message
)
Write-Host -NoNewLine -ForegroundColor Cyan ("{0}… " -f $Message)
$si = New-Object System.Diagnostics.ProcessStartInfo
$si.FileName = "docker"
$si.Arguments = "$Arguments --ansi never"
$si.RedirectStandardOutput = $true
$si.RedirectStandardError = $true
$si.UseShellExecute = $false
$p = [System.Diagnostics.Process]::Start($si)
$i = 0
while (-not $p.HasExited)
{
$frame = $Spinner[$i % $Spinner.Length]
$col = $Colors[$i % $Colors.Length]
Write-Host -NoNewLine -ForegroundColor $col $frame
Start-Sleep -Milliseconds $Delay
Write-Host -NoNewLine "`b"
$i++
}
$p.WaitForExit()
Write-Host -ForegroundColor Green ""
}
Invoke-Spinner -Arguments "compose up --no-build --detach --wait" -Message "Starting services"
Invoke-Spinner -Arguments "compose exec app poetry run python manage.py migrate --no-input" -Message "Applying migrations"
Invoke-Spinner -Arguments "compose exec app poetry run python manage.py collectstatic --no-input" -Message "Collecting static files"
Invoke-Spinner -Arguments "compose exec app poetry run python manage.py set_default_caches" -Message "Setting default caches"
Invoke-Spinner -Arguments "compose exec app poetry run python manage.py set_default_caches" -Message "Cleaning up"
Write-Host "All done! eVibes is up and running." -ForegroundColor Green