Fixes #3431
Fixes #3432
Fixes #3427
Fixes issues found by troubleshooting
https://github.com/microsoft/AL-Go/issues/969

---------

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
This commit is contained in:
Freddy Kristiansen 2024-03-26 08:28:15 +01:00 коммит произвёл GitHub
Родитель f5784320e5
Коммит b0fc84f650
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
10 изменённых файлов: 47 добавлений и 85 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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)) {

Просмотреть файл

@ -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)) {

Просмотреть файл

@ -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)) {

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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)
@ -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"
}

Просмотреть файл

@ -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
@ -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")
}

Просмотреть файл

@ -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
@ -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 @'
@ -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"
$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 += "`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"
}
}
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"
$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 @'
@ -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) {
@ -1315,7 +1274,7 @@ $Step.Memory {
$memoryLimit = ""
}
else {
$memoryLimit = "$($memoryLimit.Trim().ToLowerInvariant().TrimEnd('gb').TrimEnd('g'))G"
$memoryLimit = "$($memoryLimit.ToLowerInvariant().Trim(' gb'))G"
}
}
}

Просмотреть файл

@ -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())
@ -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) {
@ -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

Просмотреть файл

@ -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