暂存提交
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
param(
|
||||
[string]$ServerAddr = '127.0.0.1:8848',
|
||||
[string]$Group = 'BAIYUE',
|
||||
[string]$Namespace = 'public'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$projectRoot = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||||
$configRoot = Join-Path $projectRoot 'config\nacos\local'
|
||||
$healthUrl = "http://$ServerAddr/nacos/v1/console/health/readiness"
|
||||
$publishUrl = "http://$ServerAddr/nacos/v1/cs/configs"
|
||||
|
||||
$health = Invoke-WebRequest -UseBasicParsing -Uri $healthUrl -TimeoutSec 5
|
||||
if ($health.StatusCode -ne 200 -or $health.Content.Trim() -ne 'OK') {
|
||||
throw "Local Nacos is not ready: $healthUrl"
|
||||
}
|
||||
|
||||
$files = Get-ChildItem -LiteralPath $configRoot -File -Filter '*.yml' | Sort-Object Name
|
||||
if ($files.Count -eq 0) {
|
||||
throw "No local Nacos configuration found: $configRoot"
|
||||
}
|
||||
|
||||
$published = 0
|
||||
foreach ($file in $files) {
|
||||
$body = @{
|
||||
dataId = $file.Name
|
||||
group = $Group
|
||||
content = Get-Content -LiteralPath $file.FullName -Raw -Encoding UTF8
|
||||
type = 'yaml'
|
||||
}
|
||||
if ($Namespace -and $Namespace -ne 'public') {
|
||||
$body.tenant = $Namespace
|
||||
}
|
||||
|
||||
$result = Invoke-RestMethod -Method Post -Uri $publishUrl `
|
||||
-ContentType 'application/x-www-form-urlencoded; charset=UTF-8' `
|
||||
-Body $body -TimeoutSec 10
|
||||
if ([string]$result -ne 'true') {
|
||||
throw "Publish failed: $($file.Name), Nacos response: $result"
|
||||
}
|
||||
$published++
|
||||
Write-Host "Published $($file.Name) -> $Namespace / $Group"
|
||||
}
|
||||
|
||||
Write-Host "Local first-leg Nacos configuration published: $published items."
|
||||
Reference in New Issue
Block a user