Skip to content

Commit

Permalink
Fix issue in CopyApps (#3436)
Browse files Browse the repository at this point in the history
Fixes #3431
Fixes #3432
Fixes #3427
Fixes issues found by troubleshooting
microsoft/AL-Go#969

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Mar 26, 2024
1 parent f578432 commit b0fc84f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 85 deletions.
3 changes: 2 additions & 1 deletion AppHandling/Copy-AppFilesToFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#>
function Copy-AppFilesToFolder {
Param(
[Parameter(Mandatory=$true)]
$appFiles,
[Parameter(Mandatory=$true)]
[string] $folder
)

CopyAppFilesToFolder -appFiles $appFiles -folder $folder
}
Export-ModuleMember -Function Copy-AppFilesToFolder
2 changes: 1 addition & 1 deletion AppHandling/Get-TestsFromNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ try {
}
} -argumentList "01:00:00"

$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)
$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)

$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
if (!(Test-Path $newtonSoftDllPath)) {
Expand Down
2 changes: 1 addition & 1 deletion AppHandling/Run-ConnectionTestToNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ try {
}
else {

$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)
$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)

$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
if (!(Test-Path $newtonSoftDllPath)) {
Expand Down
2 changes: 1 addition & 1 deletion AppHandling/Run-TestsInNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ try {
}
}

$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)
$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)

$newtonSoftDllPath = "C:\Program Files\Microsoft Dynamics NAV\*\Service\Management\NewtonSoft.json.dll"
if (!(Test-Path $newtonSoftDllPath)) {
Expand Down
2 changes: 1 addition & 1 deletion ContainerHandling/Enter-NavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Enter-BcContainer {
Enter-PSSession -Session $session
if ($session.ComputerType -eq 'Container') {
Invoke-Command -Session $session -ScriptBlock {
function prompt {"[$env:COMPUTERNAME]: PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "}
function prompt {"[$env:COMPUTERNAME]: PS5 $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "}
}
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion ContainerHandling/New-NavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ try {
Write-Host "BcContainerHelper is running inside a Container"
}
Write-Host "UsePsSession is $($bcContainerHelperConfig.UsePsSession)"
Write-Host "UsePwshForBc24 is $($bcContainerHelperConfig.UsePwshForBc24)"
Write-Host "Host is $($os.Caption) - $hostOsVersion"

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

if ($version.Major -ge 24) {
('
if (!(Get-Command "invoke-sqlcmd" -ErrorAction SilentlyContinue)) { Install-package SqlServer -Force -RequiredVersion 21.1.18256 | Out-Null }
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" } }
') | Add-Content -Path "$myfolder\HelperFunctions.ps1"
}

Expand Down
7 changes: 5 additions & 2 deletions ContainerHandling/Open-NavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function Open-BcContainer {

Process {
$shell = 'powershell'
$ps = 'PS5'
try {
$inspect = docker inspect $containerName | ConvertFrom-Json
$version = [Version]$inspect.Config.Labels.version
Expand All @@ -29,11 +30,13 @@ function Open-BcContainer {
}
if ($version.Major -ge 24 -and $usePwsh) {
$shell = 'pwsh'
$ps = 'PS7'
}
$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"""
throw 'x'
$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"""
}
catch {
$psPrompt = """function prompt {'[$($containerName.ToUpperInvariant())] PS '+`$executionContext.SessionState.Path.CurrentLocation+('>'*(`$nestedPromptLevel+1))+' '}; . 'c:\run\prompt.ps1'"""
$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"""
}
Start-Process "cmd.exe" @("/C";"docker exec -it $containerName $shell -noexit -command $psPrompt")
}
Expand Down
91 changes: 25 additions & 66 deletions CreateScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,12 @@ if (($pswindow.BufferSize) -and ($pswindow.WindowSize) -and ($pswindow.WindowSiz
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdministrator = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
$randompw = Get-RandomPassword
$bestContainerOsVersion = [System.Version]((Get-BestGenericImageName).Split(':')[1]).Split('-')[0]
$os = (Get-CimInstance Win32_OperatingSystem)
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
throw "Unknown Host Operating System"
}
$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")
$ErrorActionPreference = "STOP"

$script:wizardStep = 0
Expand Down Expand Up @@ -1184,51 +1189,8 @@ $Step.SSL {

$Step.Isolation {
if ($hosting -eq "Local") {

$os = (Get-CimInstance Win32_OperatingSystem)
if ($os.OSType -ne 18 -or !$os.Version.StartsWith("10.0.")) {
throw "Unknown Host Operating System"
}

$UBR = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -Name UBR).UBR
$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")

try {
$bestContainerOS = "The image, which matches your host OS best is $($bestContainerOsVersion.ToString())"
if ($hostOsVersion.Build -ge 20348 -and $bestContainerOsVersion.Build -ge 20348) {
if ($bestContainerOsVersion -le $hostOsVersion) {
$defaultIsolation = "process"
}
else {
$defaultIsolation = "Hyper-V"
}
}
elseif ($hostOsVersion.Major -eq $bestContainerOsVersion.Major -and $hostOsVersion.Minor -eq $bestContainerOsVersion.Minor -and $hostOsVersion.Build -eq $bestContainerOsVersion.Build) {
$defaultIsolation = "Process"
}
else {
$defaultIsolation = "Hyper-V"
}
}
catch {
$bestContainerOsVersion = [System.Version]"0.0.0.0"
$bestContainerOS = "Unable to determine the image which matches your OS best"
$defaultIsolation = "Hyper-V"
}

$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"

if ($isAdministrator) {
$hyperv = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online
if ($hyperv) {
$description += "Hyper-V is enabled"
}
else {
$description += "Hyper-V is NOT enabled (you will not be able to use Hyper-V isolation on this host)"
$defaultIsolation = "Process"
}
}
$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" }
$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."
$options = [ordered]@{"default" = "Allow the ContainerHelper to decide which isolation mode to use"; "process" = "Force Process isolation"; "hyperv" = "Force Hyper-V isolation" }

$isolation = Select-Value `
-title @'
Expand Down Expand Up @@ -1270,27 +1232,24 @@ $Step.Memory {
if ($newBaseApp) {
$description += "- $($newBaseApp)G for base app development`n"
}
if ($isolation -eq "process" -or ($isolation -eq "default" -and $defaultIsolation -eq "Process")) {
$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."
$defaultDescription = "blank means no limit"
}
else {
$description += "`nWhen running Hyper-V isolation, the container will pre-allocate the full amount of memory given to the container.`n"
if ($hostOsVersion.Build -ge 17763) {
$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"
try {
$CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2'
if ($CompSysResults.AutomaticManagedPagefile) {
$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"
}
$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. "
$description += "(blank means no limit)"

$description += "`n`nWhen running Hyper-V isolation, the container will pre-allocate the full amount of memory given to the container. "
if ($hostOsVersion.Build -ge 17763) {
$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. "
try {
$CompSysResults = Get-CimInstance win32_computersystem -ComputerName $computer -Namespace 'root\cimv2'
if ($CompSysResults.AutomaticManagedPagefile) {
$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. "
}
catch {}
}
else {
$description += "Windows Server 2016 and Windows 10 versions before 1809 is doing this by allocating the memory from the main memory pool.`n"
}
$defaultDescription = "blank will use ContainerHelper default which is 4G"
catch {}
}
else {
$description += "Windows Server 2016 and Windows 10 versions before 1809 is doing this by allocating the memory from the main memory pool. "
}
$description += "(blank will use ContainerHelper default which is 4G)"

$memoryLimit = Enter-Value `
-title @'
Expand All @@ -1304,7 +1263,7 @@ $Step.Memory {
|___/
'@ `
-description $description `
-question "Specify the amount of memory the container is allowed to use? ($defaultDescription)" `
-question "Specify the amount of memory the container is allowed to use?" `
-default 'blank' `
-previousStep
if ($script:wizardStep -eq $script:thisStep+1) {
Expand All @@ -1315,7 +1274,7 @@ $Step.Memory {
$memoryLimit = ""
}
else {
$memoryLimit = "$($memoryLimit.Trim().ToLowerInvariant().TrimEnd('gb').TrimEnd('g'))G"
$memoryLimit = "$($memoryLimit.ToLowerInvariant().Trim(' gb'))G"
}
}
}
Expand Down
15 changes: 4 additions & 11 deletions HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ function CopyAppFilesToFolder {
New-Item -Path $folder -ItemType Directory | Out-Null
}
$appFiles | Where-Object { $_ } | ForEach-Object {
$appFile = $_
$appFile = "$_"
if ($appFile -like "http://*" -or $appFile -like "https://*") {
$appUrl = $appFile
$appFileFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
Expand All @@ -564,13 +564,8 @@ function CopyAppFilesToFolder {
}
}
elseif (Test-Path $appFile -PathType Container) {
get-childitem $appFile -Filter '*.app' -Recurse | ForEach-Object {
$destFile = Join-Path $folder $_.Name
if (Test-Path $destFile) {
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."
}
Copy-Item -Path $_.FullName -Destination $destFile -Force
$destFile
Get-ChildItem $appFile -Recurse | ForEach-Object {
CopyAppFilesToFolder -appFile $_.FullName -folder $folder
}
}
elseif (Test-Path $appFile -PathType Leaf) {
Expand All @@ -587,9 +582,7 @@ function CopyAppFilesToFolder {
$copied = $true
}
Expand-Archive $appfile -DestinationPath $tmpFolder -Force
Get-ChildItem -Path $tmpFolder -Recurse | Where-Object { $_.Name -like "*.app" -or $_.Name -like "*.zip" } | ForEach-Object {
CopyAppFilesToFolder -appFile $_.FullName -folder $folder
}
CopyAppFilesToFolder -appFiles $tmpFolder -folder $folder
}
finally {
Remove-Item -Path $tmpFolder -Recurse -Force
Expand Down
5 changes: 5 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
6.0.12
Issue 3432 New-BcContainerWizard stopped working after generic images with ltsc2016, ltsc2019 and ltsc2022 was introduced
Make parameters in Copy-AppFilesToFolder mandatory
Support .zip files in folders in Copy-AppFilesToFolder
Issue 3431 Run-TestsInBcContainer, Get-TestsFromBcContainer and Run-ConnectionTest doesn't work if container is using SSL
Issue 3427 New-BCContainer in version 6.0.11 failed to run completely

6.0.11
Issue 3420 New-BcImage uses hyperv even if it is disabled
Expand Down

0 comments on commit b0fc84f

Please sign in to comment.