RelateIT_BC.psm1
function Install-Dependencies { Param ( [Parameter(ValueFromPipelineByPropertyName = $True)] $ContainerName = '', [Parameter(ValueFromPipelineByPropertyName = $True)] $DependenciesYAML = '' ) write-host $(' ____ __ _ / __ \___ ____ ___ ____ ____/ /__ ____ _____(_)__ _____ / / / / _ \/ __ \/ _ \/ __ \/ __ / _ \/ __ \/ ___/ / _ \/ ___/ / /_/ / __/ /_/ / __/ / / / /_/ / __/ / / / /__/ / __(__ ) /_____/\___/ .___/\___/_/ /_/\__,_/\___/_/ /_/\___/_/\___/____/ /_/ ') -ForegroundColor Yellow function DownloadApps { Param ( [Parameter(ValueFromPipelineByPropertyName = $True)] $ContainerName = '', [Parameter(ValueFromPipelineByPropertyName = $True)] $DependenciesYAML = '' ) az login $AllApps = @() $Feed = ""; $package = ""; $version = ""; foreach ($line in [System.IO.File]::ReadLines("$DependenciesYAML")) { $words = $line.Split(" "); foreach ($word in $words) { if ($Feed -eq "next") { $Feed = $word; } if ($word -eq "Feed:") { $Feed = "next"; } if ($package -eq "next") { $package = $word; } if ($word -eq "Package:") { $package = "next"; } if ($version -eq "next") { $version = $word; $AllApps += [PSCustomObject]@{ Feed = $Feed Package = $package Version = $version } } if ($word -eq "Version:") { $version = "next"; } } } foreach ($app in $AllApps) { $versionVar = $app.Version $versionVar = $versionVar.Replace("'", "") $last_index = $versionVar.LastIndexOf('.') $cleanVersion = $versionVar.Remove($last_index, 1).Insert($last_index, '-') $feed = $app.Feed $feed = $feed.Replace("'", "") $package = $app.Package; $package = $package.Replace("'", "") az artifacts universal download --organization "https://dev.azure.com/relateit/" --feed "$feed" --name "$package" --version "$cleanVersion" --path "C:\ProgramData\BcContainerHelper\Extensions\$ContainerName\my" } } DownloadApps -ContainerName $ContainerName -DependenciesYAML $DependenciesYAML Invoke-ScriptInBcContainer -scriptblock { Param($ContainerName) function Install-AppDependencies { [CmdletBinding()] param( [string] $Path, [Parameter(ValueFromPipelineByPropertyName = $True)] $ContainerName = '' ) function AddToDependencyTree() { param( [PSObject] $App, [PSObject[]] $DependencyArray, [PSObject[]] $AppCollection, [Int] $Order = 1, [Parameter(ValueFromPipelineByPropertyName = $True)] $containerName = '' ) foreach ($Dependency in $App.Dependencies) { $DependencyArray = AddToDependencyTree ` -App ($AppCollection | where AppId -eq $Dependency.AppId) ` -DependencyArray $DependencyArray ` -AppCollection $AppCollection ` -Order ($Order - 1) } if (-not($DependencyArray | where AppId -eq $App.AppId)) { $DependencyArray += $App try { ($DependencyArray | where AppId -eq $App.AppId).ProcessOrder = $Order } catch { } } else { if (($DependencyArray | where AppId -eq $App.AppId).ProcessOrder -gt $Order) { ($DependencyArray | where AppId -eq $App.AppId).ProcessOrder = $Order } } $DependencyArray } #Script execution #. (Join-Path $PSScriptRoot "GetDependencies_TestApps.ps1") if ($Path -eq "") { $Path = "C:\ProgramData\BcContainerHelper\Extensions\$containerName\my" } $AllAppFiles = Get-ChildItem -Path $Path -Filter "*.app" $AllApps = @() foreach ($AppFile in $AllAppFiles) { $App = Get-NAVAppInfo -Path $AppFile.FullName $AllApps += [PSCustomObject]@{ AppId = $App.AppId Version = $App.Version Name = $App.Name Publisher = $App.Publisher ProcessOrder = 0 Dependencies = $App.Dependencies Path = $AppFile.FullName } } $FinalResult = @() $AllApps | foreach { $FinalResult = AddToDependencyTree -App $_ -DependencyArray $FinalResult -AppCollection $AllApps -Order $AllApps.Count -ContainerName $ContainerName } Write-Output $FinalResult | sort ProcessOrder | ft foreach ($f in $FinalResult) { if (-not ([string]::IsNullOrEmpty($f.Path))) { Publish-NAVApp -ServerInstance BC -Path $f.Path -SkipVerification -ErrorAction Ignore Sync-NavApp -ServerInstance BC -Name $f.Name -Version $f.Version -ErrorAction Ignore Install-NAVApp -ServerInstance BC -Name $f.Name -ErrorAction Ignore } } Restart-NAVServerInstance -ServerInstance BC -force } Install-AppDependencies -ContainerName $ContainerName } -containerName $ContainerName -argumentList $ContainerName } Export-ModuleMember -Function Install-Dependencies |