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:
parent
53226f09b4
commit
f947b0b3b4
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"package": {
|
||||
"Condition": [],
|
||||
"Name": "GitHub"
|
||||
}
|
||||
}
|
|
@ -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 }
|
||||
}
|
|
@ -23,15 +23,41 @@ function CompleteJobs{
|
|||
if( -not $JobQueue ) { return }
|
||||
$local:currentJobQueue = $JobQueue
|
||||
$JobQueue = @()
|
||||
$CleanupJobQueue += $currentJobQueue
|
||||
$CleanupJobQueue += $currentJobQueue.Job
|
||||
|
||||
Wait-Job $currentJobQueue | ForEach-Object {
|
||||
$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 {
|
||||
$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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue