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

View File

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

View File

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