Skip to content

Commit b121f31

Browse files
committed
fix: 修复 Wait-ServiceHealthy 函数中的 docker 命令调用方式
重构 Wait-ServiceHealthy 函数,简化 docker 命令调用逻辑,移除对 docker-compose 的兼容性处理 同时修复 mongodb-replica 服务启动时的密码处理,使用 Get-PlainTextFromSecure 转换安全密码
1 parent c0ca6a1 commit b121f31

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

‎start-container.ps1‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,9 @@ function Wait-ServiceHealthy {
188188
$elapsed = 0
189189
while ($elapsed -lt $TimeoutSec) {
190190
try {
191-
$filterArgs = @('ps', '-q', '--filter', "label=com.docker.compose.service=$Service")
192-
if ($Project) { $filterArgs += @('--filter', "label=com.docker.compose.project=$Project") }
193-
$mode = Test-DockerAvailable
194-
$psArgs = @()
195-
if ($mode -eq 'sub') { $psArgs += 'compose' }
196-
$psArgs += $filterArgs
197-
$ids = if ($mode -eq 'sub') { & docker @psArgs } else { & docker-compose @filterArgs }
191+
$psArgs = @('ps', '-q', '--filter', "label=com.docker.compose.service=$Service")
192+
if ($Project) { $psArgs += @('--filter', "label=com.docker.compose.project=$Project") }
193+
$ids = & docker @psArgs
198194
if ([string]::IsNullOrWhiteSpace($ids)) { Start-Sleep -Milliseconds 500; continue }
199195
$inspect = & docker inspect $ids
200196
if ($inspect -match '"Status":\s*"healthy"') { return $true }
@@ -257,7 +253,7 @@ if ($NetworkName) { New-NetworkIfMissing -Name $NetworkName }
257253
if ($ServiceName -eq 'mongodb-replica' -and (Test-Path $mongoReplComposePath)) {
258254
$env:DOCKER_DATA_PATH = $DataPath
259255
$env:MONGO_USER = $DefaultUser
260-
$env:MONGO_PASSWORD = $DefaultPassword
256+
$env:MONGO_PASSWORD = (Get-PlainTextFromSecure -Secure $DefaultPassword)
261257
Invoke-DockerCompose -File $mongoReplComposePath -Project 'mongo-repl-dev' -Action 'up -d' -DryRun:$DryRun
262258
if (-not $DryRun) { [void](Wait-ServiceHealthy -Service 'mongo1' -Project 'mongo-repl-dev') }
263259
return

0 commit comments

Comments
 (0)