hezarfen_text_to_podcast
Clone
https://git.tahinli.com/archive/hezarfen_text_to_podcast.git
0 watching0 forksPython351.2 KiBbca8bffAhmet Kaan Gümüş2 months ago27 commits
| 1 | [CmdletBinding()] |
| 2 | param( |
| 3 | [string]$Root = "C:\PROJECTS\podcast", |
| 4 | [string]$BackendProject = "hezarfen_backend", |
| 5 | [switch]$Rebuild, |
| 6 | [switch]$PodcastOnly |
| 7 | ) |
| 8 | $ErrorActionPreference = "Stop" |
| 9 | |
| 10 | function Invoke-Quiet { |
| 11 | param([Parameter(Mandatory)][string]$Command, [string[]]$Arg = @()) |
| 12 | $previousEAP = $ErrorActionPreference |
| 13 | $ErrorActionPreference = 'Continue' |
| 14 | try { & $Command @Arg *> $null } finally { $ErrorActionPreference = $previousEAP } |
| 15 | return $LASTEXITCODE |
| 16 | } |
| 17 | |
| 18 | |
| 19 | function Find-Podman { |
| 20 | $c = (Get-Command podman -ErrorAction SilentlyContinue).Source |
| 21 | if ($c) { return $c } |
| 22 | foreach ($p in @("$env:LOCALAPPDATA\Programs\Podman\podman.exe", |
| 23 | "$env:ProgramFiles\RedHat\Podman\podman.exe")) { |
| 24 | if (Test-Path $p) { return $p } |
| 25 | } |
| 26 | throw "podman.exe bulunamadi. winget install RedHat.Podman" |
| 27 | } |
| 28 | $PODMAN = Find-Podman |
| 29 | $podcast = Split-Path -Parent $PSScriptRoot |
| 30 | Write-Host "[stack] podman : $PODMAN" |
| 31 | Write-Host "[stack] podcast : $podcast" |
| 32 | |
| 33 | if (-not (Test-Path -LiteralPath $Root)) { throw "Arama koku yok: $Root" } |
| 34 | Write-Host "[stack] repolar araniyor: $Root" |
| 35 | $candidates = Get-ChildItem -LiteralPath $Root -Recurse -Depth 3 -File -Filter "compose.yaml" ` |
| 36 | -ErrorAction SilentlyContinue | |
| 37 | Where-Object { $_.FullName -notmatch '\\(\.venv|node_modules|vendor|out|target)\\' } |
| 38 | |
| 39 | function Find-Repo([string]$signature, [string]$label) { |
| 40 | $found = @() |
| 41 | foreach ($c in $candidates) { |
| 42 | if ($c.DirectoryName -eq $podcast) { continue } |
| 43 | if ((Get-Content -LiteralPath $c.FullName -Raw) -match $signature) { $found += $c.DirectoryName } |
| 44 | } |
| 45 | $found = @($found | Sort-Object -Unique) |
| 46 | if ($found.Count -eq 0) { |
| 47 | throw "$label reposu bulunamadi ($Root altinda '$signature' iceren compose.yaml yok). -Root ile arama kokunu ver." |
| 48 | } |
| 49 | if ($found.Count -gt 1) { |
| 50 | throw "$label icin BIRDEN COK aday bulundu; hangisi oldugu belirsiz:`n " + ($found -join "`n ") |
| 51 | } |
| 52 | Write-Host ("[stack] {0,-9}: {1}" -f $label, $found[0]) |
| 53 | return $found[0] |
| 54 | } |
| 55 | |
| 56 | if (-not $PodcastOnly) { |
| 57 | $backend = Find-Repo 'container_name:\s*hezarfen-backend' "backend" |
| 58 | $frontend = Find-Repo 'container_name:\s*hezarfen-frontend' "frontend" |
| 59 | $chatbot = Find-Repo 'container_name:\s*hezarfen-chatbot-bridge' "chatbot" |
| 60 | } |
| 61 | |
| 62 | $vendor = Join-Path $podcast "vendor\pipeline\router\hat.py" |
| 63 | if (-not (Test-Path -LiteralPath $vendor)) { |
| 64 | throw "vendor/pipeline yok. Once calistir: pwsh -File deploy/setup-pipeline.ps1" |
| 65 | } |
| 66 | if (-not $env:AI_SHARED_TOKEN) { |
| 67 | $envFile = Join-Path $podcast ".env" |
| 68 | if (-not (Test-Path -LiteralPath $envFile) -or |
| 69 | -not ((Get-Content -LiteralPath $envFile -Raw) -match '(?m)^\s*AI_SHARED_TOKEN\s*=\s*\S')) { |
| 70 | throw "AI_SHARED_TOKEN yok. `$env:AI_SHARED_TOKEN='...' ver ya da .env doldur (backend ile AYNI deger)." |
| 71 | } |
| 72 | } |
| 73 | $probeFile = "/models/ses_modelleri/supertonic-3/onnx/vocoder.onnx" |
| 74 | $null = Invoke-Quiet $PODMAN @('volume','exists','podcast-models') |
| 75 | if ($LASTEXITCODE -ne 0) { |
| 76 | Write-Host "[stack] UYARI: 'podcast-models' hacmi YOK. TTS ve CER kapisi CALISMAZ." |
| 77 | Write-Host " pwsh -File deploy/setup-models.ps1" |
| 78 | } else { |
| 79 | & $PODMAN run --rm -v podcast-models:/models:ro docker.io/library/python:3.10-slim ` |
| 80 | test -e $probeFile |
| 81 | if ($LASTEXITCODE -ne 0) { |
| 82 | Write-Host "[stack] UYARI: 'podcast-models' hacmi var ama BOS/EKSIK gorunuyor." |
| 83 | Write-Host " beklenen: $probeFile" |
| 84 | Write-Host " pwsh -File deploy/setup-models.ps1 -Refresh" |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | $previousEAP = $ErrorActionPreference |
| 89 | $ErrorActionPreference = 'Continue' |
| 90 | & $PODMAN machine start *> $null |
| 91 | $ErrorActionPreference = $previousEAP |
| 92 | |
| 93 | if (-not $PodcastOnly) { |
| 94 | Write-Host "`n[stack] 1/5 base imajlar pre-pull..." |
| 95 | $bases = @("docker.io/surrealdb/surrealdb:v3") |
| 96 | foreach ($d in @($backend, $frontend, $chatbot, $podcast)) { |
| 97 | $cf = Join-Path $d "Containerfile" |
| 98 | if (Test-Path -LiteralPath $cf) { |
| 99 | Select-String -LiteralPath $cf -Pattern '^\s*FROM\s+(\S+)' | ForEach-Object { |
| 100 | $bases += $_.Matches[0].Groups[1].Value |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | foreach ($img in ($bases | Where-Object { $_ -notmatch '^\$' } | Sort-Object -Unique)) { |
| 105 | Write-Host " pull $img"; Invoke-Quiet $PODMAN @('pull',$img) | Out-Null |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | function Compose-Up([string]$dir, [string[]]$preArgs) { |
| 110 | Push-Location $dir |
| 111 | try { |
| 112 | & $PODMAN compose @preArgs up -d --build |
| 113 | if ($LASTEXITCODE -ne 0) { throw "compose up basarisiz: $dir" } |
| 114 | } finally { Pop-Location } |
| 115 | } |
| 116 | |
| 117 | if (-not $PodcastOnly) { |
| 118 | Write-Host "`n[stack] 2/5 backend (-p $BackendProject ; Rust ilk seferde uzun surer)..." |
| 119 | Compose-Up $backend @("-p", $BackendProject) |
| 120 | Write-Host "`n[stack] 3/5 frontend..." |
| 121 | Compose-Up $frontend @() |
| 122 | Write-Host "`n[stack] 4/5 chatbot..." |
| 123 | Compose-Up $chatbot @() |
| 124 | } |
| 125 | |
| 126 | $net = (& $PODMAN inspect hezarfen-backend --format '{{range $k, $v := .NetworkSettings.Networks}}{{$k}} {{end}}' 2>$null) |
| 127 | $net = ($net -split '\s+' | Where-Object { $_ }) | Select-Object -First 1 |
| 128 | $_raw = & $PODMAN inspect hezarfen-backend --format json 2>$null |
| 129 | $_mounts = @() |
| 130 | if ($_raw) { try { $_mounts = ($_raw | ConvertFrom-Json)[0].Mounts } catch { $_mounts = @() } } |
| 131 | $vol = ($_mounts | Where-Object { $_.Destination -eq '/data' } | |
| 132 | Select-Object -First 1 -ExpandProperty Name -ErrorAction SilentlyContinue) |
| 133 | $vol = ($vol | Out-String).Trim() |
| 134 | |
| 135 | if ($net) { $env:HEZARFEN_NET = $net } |
| 136 | else { Write-Host "[stack] UYARI: backend agi okunamadi; compose varsayilani kullanilacak." } |
| 137 | if ($vol) { $env:HEZARFEN_DATA_VOLUME = $vol } |
| 138 | else { Write-Host "[stack] UYARI: backend /data hacmi okunamadi; compose varsayilani kullanilacak." } |
| 139 | Write-Host "`n[stack] backend agi : $($env:HEZARFEN_NET)" |
| 140 | Write-Host "[stack] backend hacmi : $($env:HEZARFEN_DATA_VOLUME) (PDF'ler burada, :ro baglanir)" |
| 141 | |
| 142 | $image = "localhost/hezarfen-podcast" |
| 143 | |
| 144 | $previousId = (& $PODMAN images "${image}:current" --format "{{.ID}}" 2>$null | |
| 145 | Select-Object -First 1) |
| 146 | |
| 147 | Write-Host "`n[stack] 5/5 podcast imaji build ediliyor (${image}:current)" |
| 148 | Push-Location $podcast |
| 149 | try { |
| 150 | $buildArgs = @("build", "-t", "${image}:current", "-f", "Containerfile", ".") |
| 151 | if ($Rebuild) { $buildArgs = @("build", "--no-cache") + $buildArgs[1..($buildArgs.Count - 1)] } |
| 152 | & $PODMAN @buildArgs |
| 153 | if ($LASTEXITCODE -ne 0) { throw "podcast imaji build edilemedi." } |
| 154 | |
| 155 | $currentId = (& $PODMAN images "${image}:current" --format "{{.ID}}" 2>$null | |
| 156 | Select-Object -First 1) |
| 157 | if ($currentId -and $currentId -ne $previousId) { |
| 158 | $tag = Get-Date -Format "yyyyMMdd-HHmmss" |
| 159 | & $PODMAN tag "${image}:current" "${image}:$tag" |
| 160 | if ($LASTEXITCODE -ne 0) { throw "surum etiketi konulamadi." } |
| 161 | Write-Host "[stack] imaj DEGISTI -> yeni surum etiketi: $tag ($currentId)" |
| 162 | } else { |
| 163 | Write-Host "[stack] imaj degismedi ($currentId) - yeni surum etiketi ACILMADI" |
| 164 | } |
| 165 | |
| 166 | & $PODMAN compose --profile product up -d |
| 167 | if ($LASTEXITCODE -ne 0) { throw "podcast compose up basarisiz." } |
| 168 | } finally { Pop-Location } |
| 169 | |
| 170 | Write-Host "`n[stack] dogrulama..." |
| 171 | Start-Sleep -Seconds 8 |
| 172 | & $PODMAN ps --format "{{.Names}}`t{{.Status}}`t{{.Image}}" |
| 173 | |
| 174 | foreach ($p in 8080, 5173) { |
| 175 | try { |
| 176 | $code = (Invoke-WebRequest -UseBasicParsing -Uri "http://localhost:$p/" -TimeoutSec 8).StatusCode |
| 177 | Write-Host " localhost:$p -> HTTP $code" |
| 178 | } catch { |
| 179 | Write-Host " localhost:$p -> ERISILEMEDI ($($_.Exception.Message))" |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | Write-Host " podcast kaydi bekleniyor (en fazla 30 sn)..." |
| 184 | $registered = $false |
| 185 | for ($i = 0; $i -lt 15; $i++) { |
| 186 | $log = (& $PODMAN logs --tail 200 hezarfen_text_to_podcast 2>&1 | Out-String) |
| 187 | if ($log -match "kayit basarili") { $registered = $true; break } |
| 188 | Start-Sleep -Seconds 2 |
| 189 | } |
| 190 | if ($registered) { |
| 191 | ((& $PODMAN logs --tail 200 hezarfen_text_to_podcast 2>&1 | Out-String) -split "`n" | |
| 192 | Where-Object { $_ -match "kayit basarili|GERCEK hat bagli|acik formatlar|SAHTE hat" }) | |
| 193 | ForEach-Object { Write-Host " $($_.Trim())" } |
| 194 | Write-Host "`n[stack] HAZIR. Frontend: http://localhost:5173 (admin / admin123)" |
| 195 | Write-Host "[stack] geri alma : pwsh -File deploy/rollback.ps1 -List" |
| 196 | } else { |
| 197 | Write-Host "`n[stack] !!! Podcast koprusu KAYIT OLMADI. Son loglar:" |
| 198 | & $PODMAN logs --tail 40 hezarfen_text_to_podcast |
| 199 | Write-Host "`n[stack] sorun giderme: deploy/OKU.md" |
| 200 | exit 1 |
| 201 | } |