feat: 增加 Portal YAML 运行配置 (#56)
This commit is contained in:
@@ -332,7 +332,7 @@ function Start-Portal {
|
||||
}
|
||||
$endpoint = ConvertTo-Endpoint $Resolved.portal_address
|
||||
Assert-PortAvailable $endpoint "portal"
|
||||
& (Join-Path $PSScriptRoot "chorus-dev.bat") start $Resolved.portal_environment_file $Resolved.portal_address
|
||||
& (Join-Path $PSScriptRoot "chorus-dev.bat") start $Resolved.portal_environment_file $Resolved.portal_address $Resolved.portal_settings_file
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Portal startup failed."
|
||||
}
|
||||
|
||||
+35
-5
@@ -8,7 +8,10 @@ param(
|
||||
[string]$EnvironmentFile,
|
||||
|
||||
[Parameter(Position = 2)]
|
||||
[string]$PortalAddress
|
||||
[string]$PortalAddress,
|
||||
|
||||
[Parameter(Position = 3)]
|
||||
[string]$SettingsFile
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
@@ -20,6 +23,7 @@ if ([string]::IsNullOrWhiteSpace($env:LOCALAPPDATA)) {
|
||||
|
||||
$script:RepoRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot ".."))
|
||||
$script:EnvironmentFile = $EnvironmentFile
|
||||
$script:SettingsFile = $SettingsFile
|
||||
$script:StateRoot = Join-Path $env:LOCALAPPDATA "Chorus\dev"
|
||||
$script:BinRoot = Join-Path $script:StateRoot "bin"
|
||||
$script:LogRoot = Join-Path $script:StateRoot "logs"
|
||||
@@ -153,6 +157,18 @@ function Get-PortalEndpoint {
|
||||
return Get-Endpoint $address "127.0.0.1:8080" "portal address"
|
||||
}
|
||||
|
||||
function Get-PortalSettingsFile {
|
||||
if ([string]::IsNullOrWhiteSpace($script:SettingsFile)) {
|
||||
$script:SettingsFile = Join-Path $script:RepoRoot "portal\config\settings.yml"
|
||||
}
|
||||
$resolved = Resolve-Path -LiteralPath $script:SettingsFile -ErrorAction SilentlyContinue
|
||||
if ($null -eq $resolved -or $resolved.Path -notmatch '\.(yml|yaml)$') {
|
||||
throw "Portal settings file is missing or invalid: $script:SettingsFile"
|
||||
}
|
||||
$script:SettingsFile = $resolved.Path
|
||||
return $script:SettingsFile
|
||||
}
|
||||
|
||||
function Test-TcpPort {
|
||||
param([string]$HostName, [int]$Port, [int]$TimeoutMilliseconds = 500)
|
||||
$client = [Net.Sockets.TcpClient]::new()
|
||||
@@ -259,7 +275,8 @@ function Start-Component {
|
||||
param(
|
||||
[ValidateSet("portal", "mock")][string]$Name,
|
||||
[string]$Package,
|
||||
$Endpoint
|
||||
$Endpoint,
|
||||
[string[]]$Arguments = @()
|
||||
)
|
||||
$existing = Get-ManagedProcess $Name
|
||||
if ($null -ne $existing) {
|
||||
@@ -272,7 +289,18 @@ function Start-Component {
|
||||
$stamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
$stdout = Join-Path $script:LogRoot "$Name-$stamp.out.log"
|
||||
$stderr = Join-Path $script:LogRoot "$Name-$stamp.err.log"
|
||||
$process = Start-Process -FilePath $executable -WorkingDirectory $script:RepoRoot -RedirectStandardOutput $stdout -RedirectStandardError $stderr -PassThru -WindowStyle Hidden
|
||||
$startArguments = @{
|
||||
FilePath = $executable
|
||||
WorkingDirectory = $script:RepoRoot
|
||||
RedirectStandardOutput = $stdout
|
||||
RedirectStandardError = $stderr
|
||||
PassThru = $true
|
||||
WindowStyle = "Hidden"
|
||||
}
|
||||
if ($Arguments.Count -gt 0) {
|
||||
$startArguments.ArgumentList = $Arguments
|
||||
}
|
||||
$process = Start-Process @startArguments
|
||||
$state = [ordered]@{
|
||||
name = $Name
|
||||
pid = $process.Id
|
||||
@@ -361,7 +389,8 @@ try {
|
||||
Assert-DatabaseAvailable
|
||||
$portalEndpoint = Get-PortalEndpoint
|
||||
$env:CHORUS_LISTEN_ADDRESS = $portalEndpoint.Address
|
||||
Start-Component "portal" "./portal" $portalEndpoint
|
||||
$settingsArgument = '--config="' + (Get-PortalSettingsFile).Replace('"', '\"') + '"'
|
||||
Start-Component "portal" "./portal" $portalEndpoint @($settingsArgument)
|
||||
}
|
||||
"start-mock" {
|
||||
Import-ChorusEnvironment
|
||||
@@ -375,7 +404,8 @@ try {
|
||||
Assert-DatabaseAvailable
|
||||
$portalEndpoint = Get-PortalEndpoint
|
||||
$env:CHORUS_LISTEN_ADDRESS = $portalEndpoint.Address
|
||||
Start-Component "portal" "./portal" $portalEndpoint
|
||||
$settingsArgument = '--config="' + (Get-PortalSettingsFile).Replace('"', '\"') + '"'
|
||||
Start-Component "portal" "./portal" $portalEndpoint @($settingsArgument)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ function Run-Portal {
|
||||
}
|
||||
$env:CHORUS_LISTEN_ADDRESS = $resolved.portal_address
|
||||
$executable = Join-Path $script:BinRoot "chorus-portal.exe"
|
||||
& $executable
|
||||
& $executable --config $resolved.portal_settings_file
|
||||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user