docker and docker-compose commands

Invoke-DockerCompose which will be the basis of all other future dc
prefixed commands (which currently contains to much copy-pasted code)
This commit is contained in:
lksz 2021-01-13 01:02:37 -05:00
parent 6e56ac6097
commit 24b5e928d0
14 changed files with 183 additions and 17 deletions

View File

@ -1,3 +1,7 @@
[CmdletBinding()]param([string[]]$Remotes = 'All')
[CmdletBinding()]param(
[string[]]$Remotes = 'All',
[switch]$OneLine
Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower())
)
Invoke-ViaAnsible -Command "Update-OSz -Mode Auto" -Remotes:$($Remotes.ToLower()) -OneLine:$OneLine

View File

@ -29,7 +29,7 @@ begin {
}
if( [string]::IsNullOrWhiteSpace($DirPermission) ) {
$DirPermission = $env:SZ_DIR_PERM ?? "664"
$DirPermission = $env:SZ_DIR_PERM ?? "775"
}
$cmdArgs = "-Recurse:`$$(-not $NonRecursive) -Force:`$$Force"

View File

@ -5,8 +5,8 @@ param(
$script:yayCli = "cat /run/check.yay.updates/list"
switch( $Mode ){
'Update' { $yayCli = "yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux" }
'Auto' { $yayCli = "yay -Syu --needed --noconfirm --ignore docker || yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux --noconfirm" }
'Update' { $yayCli = "yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux,zfs-utils" }
'Auto' { $yayCli = "yay -Syu --needed --noconfirm --ignore docker || yay -Syu --needed --ignore docker,linux,linux-api-headers,linux-firmware,linux-headers,zfs-linux,zfs-utils --noconfirm" }
'All' { $yayCli = "yay -Syu --needed" }
}

1
docker/Aliases/dcall.ps1 Normal file
View File

@ -0,0 +1 @@
Invoke-DockerCompose

View File

@ -14,7 +14,7 @@
)
$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml')
$local:editCandidates = @('docker-compose.yml','.base.docker-compose.yml','Dockerfile')
$local:editFiles = @()
foreach( $local:fileName in $EditCandidates ) {
foreach( $local:path in $ProjectPath ) {

View File

@ -0,0 +1,114 @@
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[switch]$Recurse,
[int]$Depth=1,
[switch]$Force,
[switch]$OneLine,
[Parameter(Position = 0, ValueFromRemainingArguments = $true, mandatory)]
[array]$CliParams
)
$script:JobQueue = @()
$script:CleanupJobQueue = @()
function CompleteJobs{
if( -not $JobQueue ) { return }
$local:currentJobQueue = $JobQueue
$JobQueue = @()
$CleanupJobQueue += $currentJobQueue
Wait-Job $currentJobQueue | ForEach-Object {
$_ | Receive-Job | ForEach-Object {
Write-Host "---: $($_.Path) | $($_.Params)" -ForegroundColor Cyan
$_.Results
}
}
Write-Host '--- Background jobs completed' -ForegroundColor Green
}
if( $CliParams[0] -is [string] ) {
$CliParams = @($CliParams,@($null))
}
$local:dcPathList = $ProjectPath | ForEach-Object {
if( (Test-Path (Join-Path $_ 'docker-compose.yml')) -and -not $Recurse ) {
Resolve-Path $_
} elseif( $Recurse ) {
$local:gciParams = [ordered]@{
Recurse = $true
}
if( $Depth ) {
$gciParams.Depth = $Depth
}
Get-ChildItem -Path $_ -Include 'docker-compose.yml' @gciParams |
Select-Object -ExpandProperty Directory |
Where-Object { $Force -or -not (Test-Path $(Join-Path $_ .noauto.all)) }
# _DIRS_=$( find . -mindepth 1 -maxdepth 1 -type d -exec test -f {}/docker-compose.yml \; -exec test -f {}/.ask.all \; -print | sort )
# _DIRS_="$_DIRS_ $( find . -mindepth 1 -maxdepth 1 -type d -exec test -f {}/docker-compose.yml \; -not -exec test -f {}/.ask.all \; -not -exec test -f {}/.noauto.all \; -print | sort )"
}
}
if( -not $dcPathList ) { return }
Write-Verbose "$dcPathList"
foreach( $local:p in $CliParams ) {
if( -not $p ) { continue }
$local:AsJob = $false;
$local:Wait = $false;
if( $p -isnot [String] ) {
$local:skipFirst = $true
switch( $p[0] ) {
'&' { $AsJob = $true }
'!' { $Wait = $true }
default { $skipFirst = $false }
}
if( $skipFirst ) { $p = $p | Select-Object -Skip 1 }
}
$dcParams = $p | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
$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" } }
Write-Verbose "& docker-compose --file $dcPath $dcParams"
if( $Wait ) {
CompleteJobs
}
if( -not $dcParams ) { continue }
if( $AsJob ) {
$JobQueue += Start-Job -ArgumentList @($dcPath,$dcParams) -ScriptBlock {
param($dcPath,$dcParams)
[PSCustomObject] $([ordered]@{
Path = $dcPath
Params = $dcParams
Results = $(& docker-compose --file $dcPath $dcParams)
})
}
} else {
& docker-compose --file $dcPath $dcParams
}
}
}
CompleteJobs
if( $CleanupJobQueue ) {
$CleanupJobQueue | Remove-Job
}

29
docker/dcrefresh.ps1 Normal file
View File

@ -0,0 +1,29 @@
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath,
[switch]$Recurse,
[int]$Depth=1,
[switch]$Force,
[switch]$OneLine,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[array]$CliParams=@('&','up','-d')
)
$local:passParams = [ordered]@{
Depth = $Depth
Force = $Force
OneLine = $OneLine
CliParams = $CliParams
}
if( -not $ProjectPath -and -not $Recurse ) { $Recurse = $true }
if( $ProjectPath ) { $passParams.ProjectPath = $ProjectPath }
if( $Recurse ) { $passParams.Recurse = $Recurse }
Invoke-DockerCompose @passParams

View File

@ -1,11 +1,26 @@
#[CmdletBinding(SupportsShouldProcess)]param()
[CmdletBinding(SupportsShouldProcess)]param(
[ArgumentCompleter({ param (
$commandName,
$parameterName,
$wordToComplete,
$commandAst,
$fakeBoundParameters
)
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[string[]]$UpCliParams,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
)
$local:dcParams = [string]::Empty
if( $args ) {
$dcParams = $args | ForEach-Object {
if( $_ -match "(?:^'[^']+'$)|(?:^`"[^`"]+`"$)|(?:^[^\s]+$)" ) { $_ }
else { "'$($_.Replace( "'", "''" ))'" }
}
$local:passParams = [ordered]@{
ProjectPath=$ProjectPath
UpCliParams=@('--force-recreate')
}
docker-compose up -d --force-recreate --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams
if( $UpCliParams ) { $passParams.UpCliParams += $UpCliParams }
if( $CliParams ) { $passParams.CliParams = $CliParams }
dcup @passParams
# docker-compose --file $dcPath up -d --force-recreate --remove-orphans $dcParams && docker-compose logs --follow --tail 10 $dcParams

View File

@ -9,6 +9,7 @@
[DockerComposeDirs]::_GetValidValues($wordToComplete,$true)
})]
[string[]]$ProjectPath=@($PWD),
[string[]]$UpCliParams,
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$CliParams
)
@ -20,9 +21,11 @@ if( $CliParams ) {
else { "'$($_.Replace( "'", "''" ))'" }
}
}
$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 $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams"
docker-compose --file $dcPath up -d --remove-orphans $dcParams && docker-compose --file $dcPath logs --follow --tail 10 $dcParams
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
}

View File

@ -1 +1 @@
docker-compose exec "$args"
docker-compose exec $args