DockerCompose commands refactoring

All dc... commands are now based on Invoke-DockerCompose.
dco is aliased to Invoke-DockerCompose.
dco_ is aliased to the docker-compose binary.
'&' and '!' shorthand introduced to dco to execut in bg as job and wait
for all bg jobs to complete respectively.
This commit is contained in:
lksz 2021-01-15 01:15:54 -05:00
parent c453e5bdea
commit dcc9113cda
13 changed files with 172 additions and 70 deletions

View file

@ -8,24 +8,47 @@
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[string[]]$UpCliParams,
[string[]]$ProjectPath,
[switch]$Recurse,
[int]$Depth=1,
[switch]$NoLogs,
[switch]$NoPull,
[array]$PullParams,
[array]$LogsParams,
[array]$UpParams,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
[array]$Containers
)
$local:dcParams = [string]::Empty
if( $CliParams ) {
$dcParams = $CliParams | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
$local:ForceNoFollow = $false
if( -not $ProjectPath ) {
$ProjectPath=@($PWD)
$ForceNoFollow = $Recurse
} elseif( -not $NoLogs ) {
$ForceNoFollow=$($ProjectPath.Length -gt 1)
}
if( -not $Containers -or ($Containers[0] -is [string]) ) { $Containers = @($Containers,@($null)) }
if( -not $UpParams -or ($UpParams[0] -is [string]) ) { $UpParams = @($UpParams,@($null)) }
if( -not $PullParams -or ($PullParams[0] -is [string]) ) { $PullParams = @($PullParams,@($null)) }
if( -not $LogsParams -or ($LogsParams[0] -is [string]) ) { $LogsParams = @($LogsParams,@($null)) }
if( -not $LogsParams[0] ) {
$local:tailLen = 10
$logsParams[0] = @()
if( -not $ForceNoFollow ) {
$tailLen = 40
$logsParams[0] += @('--follow')
}
}
$local:dcUpParams = $UpCliParams + $dcParams
$ProjectPath | ForEach-Object {
$local:dcPath = $(Resolve-Path $(Join-Path $_ docker-compose.yml))
Write-Verbose "docker-compose --file $dcPath up -d --remove-orphans $dcUpParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams"
docker-compose --file $dcPath up -d --remove-orphans $dcUpParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams
$logsParams[0] += @("--tail=$tailLen")
}
$PullParams[0] = @('&','pull' ) + $PullParams[0] + $Containers
$UpParams[0] = @('&', 'up' ) + $UpParams[0] + $Containers
$LogsParams[0] = @('logs' ) + $LogsParams[0] + $Containers
$local:allParams = $PullParams + @(@('!')) + $UpParams
if( -not $NoLogs ) { $allParams += @(@('!')) + $LogsParams }
Invoke-DockerCompose -ProjectPath $ProjectPath -CliParams $allParams -Recurse:$Recurse -Depth $Depth