Improvements and bug fixes

dcl, dcll and dcre were brokeen, fixed that
Invoke-WebDownload given a URL, automatically deduce the file file.
Get-GitHubReleaseAssets - Grab URLs from a GitHub release page.
Invoke-DockerCompose updated to display progress while waiting on
background jobs.
This commit is contained in:
lksz 2021-02-10 18:26:48 -05:00
parent 53226f09b4
commit f947b0b3b4
7 changed files with 122 additions and 21 deletions

View file

@ -1,6 +1,6 @@
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
@ -19,19 +19,45 @@
$script:JobQueue = @()
$script:CleanupJobQueue = @()
function CompleteJobs{
function CompleteJobs {
if( -not $JobQueue ) { return }
$local:currentJobQueue = $JobQueue
$JobQueue = @()
$CleanupJobQueue += $currentJobQueue
$CleanupJobQueue += $currentJobQueue.Job
Wait-Job $currentJobQueue | ForEach-Object {
$_ | Receive-Job | ForEach-Object {
Write-Host "---: $($_.Path) | $($_.Params)" -ForegroundColor Cyan
$_.Results
$local:sw = [System.Diagnostics.StopWatch]::StartNew()
$local:progress = [ordered]@{
Activity = "Waiting for docker-compose..."
ItemCount = $currentJobQueue.Count
}
while( $true ) {
$local:activeJobs = $($currentJobQueue | Where-Object Done -eq $false)
$progress.CurrentOperation = "Processing: $($activeJobs.Name -join ', ')..."
$progress.ItemProgress = $currentJobQueue.Count - $activeJobs.Count
$progress.Elapsed = $sw.Elapsed
Show-Progress @progress
$local:doneJobs = $activeJobs |
Select-Object -ExpandProperty Job |
Wait-Job -Any -Timeout 3
if( $doneJobs ) {
$doneJobs | ForEach-Object {
$_ | Receive-Job | ForEach-Object {
Write-Host "---: $($_.Path) | $($_.Params)" -ForegroundColor Cyan
$_.Results
foreach( $local:j in $currentJobQueue ) {
if( $j.Path -eq $_.Path ) {
$j.Done = $true
}
}
}
}
}
if( -not $($currentJobQueue.Done -contains $false) ) { break }
}
Write-Host '--- Background jobs completed' -ForegroundColor Green
Show-Progress -Activity $progress.Activity -Completed
}
if( $CliParams[0] -is [string] ) {
@ -81,7 +107,10 @@ foreach( $local:p in $CliParams ) {
$dcPathList | ForEach-Object {
$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" }
}
if( $Wait ) {
if( $WhatIfPreference ) {
@ -100,14 +129,18 @@ foreach( $local:p in $CliParams ) {
Write-Verbose $nextActionDescription
if( $AsJob ) {
$JobQueue += Start-Job -ArgumentList @($dcPath,$dcParams) -ScriptBlock {
param($dcPath,$dcParams)
[PSCustomObject] $([ordered]@{
Path = $dcPath
Params = $dcParams
Results = $(& docker-compose --file $dcPath $dcParams)
})
}
$JobQueue += ([PSCustomObject]([ordered]@{
Path = $dcPath
Name = Split-Path -Leaf $(Split-Path -Parent $dcPath)
Job = Start-Job -ArgumentList @($dcPath,$dcParams) -ScriptBlock {
param($dcPath,$dcParams)
[PSCustomObject] $([ordered]@{
Path = $dcPath
Params = $dcParams
Results = $(& docker-compose --file $dcPath $dcParams)
})}
Done = $false
}))
} else {
& docker-compose --file $dcPath $dcParams
}

View file

@ -13,7 +13,7 @@
[array]$CliParams
)
if( $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
if( -not $CliParams -or $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
$CliParams[0] = @('logs','--tail=40','follow') + $CliParams[0]
Invoke-DockerCompose -ProjectPath $ProjectPath -CliParams $CliParams

View file

@ -13,7 +13,7 @@
[array]$CliParams
)
if( $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
if( -not $CliParams -or $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
$CliParams[0] = @('logs') + $CliParams[0]
Invoke-DockerCompose -ProjectPath $ProjectPath -CliParams $CliParams

View file

@ -13,7 +13,7 @@
[array]$CliParams
)
if( $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
if( -not $CliParams -or $CliParams[0] -is [string] ) { $CliParams = @($CliParams,@($null)) }
$CliParams[0] = @('restart') + $CliParams[0]
Invoke-DockerCompose -ProjectPath $ProjectPath -CliParams $CliParams