diff --git a/GitHub/Get-GitHubReleaseAssets.ps1 b/GitHub/Get-GitHubReleaseAssets.ps1 new file mode 100644 index 0000000..1ae6ca2 --- /dev/null +++ b/GitHub/Get-GitHubReleaseAssets.ps1 @@ -0,0 +1,18 @@ +[CmdletBinding()]param( + [Parameter(Mandatory)] + [string]$GitHubProject, + [string]$tag='latest', + [Alias("Match")] + [string]$MatchPattern +) + +filter Out-Matched { $_ | Where-Object { $_ -match $MatchPattern } } +Set-Alias FinalOutput Out-Default +if( $MatchPattern ) { Set-Alias FinalOutput Out-Matched } + +Invoke-WebRequest https://github.com/$GitHubProject/releases/$tag -ErrorAction Stop | + Select-Object -ExpandProperty Links | + Where-Object href -match 'download/.*' | + Select-Object -ExpandProperty href | + ForEach-Object { "https://github.com$_" } | + FinalOutput diff --git a/GitHub/_.package.json b/GitHub/_.package.json new file mode 100644 index 0000000..5d501ae --- /dev/null +++ b/GitHub/_.package.json @@ -0,0 +1,6 @@ +{ + "package": { + "Condition": [], + "Name": "GitHub" + } +} diff --git a/base/Invoke-WebDownload.ps1 b/base/Invoke-WebDownload.ps1 new file mode 100644 index 0000000..35da14d --- /dev/null +++ b/base/Invoke-WebDownload.ps1 @@ -0,0 +1,44 @@ +[CmdletBinding()]param( + [Parameter(Position=1)] + [string]$OutputPath, + [Parameter(Mandatory,Position=0,ValueFromPipeline)] + [string]$Url, + [switch]$Force, + [switch]$PassThru +) + +process { + $local:outputFileName=[string]::Empty + if( -not $OutputPath ) { + $OutputPath = Join-Path $(Get-Item $PWD) '' + } elseif( Test-Path -Type Container $OutputPath ) { + $OutputPath = Join-Path $(Get-Item $OutputPath) '' + } + + if( $OutputPath -notmatch '[/\\]$' ) { + $outputFileName = Split-Path -Leaf $OutputPath + $OutputPath = Join-Path $(Split-Path -Parent $OutputPath) '' + } + + if( -not (Test-Path $OutputPath) -and $Force ) { + New-Item -Type Directory $OutputPath + } + + if( -not (Test-Path $OutputPath) ) { throw "Destination $OutputPath does not exists, aborting!" } + + if( -not $outputFileName ) { + $outputFileName = Split-Path -Leaf $Url + } + + $outputFileName = Join-Path $OutputPath $outputFileName + + if( (Test-Path $outputFileName) -and -not $Force) { + throw "$OutputPath already exists" + } + + Write-Verbose "About to start download from:`n`t$Url`n`tto`n`t$outputFileName`n" + + Invoke-WebRequest -Uri $Url -OutFile $outputFileName + + if( $PassThru ) { Get-Item $outputFileName } +} diff --git a/docker/Invoke-DockerCompose.ps1 b/docker/Invoke-DockerCompose.ps1 index 6741674..8c6d96f 100644 --- a/docker/Invoke-DockerCompose.ps1 +++ b/docker/Invoke-DockerCompose.ps1 @@ -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 } diff --git a/docker/dcl.ps1 b/docker/dcl.ps1 index 8d72c39..96a9f23 100644 --- a/docker/dcl.ps1 +++ b/docker/dcl.ps1 @@ -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 diff --git a/docker/dcll.ps1 b/docker/dcll.ps1 index dd2b3cc..5b7c1fe 100644 --- a/docker/dcll.ps1 +++ b/docker/dcll.ps1 @@ -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 diff --git a/docker/dcre.ps1 b/docker/dcre.ps1 index f62ccce..2d17120 100644 --- a/docker/dcre.ps1 +++ b/docker/dcre.ps1 @@ -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