Fixes and completion of Invoke-DockerCompose

This commit is contained in:
Gal 2021-01-15 01:56:10 -05:00
parent dcc9113cda
commit a7ac392886
3 changed files with 23 additions and 15 deletions

View File

@ -62,7 +62,7 @@ foreach( $local:p in $CliParams ) {
$local:AsJob = $false;
$local:Wait = $false;
if( $p -isnot [String] ) {
if( $p -isnot [String] -or $p.Length -eq 1 ) {
$local:skipFirst = $true
switch( $p[0] ) {
'&' { $AsJob = $true }
@ -72,7 +72,8 @@ foreach( $local:p in $CliParams ) {
if( $skipFirst ) { $p = $p | Select-Object -Skip 1 }
}
$dcParams = $p | Where-Object { $_ } | ForEach-Object {
$local:dcParams=@()
$local:dcParams = $p | Where-Object { $_ } | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
@ -81,16 +82,22 @@ foreach( $local:p in $CliParams ) {
$local:dcPath = Join-Path $_ 'docker-compose.yml'
if( -not (Test-Path $dcPath) ) { if( $Recurse ) { return } else { throw "ERROR: dcPath ($dcPath) does not exists" } }
Write-Verbose "& docker-compose --file $dcPath $dcParams"
if( $Wait -and -not $WhatIfPreference ) {
if( $Wait ) {
if( $WhatIfPreference ) {
Write-Host -ForegroundColor DarkCyan "Wait for bg jobs to complete !"
} else {
CompleteJobs
}
}
if( -not $dcParams ) { continue }
if( -not $dcParams ) { continue }
if( $WhatIfPreference ) {
Write-Host "In $dcPath Run $(if($AsJob){"(bg) "})with: $dcParams"
} elseif( $AsJob ) {
if( $WhatIfPreference ) {
Write-Host "In $dcPath Run $(if($AsJob){"(bg) "})with: $dcParams"
} else {
Write-Verbose "& docker-compose --file $dcPath $dcParams"
if( $AsJob ) {
$JobQueue += Start-Job -ArgumentList @($dcPath,$dcParams) -ScriptBlock {
param($dcPath,$dcParams)
[PSCustomObject] $([ordered]@{
@ -102,9 +109,9 @@ foreach( $local:p in $CliParams ) {
} else {
& docker-compose --file $dcPath $dcParams
}
}
}
}
# if( $WhatIfPreference ) { return }

View File

@ -15,7 +15,7 @@
[switch]$NoPull,
[array]$PullParams,
[array]$LogsParams,
[array]$UpParams,
[array]$UpParams=@('-d'),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[array]$Containers
)

View File

@ -15,7 +15,7 @@
[switch]$NoPull,
[array]$PullParams,
[array]$LogsParams,
[array]$UpParams,
[array]$UpParams=@('-d'),
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[array]$Containers
)
@ -48,7 +48,8 @@ $PullParams[0] = @('&','pull' ) + $PullParams[0] + $Containers
$UpParams[0] = @('&', 'up' ) + $UpParams[0] + $Containers
$LogsParams[0] = @('logs' ) + $LogsParams[0] + $Containers
$local:allParams = $PullParams + @(@('!')) + $UpParams
if( -not $NoPull ) { $allParams += $PullParams + @(@('!')) }
$local:allParams += $UpParams
if( -not $NoLogs ) { $allParams += @(@('!')) + $LogsParams }
Invoke-DockerCompose -ProjectPath $ProjectPath -CliParams $allParams -Recurse:$Recurse -Depth $Depth