Open kine opened 2 months ago
Workaround for now is to run my\additionalsetup.ps1 e.g. through custom my\servicesettings.ps1 because this is runned from navinstall.ps1 which is running even for filesOnly container. But there is no way how to do that when running Run-ALValidation.
Hmm, it seems more complicated. When I resolved the problem with connection, I have problem with another code running in the get-bccontainersession failing on error:
Cannot find path 'C:\Program Files\Microsoft Dynamics NAV' because it does not exist.
+ CategoryInfo : ObjectNotFound: (C:\Program Files\Microsoft Dynamics NAV:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
Because it is running script "prompt.ps1"
navinstall runs with $filesOnly
set to true - I will just copy the files around and not actually perform the install - but it should copy the files to C:\Program Files\Microsoft Dynamics NAV - so this folder should exist.
Ok, I did new research and there are the differences when running from outside container and from within container
In both cases, this script was used to try to create the container:
$password = 'randompassword'
Write-Host "admin/$password"
$credential= (New-Object pscredential 'admin', (ConvertTo-SecureString -String $password -AsPlainText -Force))
$Parameters = @{
"accept_eula" = $true
"accept_insiderEula" = $true
"containerName" = 'test'
"artifactUrl" = 'https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.2.20227.21047/cz'
"useGenericImage" = 'mcr.microsoft.com/businesscentral:ltsc2022-dev'
"Credential" = $credential
"auth" = 'UserPassword'
"updateHosts" = $true
"vsixFile" = 'https://ms-dynamics-smb.gallerycdn.vsassets.io/extensions/ms-dynamics-smb/al/13.0.1027618/1716970921654/Microsoft.VisualStudio.Services.VSIXPackage'
"EnableTaskScheduler" = $true
"AssignPremiumPlan" = $true
"MemoryLimit" = '16GB'
"FilesOnly" = $true
}
New-BcContainer @parameters
The container used to run the script from within container was created by this script:
#creating the container
docker run -t -d -h 'testcontainer' --name 'testcontainer' -v "\\.\pipe\docker_engine:\\.\pipe\docker_engine" -v "c:\bcartifacts.cache:c:\bcartifacts.cache" -v "c:\programdata\BcContainerHelper:c:\programdata\BcContainerHelper" mcr.microsoft.com/dotnet/runtime:8.0.5-windowsservercore-ltsc2022
#Preparing the container
#Run in the container after connecting through enter-pssession -ContainerId xxxxx -RunAsAdministrator:
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
choco feature enable -n allowGlobalConfirmation
choco install docker-cli --no-progress
choco install 7zip --no-progress; `
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force -WarningAction Ignore
Install-Module powershellget -force
Install-Module bccontainerhelper -force
Output of the script running from the host (and finishing ok):
admin/randompassword
BcContainerHelper version 6.0.19
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.20348.2400
BcContainerHelper is version 6.0.19
BcContainerHelper is running as administrator
HyperV is Enabled
Host is Microsoft Windows Server 2022 Standard - 10.0.20348.2461
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 26.1.3
Docker Server Version is 26.1.3
Removing Desktop shortcuts
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2022-dev
Creating Container test
Style: sandbox
Multitenant: Yes
Version: 24.2.20227.21047
Platform: 24.0.20984.0
Generic Tag: 1.0.2.36-dev
Container OS Version: 10.0.20348.2527 (ltsc2022)
Host OS Version: 10.0.20348.2461 (ltsc2022)
WARNING: Container and host OS build is 20348 or above, defaulting to process isolation. If you encounter issues, you could try to install HyperV.
Using process isolation
Using locale cs-CZ
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Downloading C:\ProgramData\BcContainerHelper\Extensions\test\Microsoft.VisualStudio.Services.VSIXPackage.vsix
Additional Parameters:
--expose 5986
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\test\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- HelperFunctions.ps1
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container test from image mcr.microsoft.com/businesscentral:ltsc2022-dev
6494874dda4b370ac072c4b4345d88168fc19ab19bc980970fef0227efffaaa5
Waiting for container test to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.2.20227.21047/cz
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=True, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.2.20227.21047\cz, platformArtifactPath=c:\dl\sandbox\24.2.20227.21047\p
latform, databasePath=c:\dl\sandbox\24.2.20227.21047\cz\BusinessCentral-CZ.bak, licenseFilePath=c:\dl\sandbox\24.2.20227.21047\cz\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Copying Service Tier Files
c:\dl\sandbox\24.2.20227.21047\platform\ServiceTier\Program Files
c:\dl\sandbox\24.2.20227.21047\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.2.20227.21047\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.2.20227.21047\platform
c:\dl\sandbox\24.2.20227.21047\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.2.20227.21047\cz\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.2.20227.21047\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.2.20227.21047\cz\Extensions
Copying Applications
C:\dl\sandbox\24.2.20227.21047\platform\Applications
Copying Applications.CZ
C:\dl\sandbox\24.2.20227.21047\cz\Applications.CZ
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 8 seconds
Installation complete
Ready for connections!
Reading CustomSettings.config from test
Cleanup old dotnet core assemblies
Output of the script running from within container:
admin/randompassword
BcContainerHelper version 6.0.19
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.20348.2400
BcContainerHelper is version 6.0.19
BcContainerHelper is running as administrator
HyperV is DisabledWithPayloadRemoved
BcContainerHelper is running inside a Container
Host is Microsoft Windows Server 2022 Datacenter - 10.0.20348.2461
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Dockerd process not found. Docker might not be started, not installed or not running Windows Containers. If Docker Desktop is already installed, open the system tray, right-click on the Docker icon, and select 'Switch to Windows containers...'
Docker Client Version is 27.0.3
Docker Server Version is 26.1.3
Removing Desktop shortcuts
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2022-dev
Creating Container test
Style: sandbox
Multitenant: Yes
Version: 24.2.20227.21047
Platform: 24.0.20984.0
Generic Tag: 1.0.2.36-dev
Container OS Version: 10.0.20348.2527 (ltsc2022)
Host OS Version: 10.0.20348.2461 (ltsc2022)
WARNING: Container and host OS build is 20348 or above, defaulting to process isolation. If you encounter issues, you could try to install HyperV.
Using process isolation
Using locale cs-CZ
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Downloading C:\ProgramData\BcContainerHelper\Extensions\test\Microsoft.VisualStudio.Services.VSIXPackage.vsix
Additional Parameters:
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\test\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- HelperFunctions.ps1
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container test from image mcr.microsoft.com/businesscentral:ltsc2022-dev
f9ab5ba41fa3796d928cd10e0f4b3beec584912b6dce15e793e7cf606ee4b6f9
Waiting for container test to be ready
Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.2.20227.21047/cz
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=True, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.2.20227.21047\cz, platformArtifactPath=c:\dl\sandbox\24.2.20227.21047\p
latform, databasePath=c:\dl\sandbox\24.2.20227.21047\cz\BusinessCentral-CZ.bak, licenseFilePath=c:\dl\sandbox\24.2.20227.21047\cz\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Copying Service Tier Files
c:\dl\sandbox\24.2.20227.21047\platform\ServiceTier\Program Files
c:\dl\sandbox\24.2.20227.21047\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.2.20227.21047\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.2.20227.21047\platform
c:\dl\sandbox\24.2.20227.21047\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.2.20227.21047\cz\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.2.20227.21047\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.2.20227.21047\cz\Extensions
Copying Applications
C:\dl\sandbox\24.2.20227.21047\platform\Applications
Copying Applications.CZ
C:\dl\sandbox\24.2.20227.21047\cz\Applications.CZ
Copying dependencies
Importing PowerShell Modules
Skipping restore of Cronus database
Modifying Business Central Service Tier Config File for Docker
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Installation took 9 seconds
Installation complete
Ready for connections!
Error trying to establish session, retrying in 5 seconds
New-BcContainer Telemetry Correlation Id: c890ed9e-b718-4c18-b76d-284b9ced6c75
Connecting to remote server test failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from
this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed
Based on the analysis of the output, the exact point where the script fails when running from within container, is this line:
I am not sure, if there is problem that the container is not set correctly to be able to connect to it from within another container or it is set differently because it was created from within container, because e.g. content of script my\AdditionalSetup.ps1 are different for both containers. But I think this script was not triggered at all during the startup (I do not see the output of it in the output of the script).
Ok, after few days of research, I have found the original source of the problem. This is the result:
Problems:
Code to create the container inside run-alvalidation:
$NewBcContainer = { Param([Hashtable]$parameters) New-BcContainer @parameters; Invoke-ScriptInBcContainer $parameters.ContainerName -scriptblock { $progressPreference = 'SilentlyContinue' } }
Workaround: Because there is no simple way how to pass new parameter directly to new-bccontainer command inside the run-alvalidation, only way without change in the code is to use the parameter -NewBcContainer to override the process of creating the container. We can use the MyScripts to pass this modified script block to add necessary workaround code:
{
Param([Hashtable]$parameters)
$parameters += @{
"MyScripts" = @(@{'start.ps1'='. c:\run\HelperFunctions.ps1;. c:\run\SetupVariables.ps1;. c:\run\my\additionalsetup.ps1;remove-item "c:\run\my\start.ps1" -force;. (Join-Path $runPath $MyInvocation.MyCommand.Name)'})
}
New-BcContainer @parameters
Invoke-ScriptInBcContainer $parameters.ContainerName -scriptblock { $progressPreference = 'SilentlyContinue'}
}
Solution: It is hard to say what is wrong in the module, if it is the fact, that additionalsetup.ps1 is called from navinstall.ps1 and not from install.ps1, or the fact, that the winrm is set through the my\additonalsetup.ps1 script at all. This is why I am unable to create some PR to fix this, because I do not know what to fix. It is rather question of rethinking how the process is working at all, because this bug have impact to all situations, when someone is trying to create FileOnly container from within container.
We switched to using containerized Azure DevOps agents and since that, running Run-ALValidation fails on New-BCContainer step with error "Error trying to establish session, retrying in 5 seconds".
After the research, I have found, that there is one step missing when filesOnly switch is combined with running the script inside container, because it will never run configuration for winrm because this.
Bare script to run inside container which lead to the problem:
Output of the script:
Then, when you try to connect/run script on the container (or anything what is getting the container session):
will lead to this error:
I was able to track the source of the problem to this line: https://github.com/microsoft/navcontainerhelper/blob/b2410696c2c9ce68b63f3ef1a65c0c09d0c58ed1/ContainerHandling/New-NavContainer.ps1#L1591
Because we are inside container, when this runs, this code will be executed and will fill the code into my\additionalsetup.ps1 file. But it will be not executed because we have filesOnly switch, which will prevent running navstart.ps1 which runs inside the my\additionalsetup.ps1. This lead to error because right after the new-bccontainer there is invoke-scriptinbccontainer (which runs get-bccontianersession inside). See https://github.com/microsoft/navcontainerhelper/blob/b2410696c2c9ce68b63f3ef1a65c0c09d0c58ed1/AppHandling/Run-AlValidation.ps1#L286
I can do workaround but I do not know how to fix the code, because I do not know the context why the code is written like that.
I am attaching even full output of the original run of the Run-ALValidation from our pipeline: