Skip to content

Commit

Permalink
NuGet changes (#3264)
Browse files Browse the repository at this point in the history
Rename appinfo cache from AppInfo.json to cache_AppInfo.json (in order
for it to be picked up by .gitignore)
Proof of concept functionality for NuGet feeds:
- Add trusted feeds to ContainerHelper settings.
- Search all trusted feeds for packages in Get-BcNuGetPackage
- Some refactoring of NuGet code
- Allow searching for Earliest, Latest, Any or Exact version of NuGet
package
- Support NuGet Versioning schema

---------

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk committed Dec 17, 2023
1 parent 943df1d commit c083763
Show file tree
Hide file tree
Showing 20 changed files with 972 additions and 342 deletions.
2 changes: 1 addition & 1 deletion AppHandling/Publish-NavContainerApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ try {
$force = $true
if ($checkAlreadyInstalled) {
if ($isCloudBcContainer) {
$installedApps = Invoke-ScriptInAlpacaBcContainer -authContext $bcAuthContext -containerId $environment -scriptblock {
$installedApps = Invoke-ScriptInCloudBcContainer -authContext $bcAuthContext -containerId $environment -scriptblock {
Get-NAVAppInfo -ServerInstance $serverInstance -TenantSpecificProperties -tenant 'default' | Where-Object { $_.IsInstalled -eq $true } | ForEach-Object { Get-NAVAppInfo -ServerInstance $serverInstance -TenantSpecificProperties -tenant 'default' -id $_.AppId -publisher $_.publisher -name $_.name -version $_.Version }
}
}
Expand Down
53 changes: 31 additions & 22 deletions AppHandling/Run-AlPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,34 @@ Function UpdateLaunchJson {

}

function GetInstalledAppIds {
Param(
[bool] $useCompilerFolder,
[string] $packagesFolder,
[string] $compilerFolder,
[bool] $filesOnly,
[hashtable] $Parameters
)
if ($useCompilerFolder) {
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app') | Select-Object -ExpandProperty FullName)
$installedApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'cache_AppInfo.json'))
$installedAppIds = @($installedApps | ForEach-Object { $_.AppId } )
$compilerFolderAppFiles = @(Get-ChildItem -Path (Join-Path $compilerFolder 'symbols/*.app') | Select-Object -ExpandProperty FullName)
$installedAppIds += @(GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $compilerFolder 'symbols/cache_AppInfo.json') | ForEach-Object { $_.AppId } )

}
elseif (!$filesOnly) {
$installedAppIds = @(Invoke-Command -ScriptBlock $GetBcContainerAppInfo -ArgumentList $Parameters | ForEach-Object { $_.AppId })
}
else {
$installedAppIds = @()
}
Write-Host "::group::Installed AppIds"
$installedAppIds | ForEach-Object { Write-Host "- $_" }
Write-Host "::endgroup::"
return $installedAppIds
}

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

Expand Down Expand Up @@ -1222,16 +1250,7 @@ $Parameters = @{
"containerName" = $containerName
"tenant" = $tenant
}
if ($useCompilerFolder) {
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app') | Select-Object -ExpandProperty FullName)
$installedAppIds = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'AppInfoCache.json') | ForEach-Object { $_.AppId } )
}
elseif (!$filesOnly) {
$installedAppIds = @(Invoke-Command -ScriptBlock $GetBcContainerAppInfo -ArgumentList $Parameters | Select-Object -ExpandProperty 'AppId')
}
else {
$installedAppIds = @()
}
$installedAppIds = @(GetInstalledAppIds -useCompilerFolder $useCompilerFolder -filesOnly $filesOnly -compilerFolder $compilerFolder -packagesFolder $packagesFolder -Parameters $Parameters)
$missingAppDependencies = @($missingAppDependencies | Where-Object { $installedAppIds -notcontains $_ })
if ($missingAppDependencies) {
if ($gitHubActions) { Write-Host "::group::Installing app dependencies" }
Expand Down Expand Up @@ -1378,17 +1397,7 @@ $Parameters = @{
"containerName" = $containerName
"tenant" = $tenant
}
if ($useCompilerFolder) {
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app') | Select-Object -ExpandProperty FullName)
$installedApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'AppInfoCache.json'))
$installedAppIds = @($installedApps | ForEach-Object { $_.AppId } )
}
elseif (!$filesOnly) {
$installedAppIds = @(Invoke-Command -ScriptBlock $GetBcContainerAppInfo -ArgumentList $Parameters | ForEach-Object { $_.AppId })
}
else {
$installedAppIds = @()
}
$installedAppIds = @(GetInstalledAppIds -useCompilerFolder $useCompilerFolder -filesOnly $filesOnly -compilerFolder $compilerFolder -packagesFolder $packagesFolder -Parameters $Parameters)
$missingTestAppDependencies = @($missingTestAppDependencies | Where-Object { $installedAppIds -notcontains $_ })
if ($missingTestAppDependencies) {
if ($gitHubActions) { Write-Host "::group::Installing test app dependencies" }
Expand Down Expand Up @@ -1561,7 +1570,7 @@ $Parameters = @{
"containerName" = $containerName
"tenant" = $tenant
}
$installedAppIds = @(Invoke-Command -ScriptBlock $GetBcContainerAppInfo -ArgumentList $Parameters | Select-Object -ExpandProperty 'AppId')
$installedAppIds = @(GetInstalledAppIds -useCompilerFolder $useCompilerFolder -filesOnly $filesOnly -compilerFolder $compilerFolder -packagesFolder $packagesFolder -Parameters $Parameters)
$missingTestAppDependencies = @($missingTestAppDependencies | Where-Object { $installedAppIds -notcontains $_ })
if ($missingTestAppDependencies) {
if ($gitHubActions) { Write-Host "::group::Installing test app dependencies" }
Expand Down
4 changes: 4 additions & 0 deletions BC.HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ function Get-ContainerHelperConfig {
"tt" = "br"
"uy" = "br"
"zw" = "w1"
"im" = "gb"
"gg" = "gb"
}
"mapNetworkSettings" = [PSCustomObject]@{
}
Expand Down Expand Up @@ -108,6 +110,8 @@ function Get-ContainerHelperConfig {
"OAuthHostName" = "b52e8b6a-2953-4a08-8e28-5cf45a2dffdc"
"OAuthScopes" = "api://b52e8b6a-2953-4a08-8e28-5cf45a2dffdc/.default offline_access"
}
"TrustedNuGetFeeds" = @(
)
}

if ($isInsider) {
Expand Down
6 changes: 5 additions & 1 deletion BC.NuGetHelper.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# NuGet specific functions
if (-not (([System.Management.Automation.PSTypeName]"NuGetFeed").Type)) {
. (Join-Path $PSScriptRoot "NuGet\NuGetFeedClass.ps1")
}
. (Join-Path $PSScriptRoot "NuGet\New-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Find-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Get-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Push-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Publish-BcNuGetPackageToContainer.ps1")
. (Join-Path $PSScriptRoot "NuGet\Copy-BcNuGetPackageToFolder.ps1")
. (Join-Path $PSScriptRoot "NuGet\Download-BcNuGetPackageToFolder.ps1")
Binary file modified BC.NuGetHelper.psd1
Binary file not shown.
6 changes: 3 additions & 3 deletions BcContainerHelper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FunctionsToExport = 'Add-FontsToBcContainer', 'Add-GitToAlProjectFolder',
'Convert-ModifiedObjectsToAl', 'ConvertTo-HashTable',
'ConvertTo-OrderedDictionary', 'Convert-Txt2Al', 'Copy-AlSourceFiles',
'Copy-AppFilesToCompilerFolder', 'Copy-BcEnvironment',
'Copy-BcNuGetPackageToFolder', 'Copy-CompanyInBcContainer',
'Download-BcNuGetPackageToFolder', 'Copy-CompanyInBcContainer',
'Copy-FileFromBcContainer', 'Copy-FileFromCloudBcContainer',
'Copy-FileToBcContainer', 'Copy-FileToCloudBcContainer',
'Copy-ItemFromBcContainer', 'Copy-ItemToBcContainer',
Expand Down Expand Up @@ -115,7 +115,7 @@ FunctionsToExport = 'Add-FontsToBcContainer', 'Add-GitToAlProjectFolder',
'Get-BcEnvironmentOperations', 'Get-BcEnvironmentPublishedApps',
'Get-BcEnvironments', 'Get-BcEnvironmentScheduledUpgrade',
'Get-BcEnvironmentUpdateWindow', 'Get-BcEnvironmentUsedStorage',
'Get-BcNotificationRecipients', 'Get-BcNuGetPackage',
'Get-BcNotificationRecipients', 'Find-BcNuGetPackage', 'Get-BcNuGetPackage',
'Get-BestBcContainerImageName', 'Get-BestGenericImageName',
'Get-CloudBcContainerEventLog',
'Get-CloudBcContainerServerConfiguration',
Expand Down Expand Up @@ -195,7 +195,7 @@ AliasesToExport = 'Add-FontsToNavContainer', 'Backup-NavContainerDatabases',
'Convert-AlcOutputToAzureDevOps', 'Copy-CompanyInNavContainer',
'Copy-FileFromAlpacaBcContainer', 'Copy-FileFromNavContainer',
'Copy-FileToAlpacaBcContainer', 'Copy-FileToNavContainer',
'Create-AadAppsForBC', 'Create-AadUsersInNavContainer',
'Copy-BcNuGetPackageToFolder', 'Create-AadAppsForBC', 'Create-AadUsersInNavContainer',
'Create-AlProjectFolderFromNavContainer', 'Enter-NavContainer',
'Export-NavContainerDatabasesAsBacpac',
'Extract-FilesFromNavContainerImage',
Expand Down
4 changes: 2 additions & 2 deletions CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ try {

Write-Host "Enumerating Apps in CompilerFolder $symbolsPath"
$compilerFolderAppFiles = @(Get-ChildItem -Path (Join-Path $symbolsPath '*.app') | Select-Object -ExpandProperty FullName)
$compilerFolderApps = @(GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $symbolsPath 'AppInfoCache.json'))
$compilerFolderApps = @(GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $symbolsPath 'cache_AppInfo.json'))

Write-Host "Enumerating Apps in Symbols Folder $appSymbolsFolder"
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $appSymbolsFolder '*.app') | Select-Object -ExpandProperty FullName)
$existingApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $appSymbolsFolder 'AppInfoCache.json'))
$existingApps = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $appSymbolsFolder 'cache_AppInfo.json'))

$depidx = 0
while ($depidx -lt $dependencies.Count) {
Expand Down
2 changes: 1 addition & 1 deletion CompilerFolderHandling/Copy-AppFilesToCompilerFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Copy-AppFilesToCompilerFolder {
Write-Host "Copy app files to compiler folder"
$symbolsPath = Join-Path $compilerFolder 'symbols'
$compilerFolderAppFiles = @(Get-ChildItem -Path (Join-Path $symbolsPath '*.app') | Select-Object -ExpandProperty FullName)
$compilerFolderApps = GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $symbolsPath 'AppInfoCache.json')
$compilerFolderApps = GetAppInfo -AppFiles $compilerFolderAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $symbolsPath 'cache_AppInfo.json')
if ($checkAlreadyInstalled) {
$appFiles = @(Sort-AppFilesByDependencies -appFiles $appFiles -includeOnlyAppIds $includeOnlyAppIds -excludeInstalledApps $compilerFolderApps -WarningAction SilentlyContinue)
}
Expand Down
21 changes: 12 additions & 9 deletions ContainerHandling/Restart-NavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ function Restart-BcContainer {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

if ($renewBindings) {
if ((docker inspect -f '{{.State.Running}}' $containerName) -eq "true") {
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock {
Set-Content -Path "c:\run\PublicDnsName.txt" -Value ""
}
}
else {
$tempFile = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
if ((docker inspect -f '{{.State.Running}}' $containerName) -eq "true") {
Invoke-ScriptInBcContainer -containerName $containerName -useSession:$false -ScriptBlock { Param( $renewBindings )
if ($renewBindings) { Set-Content -Path "c:\run\PublicDnsName.txt" -Value "" }
Set-Content -Path "c:\run\startcount.txt" -Value "0"
} -argumentList $renewBindings.IsPresent
}
else {
$tempFile = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
if ($renewBindings) {
Set-Content -Path $tempFile -Value ""
docker cp $tempFile "$($containerName):c:\run\PublicDnsName.txt"
Remove-Item -Path $tempFile
}
Set-Content -Path $tempFile -Value "0"
docker cp $tempFile "$($containerName):c:\run\startcount.txt"
Remove-Item -Path $tempFile
}

Write-Host "Removing Session $containerName"
Expand Down
12 changes: 7 additions & 5 deletions HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ function Expand-7zipArchive {
[Parameter(Mandatory = $true)]
[string] $Path,
[string] $DestinationPath,
[switch] $use7zipIfAvailable = $bcContainerHelperConfig.use7zipIfAvailable
[switch] $use7zipIfAvailable = $bcContainerHelperConfig.use7zipIfAvailable,
[switch] $silent
)

$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"
Expand All @@ -378,7 +379,7 @@ function Expand-7zipArchive {
}

if ($use7zip) {
Write-Host "using 7zip"
if (!$silent) { Write-Host "using 7zip" }
Set-Alias -Name 7z -Value $7zipPath
$command = '7z x "{0}" -o"{1}" -aoa -r' -f $Path, $DestinationPath
$global:LASTEXITCODE = 0
Expand All @@ -388,7 +389,7 @@ function Expand-7zipArchive {
}
}
else {
Write-Host "using Expand-Archive"
if (!$silent) { Write-Host "using Expand-Archive" }
if ([System.IO.Path]::GetExtension($path) -eq '.zip') {
Expand-Archive -Path $Path -DestinationPath "$DestinationPath" -Force
}
Expand Down Expand Up @@ -1114,7 +1115,7 @@ function GetAppInfo {
$appInfoCache = @{}
}
}
Write-Host "Getting .app info"
Write-Host "::group::Getting .app info $cacheAppInfoPath"
$binPath = Join-Path $compilerFolder 'compiler/extension/bin'
if ($isLinux) {
$alcPath = Join-Path $binPath 'linux'
Expand Down Expand Up @@ -1185,7 +1186,7 @@ function GetAppInfo {
}
}
Write-Host " (succeeded)"
if ($appInfoCache) {
if ($cacheAppInfoPath) {
$appInfoCache | Add-Member -MemberType NoteProperty -Name $path -Value $appInfo
$cacheUpdated = $true
}
Expand Down Expand Up @@ -1224,6 +1225,7 @@ function GetAppInfo {
$packageStream.Dispose()
}
}
Write-Host "::endgroup::"
}

function GetLatestAlLanguageExtensionUrl {
Expand Down
37 changes: 0 additions & 37 deletions NuGet/Copy-BcNuGetPackageToFolder.ps1

This file was deleted.

0 comments on commit c083763

Please sign in to comment.