Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Run-ALValidation from another container fails on New-BCContainer with error "Error trying to establish session, retrying in 5 seconds" #3582

Open
kine opened this issue Jun 24, 2024 · 5 comments
Assignees

Comments

@kine
Copy link
Contributor

kine commented Jun 24, 2024

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:

    $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

Output of the script:

admin/randompassword
BcContainerHelper is version 6.0.17
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 Session BCFdkr-agent6
Removing container BCFdkr-agent6
Removing entries from hosts
Removing BCFdkr-agent6 from container hosts file
Removing BCFdkr-agent6-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\BCFdkr-agent6
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2022-dev
Creating Container BCFdkr-agent6
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\BCFdkr-agent6\Microsoft.VisualStudio.Services.VSIXPackage.vsix
Additional Parameters:
--expose 5986
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\BCFdkr-agent6\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- HelperFunctions.ps1
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container BCFdkr-agent6 from image mcr.microsoft.com/businesscentral:ltsc2022-dev
5f3a30569c167eb32d4247662641907b0d5cebbceb6b8b82861c8d069b24f32a
Waiting for container BCFdkr-agent6 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 BCFdkr-agent6
Cleanup old dotnet core assemblies

Then, when you try to connect/run script on the container (or anything what is getting the container session):

Get-BcContainerSession -containerName Test

will lead to this error:

New-PSSession : [Test] 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.
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.17\ContainerHandling\Get-NavContainerSession.ps1:80 char:32
+ ...  $Session = New-PSSession -ConnectionUri "https://$($containerName):5 ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionOpenFailed

I was able to track the source of the problem to this line:

image

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

$NewBcContainer = { Param([Hashtable]$parameters) New-BcContainer @parameters; Invoke-ScriptInBcContainer $parameters.ContainerName -scriptblock { $progressPreference = 'SilentlyContinue' } }

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:

2024-06-19T12:48:46.6913114Z BcContainerHelper version 6.0.19-preview1213
2024-06-19T12:48:47.4310601Z BC.HelperFunctions emits usage statistics telemetry to Microsoft
2024-06-19T12:48:47.6051493Z Running on Windows, PowerShell 5.1.20348.2400
2024-06-19T12:48:52.7075569Z Validate Next Major 
2024-06-19T12:48:52.7088032Z Starting ALValidation for Current
2024-06-19T12:48:54.1668247Z   _____                               _                
2024-06-19T12:48:54.1668666Z  |  __ \                             | |               
2024-06-19T12:48:54.1668912Z  | |__) |_ _ _ __ __ _ _ __ ___   ___| |_ ___ _ __ ___ 
2024-06-19T12:48:54.1669566Z  |  ___/ _` | '__/ _` | '_ ` _ \ / _ \ __/ _ \ '__/ __|
2024-06-19T12:48:54.1669850Z  | |  | (_| | | | (_| | | | | | |  __/ |_  __/ |  \__ \
2024-06-19T12:48:54.1670112Z  |_|   \__,_|_|  \__,_|_| |_| |_|\___|\__\___|_|  |___/
2024-06-19T12:48:54.1670239Z 
2024-06-19T12:48:54.1694867Z Container name                  BCAppsdkr-agent2
2024-06-19T12:48:54.1936288Z Credential                      admin/Wyme9281
2024-06-19T12:48:54.1969651Z MemoryLimit                     8G
2024-06-19T12:48:54.1984579Z validateVersion                 
2024-06-19T12:48:54.2001215Z validateCurrent                 True
2024-06-19T12:48:54.2018655Z validateNextMinor               False
2024-06-19T12:48:54.2035353Z validateNextMajor               False
2024-06-19T12:48:54.2180972Z countries                       cz
2024-06-19T12:48:54.2197775Z validateCountries               cz
2024-06-19T12:48:54.2213834Z affixes                         NVR
2024-06-19T12:48:54.2254200Z supportedCountries              
2024-06-19T12:48:54.2268166Z ObsoleteTagMinAllowedMajorMinor 
2024-06-19T12:48:54.2281695Z vsixFile                        
2024-06-19T12:48:54.2289989Z Install Apps
2024-06-19T12:48:54.2298742Z - None
2024-06-19T12:48:54.2306587Z Previous Apps
2024-06-19T12:48:54.2328247Z - C:\_work\dkr-agent2\6\PreviousApps\NAVERTICA a.s._Navertica CZ Banking_22.4.166986.0.app
2024-06-19T12:48:54.2336377Z Apps
2024-06-19T12:48:54.2355402Z - C:\_work\dkr-agent2\6\BuildPipeline\App\NAVERTICA a.s._Navertica CZ Banking_22.5.171358.0.app
2024-06-19T12:48:54.2468169Z 
2024-06-19T12:48:54.2468893Z   _____       _ _ _                                          _        _                            
2024-06-19T12:48:54.2469261Z  |  __ \     | | (_)                                        (_)      (_)                           
2024-06-19T12:48:54.2469545Z  | |__) |   _| | |_ _ __   __ _    __ _  ___ _ __   ___ _ __ _  ___   _ _ __ ___   __ _  __ _  ___ 
2024-06-19T12:48:54.2470236Z  |  ___/ | | | | | | '_ \ / _` |  / _` |/ _ \ '_ \ / _ \ '__| |/ __| | | '_ ` _ \ / _` |/ _` |/ _ \
2024-06-19T12:48:54.2470875Z  | |   | |_| | | | | | | | (_| | | (_| |  __/ | | |  __/ |  | | (__  | | | | | | | (_| | (_| |  __/
2024-06-19T12:48:54.2472688Z  |_|    \__,_|_|_|_|_| |_|\__, |  \__, |\___|_| |_|\___|_|  |_|\___| |_|_| |_| |_|\__,_|\__, |\___|
2024-06-19T12:48:54.2472986Z                            __/ |   __/ |                                                 __/ |     
2024-06-19T12:48:54.2473221Z                           |___/   |___/                                                 |___/      
2024-06-19T12:48:54.2473361Z 
2024-06-19T12:48:54.2477489Z Pulling mcr.microsoft.com/businesscentral:ltsc2022-dev
2024-06-19T12:48:54.7710156Z 
2024-06-19T12:48:54.7711267Z Pulling generic image took 1 seconds
2024-06-19T12:48:54.7874550Z   _____       _                      _                         _   _  __           _       
2024-06-19T12:48:54.7874869Z  |  __ \     | |                    (_)                       | | (_)/ _|         | |      
2024-06-19T12:48:54.7875385Z  | |  | | ___| |_ ___ _ __ _ __ ___  _ _ __   ___    __ _ _ __| |_ _| |_ __ _  ___| |_ ___ 
2024-06-19T12:48:54.7876238Z  | |  | |/ _ \ __/ _ \ '__| '_ ` _ \| | '_ \ / _ \  / _` | '__| __| |  _/ _` |/ __| __/ __|
2024-06-19T12:48:54.7876553Z  | |__| |  __/ |_  __/ |  | | | | | | | | | |  __/ | (_| | |  | |_| | || (_| | (__| |_\__ \
2024-06-19T12:48:54.7876865Z  |_____/ \___|\__\___|_|  |_| |_| |_|_|_| |_|\___|  \__,_|_|   \__|_|_| \__,_|\___|\__|___/
2024-06-19T12:48:54.7877147Z                                                                                            
2024-06-19T12:50:21.5522137Z Found https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.2.20227.20970/cz
2024-06-19T12:50:21.6371081Z Using https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.2.20227.20970/cz
2024-06-19T12:50:21.6591636Z 
2024-06-19T12:50:21.6592506Z    _____                _   _                               _        _                 
2024-06-19T12:50:21.6592761Z   / ____|              | | (_)                             | |      (_)                
2024-06-19T12:50:21.6593058Z  | |     _ __ ___  __ _| |_ _ _ __   __ _    ___ ___  _ __ | |_ __ _ _ _ __   ___ _ __ 
2024-06-19T12:50:21.6593687Z  | |    | '__/ _ \/ _` | __| | '_ \ / _` |  / __/ _ \| '_ \| __/ _` | | '_ \ / _ \ '__|
2024-06-19T12:50:21.6593958Z  | |____| | |  __/ (_| | |_| | | | | (_| | | (__ (_) | | | | |_ (_| | | | | |  __/ |   
2024-06-19T12:50:21.6594247Z   \_____|_|  \___|\__,_|\__|_|_| |_|\__, |  \___\___/|_| |_|\__\__,_|_|_| |_|\___|_|   
2024-06-19T12:50:21.6594531Z                                      __/ |                                             
2024-06-19T12:50:21.6594753Z                                     |___/                                              
2024-06-19T12:50:21.6596524Z 
2024-06-19T12:50:21.6648764Z Creating container for country cz
2024-06-19T12:50:21.7832504Z WARNING: Container name should not exceed 15 characters
2024-06-19T12:50:22.0700207Z BcContainerHelper is version 6.0.19-preview1213
2024-06-19T12:50:22.0710614Z BcContainerHelper is running as administrator
2024-06-19T12:50:23.5327896Z HyperV is DisabledWithPayloadRemoved
2024-06-19T12:50:23.5340684Z BcContainerHelper is running inside a Container
2024-06-19T12:50:23.5371758Z Host is Microsoft Windows Server 2022 Datacenter - 10.0.20348.2461
2024-06-19T12:50:23.5406488Z UsePsSession is True
2024-06-19T12:50:23.5442374Z UsePwshForBc24 is True
2024-06-19T12:50:23.5453768Z UseWinRmSession is allow
2024-06-19T12:50:23.5486596Z UseSslForWinRmSession is True
2024-06-19T12:50:23.5643603Z 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...'
2024-06-19T12:50:23.6943572Z Docker Client Version is 26.1.4
2024-06-19T12:50:23.6961217Z Docker Server Version is 26.1.3
2024-06-19T12:50:24.2928896Z Removing Desktop shortcuts
2024-06-19T12:50:24.8439265Z Fetching all docker images
2024-06-19T12:50:25.0041355Z Fetching all docker volumes
2024-06-19T12:50:25.5052778Z Using image mcr.microsoft.com/businesscentral:ltsc2022-dev
2024-06-19T12:50:26.1204979Z Creating Container BCAppsdkr-agent2
2024-06-19T12:50:26.1216772Z Style: sandbox
2024-06-19T12:50:26.1228344Z Multitenant: Yes
2024-06-19T12:50:26.1243407Z Version: 24.2.20227.20970
2024-06-19T12:50:26.1257731Z Platform: 24.0.20957.0
2024-06-19T12:50:26.1275412Z Generic Tag: 1.0.2.36-dev
2024-06-19T12:50:26.1328125Z Container OS Version: 10.0.20348.2527 (ltsc2022)
2024-06-19T12:50:26.1339807Z Host OS Version: 10.0.20348.2461 (ltsc2022)
2024-06-19T12:50:26.1582268Z WARNING: Container and host OS build is 20348 or above, defaulting to process isolation. If you encounter issues, you could try to install HyperV.
2024-06-19T12:50:26.1593558Z Using process isolation
2024-06-19T12:50:26.1624579Z Using locale cs-CZ
2024-06-19T12:50:26.1674683Z Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
2024-06-19T12:50:26.2314177Z Downloading C:\ProgramData\BcContainerHelper\Extensions\BCAppsdkr-agent2\Microsoft.VisualStudio.Services.VSIXPackage.vsix
2024-06-19T12:50:54.2817304Z Additional Parameters:
2024-06-19T12:50:54.2842198Z --env customNavSettings=EnableTaskScheduler=True
2024-06-19T12:50:54.2852669Z Files in C:\ProgramData\BcContainerHelper\Extensions\BCAppsdkr-agent2\my:
2024-06-19T12:50:54.2912477Z - AdditionalOutput.ps1
2024-06-19T12:50:54.2924485Z - AdditionalSetup.ps1
2024-06-19T12:50:54.2939959Z - HelperFunctions.ps1
2024-06-19T12:50:54.2951799Z - MainLoop.ps1
2024-06-19T12:50:54.2966826Z - SetupVariables.ps1
2024-06-19T12:50:54.2980357Z - updatehosts.ps1
2024-06-19T12:50:54.2993783Z Creating container BCAppsdkr-agent2 from image mcr.microsoft.com/businesscentral:ltsc2022-dev
2024-06-19T12:50:54.6004601Z b4d099c486c22216cbb578dda679a2c2418e93dfe9d4d5a77e12462f299e7d76
2024-06-19T12:50:57.4400264Z Waiting for container BCAppsdkr-agent2 to be ready
2024-06-19T12:51:01.0433263Z Adding BCAPPSDKR-AGENT to hosts file
2024-06-19T12:51:01.0434161Z Using artifactUrl https://bcartifacts-exdbf9fwegejdqak.b02.azurefd.net/sandbox/24.2.20227.20970/cz
2024-06-19T12:51:02.1734076Z Using installer from C:\Run\240
2024-06-19T12:51:02.1735669Z Installing Business Central: multitenant=True, installOnly=False, filesOnly=True, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.2.20227.20970\cz, platformArtifactPath=c:\dl\sandbox\24.2.20227.20970\platform, databasePath=c:\dl\sandbox\24.2.20227.20970\cz\BusinessCentral-CZ.bak, licenseFilePath=c:\dl\sandbox\24.2.20227.20970\cz\Cronus.bclicense, rebootContainer=True
2024-06-19T12:51:02.1736406Z Installing from artifacts
2024-06-19T12:51:02.1736640Z Copying Service Tier Files
2024-06-19T12:51:03.3732754Z c:\dl\sandbox\24.2.20227.20970\platform\ServiceTier\Program Files
2024-06-19T12:51:03.3733565Z c:\dl\sandbox\24.2.20227.20970\platform\ServiceTier\System64Folder
2024-06-19T12:51:03.3733883Z Copying Web Client Files
2024-06-19T12:51:05.7211311Z c:\dl\sandbox\24.2.20227.20970\platform\WebClient\Microsoft Dynamics NAV
2024-06-19T12:51:05.7211778Z Copying ModernDev Files
2024-06-19T12:51:05.7212021Z c:\dl\sandbox\24.2.20227.20970\platform
2024-06-19T12:51:05.7212362Z c:\dl\sandbox\24.2.20227.20970\platform\ModernDev\program files\Microsoft Dynamics NAV
2024-06-19T12:51:05.7212656Z Copying additional files
2024-06-19T12:51:05.7212897Z Copying ConfigurationPackages
2024-06-19T12:51:05.7214425Z C:\dl\sandbox\24.2.20227.20970\cz\ConfigurationPackages
2024-06-19T12:51:05.7214782Z Copying Test Assemblies
2024-06-19T12:51:05.7215050Z C:\dl\sandbox\24.2.20227.20970\platform\Test Assemblies
2024-06-19T12:51:05.7215308Z Copying Extensions
2024-06-19T12:51:05.7215573Z C:\dl\sandbox\24.2.20227.20970\cz\Extensions
2024-06-19T12:51:05.7217331Z Copying Applications
2024-06-19T12:51:06.9813203Z C:\dl\sandbox\24.2.20227.20970\platform\Applications
2024-06-19T12:51:06.9814209Z Copying Applications.CZ
2024-06-19T12:51:06.9814473Z C:\dl\sandbox\24.2.20227.20970\cz\Applications.CZ
2024-06-19T12:51:06.9814970Z Copying dependencies
2024-06-19T12:51:06.9815204Z Importing PowerShell Modules
2024-06-19T12:51:06.9815613Z Skipping restore of Cronus database
2024-06-19T12:51:06.9816234Z Modifying Business Central Service Tier Config File for Docker
2024-06-19T12:51:06.9816828Z Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
2024-06-19T12:51:06.9817050Z Installation took 6 seconds
2024-06-19T12:51:06.9817259Z Installation complete
2024-06-19T12:51:06.9820716Z Ready for connections!
2024-06-19T12:51:28.6263510Z Error trying to establish session, retrying in 5 seconds
2024-06-19T12:51:55.2733368Z New-BcContainer Telemetry Correlation Id: 9bf12152-3b03-4321-a2e4-947e9f8c6905
2024-06-19T12:51:55.3544239Z Unexpected error while validating app. Error is: Connecting to remote server BCAppsdkr-agent2 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.
2024-06-19T12:51:55.3568398Z at Get-BcContainerSession<Process>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\ContainerHandling\Get-NavContainerSession.ps1: line 61
2024-06-19T12:51:55.3569607Z at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 50
2024-06-19T12:51:55.3570576Z at Wait-BcContainerReady<Process>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\ContainerHandling\Wait-NavContainerReady.ps1: line 57
2024-06-19T12:51:55.3576181Z at New-BcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\ContainerHandling\New-NavContainer.ps1: line 2039
2024-06-19T12:51:55.3577161Z at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1: line 286
2024-06-19T12:51:55.3577780Z at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1: line 435
2024-06-19T12:51:55.3578570Z at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1: line 413
2024-06-19T12:51:55.3581213Z at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1: line 397
2024-06-19T12:51:55.3581979Z at <ScriptBlock>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1: line 361
2024-06-19T12:51:55.3582602Z at Run-AlValidation, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1: line 359
2024-06-19T12:51:55.3583705Z at <ScriptBlock>, C:\_work\dkr-agent2\_temp\f55b11db-92f3-490d-8184-605552dca4ff.ps1: line 61
2024-06-19T12:51:55.3584132Z at <ScriptBlock>, <No file>: line 1
2024-06-19T12:51:55.3650744Z 
2024-06-19T12:51:55.3651948Z   _____                           _                _____            _        _                 
2024-06-19T12:51:55.3652483Z  |  __ \                         (_)              / ____|          | |      (_)                
2024-06-19T12:51:55.3652825Z  | |__) |___ _ __ ___   _____   ___ _ __   __ _  | |     ___  _ __ | |_ __ _ _ _ __   ___ _ __ 
2024-06-19T12:51:55.3653356Z  |  _  // _ \ '_ ` _ \ / _ \ \ / / | '_ \ / _` | | |    / _ \| '_ \| __/ _` | | '_ \ / _ \ '__|
2024-06-19T12:51:55.3653642Z  | | \ \  __/ | | | | | (_) \ V /| | | | | (_| | | |____ (_) | | | | |_ (_| | | | | |  __/ |   
2024-06-19T12:51:55.3653962Z  |_|  \_\___|_| |_| |_|\___/ \_/ |_|_| |_|\__, |  \_____\___/|_| |_|\__\__,_|_|_| |_|\___|_|   
2024-06-19T12:51:55.3654672Z                                            __/ |                                               
2024-06-19T12:51:55.3657072Z                                           |___/                                                
2024-06-19T12:51:55.3657251Z 
2024-06-19T12:51:56.1143559Z Removing Session BCAppsdkr-agent2
2024-06-19T12:51:56.3041839Z Removing container BCAppsdkr-agent2
2024-06-19T12:51:57.6217187Z Removing entries from hosts
2024-06-19T12:51:57.6499352Z Removing BCAppsdkr-agent2 from container hosts file
2024-06-19T12:51:57.7476599Z Removing BCAppsdkr-agent2-* from container hosts file
2024-06-19T12:51:57.7517001Z Removing Desktop shortcuts
2024-06-19T12:51:57.8456480Z Removing C:\ProgramData\BcContainerHelper\Extensions\BCAppsdkr-agent2
2024-06-19T12:51:58.0078729Z 
2024-06-19T12:51:58.0079685Z Removing container took 3 seconds
2024-06-19T12:51:58.0104911Z 
2024-06-19T12:51:58.0106297Z AL Validation finished in 183 seconds
2024-06-19T12:51:58.0118818Z  __      __   _ _     _       _   _               _____                _ _       
2024-06-19T12:51:58.0119184Z  \ \    / /  | (_)   | |     | | (_)             |  __ \              | | |      
2024-06-19T12:51:58.0119719Z   \ \  / /_ _| |_  __| | __ _| |_ _  ___  _ __   | |__) |___ ___ _   _| | |_ ___ 
2024-06-19T12:51:58.0120445Z    \ \/ / _` | | |/ _` |/ _` | __| |/ _ \| '_ \  |  _  // _ \ __| | | | | __/ __|
2024-06-19T12:51:58.0120717Z     \  / (_| | | | (_| | (_| | |_| | (_) | | | | | | \ \  __\__ \ |_| | | |_\__ \
2024-06-19T12:51:58.0121026Z      \/ \__,_|_|_|\__,_|\__,_|\__|_|\___/|_| |_| |_|  \_\___|___/\__,_|_|\__|___/
2024-06-19T12:51:58.0121167Z 
2024-06-19T12:51:58.0137059Z Unexpected error while validating app. Error is: Connecting to remote server BCAppsdkr-agent2 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.
2024-06-19T12:51:58.0145573Z   _____                          ___      __   _ _     _       _   _               ______    _ _                
2024-06-19T12:51:58.0145936Z  |  __ \                   /\   | \ \    / /  | (_)   | |     | | (_)             |  ____|  (_) |               
2024-06-19T12:51:58.0146453Z  | |__) |   _ _ __ ______ /  \  | |\ \  / /_ _| |_  __| | __ _| |_ _  ___  _ __   | |__ __ _ _| |_   _ _ __ ___ 
2024-06-19T12:51:58.0147118Z  |  _  / | | | '_ \______/ /\ \ | | \ \/ / _` | | |/ _` |/ _` | __| |/ _ \| '_ \  |  __/ _` | | | | | | '__/ _ \
2024-06-19T12:51:58.0147432Z  | | \ \ |_| | | | |    / ____ \| |  \  / (_| | | | (_| | (_| | |_| | (_) | | | | | | | (_| | | | |_| | | |  __/
2024-06-19T12:51:58.0147782Z  |_|  \_\__,_|_| |_|   /_/    \_\_|   \/ \__,_|_|_|\__,_|\__,_|\__|_|\___/|_| |_| |_|  \__,_|_|_|\__,_|_|  \___|
2024-06-19T12:51:58.0147930Z 
2024-06-19T12:51:58.4158256Z Run-ALValidation Telemetry Correlation Id: 9fb81579-5a9f-4858-8066-1a2fc859e44d
2024-06-19T12:51:58.5691164Z Unexpected error while validating app. Error is: Connecting to remote server BCAppsdkr-agent2 failed with the 
2024-06-19T12:51:58.5696065Z following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that 
2024-06-19T12:51:58.5696621Z the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows 
2024-06-19T12:51:58.5697038Z access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote 
2024-06-19T12:51:58.5697417Z computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic.
2024-06-19T12:51:58.5698536Z At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.19\AppHandling\Run-AlValidation.ps1:547 char:5
2024-06-19T12:51:58.5700354Z +     throw ($validationResult -join "`n")
2024-06-19T12:51:58.5700603Z +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-06-19T12:51:58.5700919Z     + CategoryInfo          : OperationStopped: (Unexpected erro...ing Help topic.:String) [], RuntimeException
2024-06-19T12:51:58.5701354Z     + FullyQualifiedErrorId : Unexpected error while validating app. Error is: Connecting to remote server BCAppsdkr-a 
2024-06-19T12:51:58.5701732Z    gent2 failed with the following error message : WinRM cannot complete the operation. Verify that the specified com  
2024-06-19T12:51:58.5702122Z   puter name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM   
2024-06-19T12:51:58.5702487Z   service is enabled and allows access from this computer. By default, the WinRM firewall exception for public prof    
2024-06-19T12:51:58.5702859Z iles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Tr    
2024-06-19T12:51:58.5703167Z oubleshooting Help topic.
@kine
Copy link
Contributor Author

kine commented Jun 24, 2024

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.

@kine
Copy link
Contributor Author

kine commented Jun 27, 2024

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"

@freddydk
Copy link
Contributor

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.

@kine
Copy link
Contributor Author

kine commented Jul 3, 2024

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:
image

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

@kine
Copy link
Contributor Author

kine commented Jul 25, 2024

Ok, after few days of research, I have found the original source of the problem. This is the result:

Problems:

  1. when inside container, new-pssession -containerid xxx cannot be used, thus get-bccontainersession have special case, which uses winrm in case when called from within container.
  2. when using FilesOnly container (which is the case of run-alvalidation), the start.ps1 script is called only, not navstart.ps1.
  3. New-bccontainer is creating file c:\run\my\AdditionalSetup.ps1 with code for setup the winrm access to the container
  4. AdditionalSetup.ps1 is called from navinstall.ps1 script inside the container
  5. run-alvalidation is by default calling code to create the container and just after to call script inside it to disable progress bar (see code under this list of problems). This needs to get the container session using get-bccontainersession
  6. Because only start.ps1 is called and not navstart.ps1, the AdditionalSetup.ps1 was not triggered yet, thus the winrm in the container is not set and thus the get-bccontainersession fails to get the session using winrm.
  7. Overriding start.ps1 leads to situation, that original start.ps1 code is not triggered, because if there is override, only the override is triggered. If I try run original code (c:\run\start.ps1) from override, never-ending loop is created.

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 act, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants