Skip to content

Commit b0fc84f

Browse files
authored
Fix issue in CopyApps (#3436)
Fixes #3431 Fixes #3432 Fixes #3427 Fixes issues found by troubleshooting microsoft/AL-Go#969 --------- Co-authored-by: freddydk <[email protected]>
1 parent f578432 commit b0fc84f

10 files changed

+47
-85
lines changed

AppHandling/Copy-AppFilesToFolder.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#>
1212
function Copy-AppFilesToFolder {
1313
Param(
14+
[Parameter(Mandatory=$true)]
1415
$appFiles,
16+
[Parameter(Mandatory=$true)]
1517
[string] $folder
1618
)
17-
1819
CopyAppFilesToFolder -appFiles $appFiles -folder $folder
1920
}
2021
Export-ModuleMember -Function Copy-AppFilesToFolder

AppHandling/Get-TestsFromNavContainer.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ try {
171171
}
172172
} -argumentList "01:00:00"
173173

174-
$result = Invoke-ScriptInBcContainer -containerName $containerName { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testCodeunit, [string] $PsTestFunctionsPath, [string] $ClientContextPath, $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests)
174+
$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testCodeunit, [string] $PsTestFunctionsPath, [string] $ClientContextPath, $testPage, $version, $culture, $timezone, $debugMode, $ignoreGroups, $usePublicWebBaseUrl, $useUrl, $extensionId, $disabledtests)
175175

176176
$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
177177
if (!(Test-Path $newtonSoftDllPath)) {

AppHandling/Run-ConnectionTestToNavContainer.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ try {
200200
}
201201
else {
202202

203-
$result = Invoke-ScriptInBcContainer -containerName $containerName { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [timespan] $interactionTimeout, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl)
203+
$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [timespan] $interactionTimeout, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl)
204204

205205
$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
206206
if (!(Test-Path $newtonSoftDllPath)) {

AppHandling/Run-TestsInNavContainer.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ try {
374374
}
375375
}
376376

377-
$result = Invoke-ScriptInBcContainer -containerName $containerName { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testGroup, [string] $testCodeunit, [string] $testFunction, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [string] $XUnitResultFileName, [bool] $AppendToXUnitResultFile, [string] $JUnitResultFileName, [bool] $AppendToJUnitResultFile, [bool] $ReRun, [string] $AzureDevOps, [string] $GitHubActions, [bool] $detailed, [timespan] $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests)
377+
$result = Invoke-ScriptInBcContainer -containerName $containerName -usePwsh $false -scriptBlock { Param([string] $tenant, [string] $companyName, [string] $profile, [pscredential] $credential, [string] $accessToken, [string] $testSuite, [string] $testGroup, [string] $testCodeunit, [string] $testFunction, [string] $PsTestFunctionsPath, [string] $ClientContextPath, [string] $XUnitResultFileName, [bool] $AppendToXUnitResultFile, [string] $JUnitResultFileName, [bool] $AppendToJUnitResultFile, [bool] $ReRun, [string] $AzureDevOps, [string] $GitHubActions, [bool] $detailed, [timespan] $interactionTimeout, $testPage, $version, $culture, $timezone, $debugMode, $usePublicWebBaseUrl, $useUrl, $extensionId, $testRunnerCodeunitId, $disabledtests, $renewClientContextBetweenTests)
378378

379379
$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
380380
if (!(Test-Path $newtonSoftDllPath)) {

ContainerHandling/Enter-NavContainer.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Enter-BcContainer {
2323
Enter-PSSession -Session $session
2424
if ($session.ComputerType -eq 'Container') {
2525
Invoke-Command -Session $session -ScriptBlock {
26-
function prompt {"[$env:COMPUTERNAME]: PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "}
26+
function prompt {"[$env:COMPUTERNAME]: PS5 $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "}
2727
}
2828
}
2929
} else {

ContainerHandling/New-NavContainer.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ try {
497497
Write-Host "BcContainerHelper is running inside a Container"
498498
}
499499
Write-Host "UsePsSession is $($bcContainerHelperConfig.UsePsSession)"
500+
Write-Host "UsePwshForBc24 is $($bcContainerHelperConfig.UsePwshForBc24)"
500501
Write-Host "Host is $($os.Caption) - $hostOsVersion"
501502

502503
$dockerProcess = (Get-Process "dockerd" -ErrorAction Ignore)
@@ -1724,7 +1725,7 @@ Get-NavServerUser -serverInstance $ServerInstance -tenant default |? LicenseType
17241725

17251726
if ($version.Major -ge 24) {
17261727
('
1727-
if (!(Get-Command "invoke-sqlcmd" -ErrorAction SilentlyContinue)) { Install-package SqlServer -Force -RequiredVersion 21.1.18256 | Out-Null }
1728+
if (!(Get-Command "invoke-sqlcmd" -ErrorAction SilentlyContinue)) { try { Write-Host "Installing SqlServer module"; Install-package SqlServer -Force -RequiredVersion 21.1.18256 | Out-Null } catch { Write-Host "Failed to install SqlServer module" } }
17281729
') | Add-Content -Path "$myfolder\HelperFunctions.ps1"
17291730
}
17301731

ContainerHandling/Open-NavContainer.ps1

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Open-BcContainer {
2020

2121
Process {
2222
$shell = 'powershell'
23+
$ps = 'PS5'
2324
try {
2425
$inspect = docker inspect $containerName | ConvertFrom-Json
2526
$version = [Version]$inspect.Config.Labels.version
@@ -29,11 +30,13 @@ function Open-BcContainer {
2930
}
3031
if ($version.Major -ge 24 -and $usePwsh) {
3132
$shell = 'pwsh'
33+
$ps = 'PS7'
3234
}
33-
$psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] PS '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; Write-Host 'Welcome to the $vs Container PowerShell prompt'; Write-Host 'Microsoft Windows Version $($inspect.Config.Labels.osversion)'; Write-Host ""Windows PowerShell Version `$(`$PSVersionTable.psversion.ToString())""; Write-Host; . 'c:\run\prompt.ps1' -silent"""
35+
throw 'x'
36+
$psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] $ps '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; Write-Host 'Welcome to the $vs Container PowerShell prompt'; Write-Host 'Microsoft Windows Version $($inspect.Config.Labels.osversion)'; Write-Host ""Windows PowerShell Version `$(`$PSVersionTable.psversion.ToString())""; Write-Host; . 'c:\run\prompt.ps1' -silent"""
3437
}
3538
catch {
36-
$psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] PS '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; . 'c:\run\prompt.ps1'"""
39+
$psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] $ps '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; Write-Host 'Welcome to the ContainerHelper PowerShell prompt'; Write-Host ""Windows PowerShell Version `$(`$PSVersionTable.psversion.ToString())""; Write-Host; . 'c:\run\prompt.ps1' -silent"""
3740
}
3841
Start-Process "cmd.exe" @("/C";"docker exec -it $containerName $shell -noexit -command $psPrompt")
3942
}

CreateScript.ps1

+25-66
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,12 @@ if (($pswindow.BufferSize) -and ($pswindow.WindowSize) -and ($pswindow.WindowSiz
320320
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
321321
$isAdministrator = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
322322
$randompw = Get-RandomPassword
323-
$bestContainerOsVersion = [System.Version]((Get-BestGenericImageName).Split(':')[1]).Split('-')[0]
323+
$os = (Get-CimInstance Win32_OperatingSystem)
324+
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
325+
throw "Unknown Host Operating System"
326+
}
327+
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
328+
$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")
324329
$ErrorActionPreference = "STOP"
325330

326331
$script:wizardStep = 0
@@ -1184,51 +1189,8 @@ $Step.SSL {
11841189

11851190
$Step.Isolation {
11861191
if ($hosting -eq "Local") {
1187-
1188-
$os = (Get-CimInstance Win32_OperatingSystem)
1189-
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
1190-
throw "Unknown Host Operating System"
1191-
}
1192-
1193-
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
1194-
$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")
1195-
1196-
try {
1197-
$bestContainerOS = "The image, which matches your host OS best is $($bestContainerOsVersion.ToString())"
1198-
if ($hostOsVersion.Build -ge 20348 -and $bestContainerOsVersion.Build -ge 20348) {
1199-
if ($bestContainerOsVersion -le $hostOsVersion) {
1200-
$defaultIsolation = "process"
1201-
}
1202-
else {
1203-
$defaultIsolation = "Hyper-V"
1204-
}
1205-
}
1206-
elseif ($hostOsVersion.Major -eq $bestContainerOsVersion.Major -and $hostOsVersion.Minor -eq $bestContainerOsVersion.Minor -and $hostOsVersion.Build -eq $bestContainerOsVersion.Build) {
1207-
$defaultIsolation = "Process"
1208-
}
1209-
else {
1210-
$defaultIsolation = "Hyper-V"
1211-
}
1212-
}
1213-
catch {
1214-
$bestContainerOsVersion = [System.Version]"0.0.0.0"
1215-
$bestContainerOS = "Unable to determine the image which matches your OS best"
1216-
$defaultIsolation = "Hyper-V"
1217-
}
1218-
1219-
$description = "Containers can run in process isolation or hyperv isolation, see more here: https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/hyperv-container`nIf not specified, the ContainerHelper will try to detect which isolation mode will work for your OS.`nIf an image with a matching OS is found, Process isolation will be favoured, else Hyper-V will be selected.`n`nYour host OS is Windows $($hostOSVersion.ToString())`n$bestContainerOS`n"
1220-
1221-
if ($isAdministrator) {
1222-
$hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online
1223-
if ($hyperv) {
1224-
$description += "Hyper-V is enabled"
1225-
}
1226-
else {
1227-
$description += "Hyper-V is NOT enabled (you will not be able to use Hyper-V isolation on this host)"
1228-
$defaultIsolation = "Process"
1229-
}
1230-
}
1231-
$options = [ordered]@{"default" = "Allow the ContainerHelper to decide which isolation mode to use (on this host, this will be $defaultIsolation isolation)"; "process" = "Force Process isolation"; "hyperv" = "Force Hyper-V isolation" }
1192+
$description = "Containers can run in process isolation or hyperv isolation, see more here: https://docs.microsoft.com/en-us/virtualization/windowscontainers/manage-containers/hyperv-container`nIf not specified, the ContainerHelper will try to detect which isolation mode will work for your OS.`nIf your host OS is updated and a matching container OS is found, Process isolation will be favoured, else Hyper-V will be selected."
1193+
$options = [ordered]@{"default" = "Allow the ContainerHelper to decide which isolation mode to use"; "process" = "Force Process isolation"; "hyperv" = "Force Hyper-V isolation" }
12321194

12331195
$isolation = Select-Value `
12341196
-title @'
@@ -1270,27 +1232,24 @@ $Step.Memory {
12701232
if ($newBaseApp) {
12711233
$description += "- $($newBaseApp)G for base app development`n"
12721234
}
1273-
if ($isolation -eq "process" -or ($isolation -eq "default" -and $defaultIsolation -eq "Process")) {
1274-
$description += "`nWhen running Process isolation, the container will only use the actual amount of memory used by the processes running in the container from the host.`nMemory no longer needed by the processes in the container are given back to the host`nYou can set a limit to the amount of memory, the container is allowed to use."
1275-
$defaultDescription = "blank means no limit"
1276-
}
1277-
else {
1278-
$description += "`nWhen running Hyper-V isolation, the container will pre-allocate the full amount of memory given to the container.`n"
1279-
if ($hostOsVersion.Build -ge 17763) {
1280-
$description += "Windows Server 2019 / Windows 10 1809 and later Windows versions are doing this by reserving the memory in the paging file and only using physical memory when needed.`nMemory no longer needed will be freed from physical memory again.`n"
1281-
try {
1282-
$CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2'
1283-
if ($CompSysResults.AutomaticManagedPagefile) {
1284-
$description += "Your paging file settings indicate that your paging file is automatically managed, you could consider changing this if you get problems with the size of the paging file.`n"
1285-
}
1235+
$description += "`n`nWhen running Process isolation, the container will only use the actual amount of memory used by the processes running in the container from the host. Memory no longer needed by the processes in the container are given back to the host. You can set a limit to the amount of memory, the container is allowed to use. "
1236+
$description += "(blank means no limit)"
1237+
1238+
$description += "`n`nWhen running Hyper-V isolation, the container will pre-allocate the full amount of memory given to the container. "
1239+
if ($hostOsVersion.Build -ge 17763) {
1240+
$description += "Windows Server 2019 / Windows 10 1809 and later Windows versions are doing this by reserving the memory in the paging file and only using physical memory when needed. Memory no longer needed will be freed from physical memory again. "
1241+
try {
1242+
$CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2'
1243+
if ($CompSysResults.AutomaticManagedPagefile) {
1244+
$description += "Your paging file settings indicate that your paging file is automatically managed, you could consider changing this if you get problems with the size of the paging file. "
12861245
}
1287-
catch {}
12881246
}
1289-
else {
1290-
$description += "Windows Server 2016 and Windows 10 versions before 1809 is doing this by allocating the memory from the main memory pool.`n"
1291-
}
1292-
$defaultDescription = "blank will use ContainerHelper default which is 4G"
1247+
catch {}
1248+
}
1249+
else {
1250+
$description += "Windows Server 2016 and Windows 10 versions before 1809 is doing this by allocating the memory from the main memory pool. "
12931251
}
1252+
$description += "(blank will use ContainerHelper default which is 4G)"
12941253

12951254
$memoryLimit = Enter-Value `
12961255
-title @'
@@ -1304,7 +1263,7 @@ $Step.Memory {
13041263
|___/
13051264
'@ `
13061265
-description $description `
1307-
-question "Specify the amount of memory the container is allowed to use? ($defaultDescription)" `
1266+
-question "Specify the amount of memory the container is allowed to use?" `
13081267
-default 'blank' `
13091268
-previousStep
13101269
if ($script:wizardStep -eq $script:thisStep+1) {
@@ -1315,7 +1274,7 @@ $Step.Memory {
13151274
$memoryLimit = ""
13161275
}
13171276
else {
1318-
$memoryLimit = "$($memoryLimit.Trim().ToLowerInvariant().TrimEnd('gb').TrimEnd('g'))G"
1277+
$memoryLimit = "$($memoryLimit.ToLowerInvariant().Trim(' gb'))G"
13191278
}
13201279
}
13211280
}

HelperFunctions.ps1

+4-11
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ function CopyAppFilesToFolder {
552552
New-Item -Path $folder -ItemType Directory | Out-Null
553553
}
554554
$appFiles | Where-Object { $_ } | ForEach-Object {
555-
$appFile = $_
555+
$appFile = "$_"
556556
if ($appFile -like "http://*" -or $appFile -like "https://*") {
557557
$appUrl = $appFile
558558
$appFileFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
@@ -564,13 +564,8 @@ function CopyAppFilesToFolder {
564564
}
565565
}
566566
elseif (Test-Path $appFile -PathType Container) {
567-
get-childitem $appFile -Filter '*.app' -Recurse | ForEach-Object {
568-
$destFile = Join-Path $folder $_.Name
569-
if (Test-Path $destFile) {
570-
Write-Host -ForegroundColor Yellow "::WARNING::$([System.IO.Path]::GetFileName($destFile)) already exists, it looks like you have multiple app files with the same name. App filenames must be unique."
571-
}
572-
Copy-Item -Path $_.FullName -Destination $destFile -Force
573-
$destFile
567+
Get-ChildItem $appFile -Recurse | ForEach-Object {
568+
CopyAppFilesToFolder -appFile $_.FullName -folder $folder
574569
}
575570
}
576571
elseif (Test-Path $appFile -PathType Leaf) {
@@ -587,9 +582,7 @@ function CopyAppFilesToFolder {
587582
$copied = $true
588583
}
589584
Expand-Archive $appfile -DestinationPath $tmpFolder -Force
590-
Get-ChildItem -Path $tmpFolder -Recurse | Where-Object { $_.Name -like "*.app" -or $_.Name -like "*.zip" } | ForEach-Object {
591-
CopyAppFilesToFolder -appFile $_.FullName -folder $folder
592-
}
585+
CopyAppFilesToFolder -appFiles $tmpFolder -folder $folder
593586
}
594587
finally {
595588
Remove-Item -Path $tmpFolder -Recurse -Force

ReleaseNotes.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
6.0.12
2+
Issue 3432 New-BcContainerWizard stopped working after generic images with ltsc2016, ltsc2019 and ltsc2022 was introduced
3+
Make parameters in Copy-AppFilesToFolder mandatory
4+
Support .zip files in folders in Copy-AppFilesToFolder
5+
Issue 3431 Run-TestsInBcContainer, Get-TestsFromBcContainer and Run-ConnectionTest doesn't work if container is using SSL
6+
Issue 3427 New-BCContainer in version 6.0.11 failed to run completely
27

38
6.0.11
49
Issue 3420 New-BcImage uses hyperv even if it is disabled

0 commit comments

Comments
 (0)