53 lines
2.2 KiB
PowerShell
53 lines
2.2 KiB
PowerShell
$ErrorActionPreference = 'Stop'
|
|
|
|
function Read-EnvFile([string]$Path) {
|
|
$values = @{}
|
|
Get-Content -LiteralPath $Path | ForEach-Object {
|
|
if ($_ -match '^\s*([^#=]+)=(.*)$') {
|
|
$values[$matches[1].Trim()] = $matches[2].Trim().Trim('"')
|
|
}
|
|
}
|
|
return $values
|
|
}
|
|
|
|
$root = Split-Path -Parent $PSScriptRoot
|
|
$deploy = Read-EnvFile (Join-Path $root '.env')
|
|
foreach ($required in @('DOKPLOY_URL', 'DOKPLOY_API_KEY')) {
|
|
if (-not $deploy[$required]) { throw "Missing $required in .env" }
|
|
}
|
|
|
|
$headers = @{ 'x-api-key' = $deploy.DOKPLOY_API_KEY; Accept = 'application/json' }
|
|
$base = $deploy.DOKPLOY_URL.TrimEnd('/')
|
|
$core = Invoke-RestMethod -Uri "$base/api/environment.byProjectId?projectId=5hj5VzXYE0fe3SKOx7y5g" -Headers $headers
|
|
$reddit = @($core.compose | Where-Object { $_.name -eq 'reddit' })[0]
|
|
if (-not $reddit.env) { throw 'Core/production Reddit service environment was not found' }
|
|
|
|
$remote = @{}
|
|
$reddit.env -split "`n" | ForEach-Object {
|
|
if ($_ -match '^([^=]+)=(.*)$') { $remote[$matches[1]] = $matches[2] }
|
|
}
|
|
foreach ($required in @('OPENROUTER_API_KEY')) {
|
|
if (-not $remote[$required]) { throw "Deployed environment is missing $required" }
|
|
}
|
|
|
|
$previous = @{}
|
|
foreach ($entry in $remote.GetEnumerator()) {
|
|
$previous[$entry.Key] = [Environment]::GetEnvironmentVariable($entry.Key, 'Process')
|
|
[Environment]::SetEnvironmentVariable($entry.Key, $entry.Value, 'Process')
|
|
}
|
|
$previous['WEB_DASHBOARD_TOKEN'] = [Environment]::GetEnvironmentVariable('WEB_DASHBOARD_TOKEN', 'Process')
|
|
[Environment]::SetEnvironmentVariable('WEB_DASHBOARD_TOKEN', 'create01', 'Process')
|
|
|
|
$logDirectory = Join-Path $root 'data'
|
|
New-Item -ItemType Directory -Force -Path $logDirectory | Out-Null
|
|
$stdout = Join-Path $logDirectory 'local-dev.stdout.log'
|
|
$stderr = Join-Path $logDirectory 'local-dev.stderr.log'
|
|
$process = Start-Process -FilePath 'npm.cmd' -ArgumentList 'run', 'dev' -WorkingDirectory $root -WindowStyle Hidden -RedirectStandardOutput $stdout -RedirectStandardError $stderr -PassThru
|
|
|
|
foreach ($name in $previous.Keys) {
|
|
[Environment]::SetEnvironmentVariable($name, $previous[$name], 'Process')
|
|
}
|
|
|
|
Write-Output "Started local RedditBot process $($process.Id)."
|
|
Write-Output "Logs: $stdout"
|