Modules/businessdev.ALbuild.Apps/Public/Publish-BcContainerAppSet.ps1
|
function Publish-BcContainerAppSet { <# .SYNOPSIS Publishes several apps that belong together (e.g. an app and its test app) into a container, replacing what is already published. .DESCRIPTION Publishes each .app in the given order with Publish-BcContainerApp, -Sync and -Install. The apps of the set may replace each other: when -IfExists removes an app that another app of the set depends on, that dependent is removed first and published again later in the same call. An app outside the set that depends on a removed one stops the publish (DEPENDENT_BLOCKS_UNPUBLISH). Pass the files in dependency order (the app before its test app). .PARAMETER Name Container name. .PARAMETER AppFile The .app files on the host, in dependency order. .PARAMETER IfExists fail | unpublish (default) | force-sync | upgrade. See Publish-BcContainerApp. .PARAMETER SyncMode Add | Clean (default) | Development | ForceSync. Clean drops the data of the replaced versions; the new versions are synced with Add. See Publish-BcContainerApp. .PARAMETER SkipVerification Publish without signature verification (for unsigned development apps). .PARAMETER DockerExecutable The Docker executable to use (default 'docker'). .EXAMPLE Publish-BcContainerAppSet -Name bld -AppFile .\out\App.app, .\out\App.Test.app -SkipVerification .OUTPUTS One PSCustomObject per app: Name, Id, Version, File. #> [CmdletBinding(SupportsShouldProcess)] [OutputType([PSCustomObject])] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [Alias('ContainerName')] [string] $Name, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string[]] $AppFile, [ValidateSet('fail', 'unpublish', 'force-sync', 'upgrade')] [string] $IfExists = 'unpublish', [ValidateSet('Add', 'Clean', 'Development', 'ForceSync')] [string] $SyncMode = 'Clean', [switch] $SkipVerification, [string] $DockerExecutable = 'docker' ) foreach ($f in $AppFile) { if (-not (Test-Path -LiteralPath $f)) { throw "App file not found: '$f'." } } if (-not $PSCmdlet.ShouldProcess($Name, "Publish $($AppFile.Count) app(s)")) { return } # The ids of the whole set, read by the container (works for runtime packages too). $infos = @(Get-BcContainerAppFileInfo -ContainerName $Name -Path $AppFile -DockerExecutable $DockerExecutable) $ids = @($infos | ForEach-Object { "$($_.Id)" } | Where-Object { $_ }) if ($ids.Count -lt $AppFile.Count) { Write-ALbuildLog -Level Warning "Read the app id of $($ids.Count) of $($AppFile.Count) file(s); an app whose id is unknown is not replaced together with the others." } Write-ALbuildLog ("Publishing {0} app(s) into '{1}' (if-exists {2}, sync mode {3}): {4}" -f $AppFile.Count, $Name, $IfExists, $SyncMode, ((@($infos | ForEach-Object { "$($_.Name) $($_.Version)" })) -join ', ')) foreach ($f in $AppFile) { Publish-BcContainerApp -Name $Name -AppFile $f -SkipVerification:$SkipVerification -Sync -Install -SyncMode $SyncMode ` -IfExists $IfExists -ReplaceableAppId $ids -DockerExecutable $DockerExecutable } foreach ($i in $infos) { [PSCustomObject]@{ Name = "$($i.Name)"; Id = "$($i.Id)"; Version = "$($i.Version)"; File = "$($i.File)" } } } |