microsoft / navcontainerhelper

Official Microsoft repository for BcContainerHelper, a PowerShell module, which makes it easier to work with Business Central Containers on Docker.
MIT License
386 stars 247 forks source link

New-BcContainer fails for containers prior to version 24 due to useWinRmSession option #3744

Closed lbev7 closed 2 weeks ago

lbev7 commented 2 weeks ago

Describe the issue We recently upgraded BCContainerHelper from version 6.0.15 to 6.0.26. Since then, we've encountered issues when creating Docker containers for any BC version prior to 24. From what I understand, BC version 24 and later use PowerShell Core 7 internally, which seems to be the source of our issue.

During the container initialization process, New-BcContainer generates and runs an AdditionalSetup.ps1 script in the my container folder. This script contains pwsh.exe command, which causes error on BC versions below 24 due to the absence of PS7. In the version 6.0.15, AdditionalSetup.ps1 was not generated, as the relevant logic in line 1426 was introduced in versions 6.0.16 and 6.0.17.

While WinRM is active on the host machine, it is configured only to allow PowerShell remote access across our network and is not intended for BCContainerHelper operations.

Scripts used to create container and cause the issue

New-BCContainer -accept_eula -accept_outdated -assignPremiumPlan -doNotExportObjectsToText -useTraefik `
 -enableTaskScheduler -includeAL -licenseFile $licencePath -updateHosts -TimeZoneId "Central European Standard Time" `
 -PublicDnsName $publicDnsName -auth NavUserPassword -shortcuts None -doNotCheckHealth -imageName w1:20 -containerName $Container

Full output of scripts

Using parameters ContainerName
BcContainerHelper version 6.0.26
Setting containerHelperFolder = c:\programdata\navcontainerhelper
Setting hostHelperFolder = c:\programdata\navcontainerhelper
BC.HelperFunctions emits usage statistics telemetry to Microsoft
Running on Windows, PowerShell 5.1.17763.5576
LatestGenericTagVersion is 1.0.2.50
BcContainerHelper is version 6.0.26
BcContainerHelper is running as administrator
HyperV is Disabled
Host is Microsoft Windows Server 2019 Standard - 10.0.17763.5576
UsePsSession is True
UsePwshForBc24 is True
UseWinRmSession is allow
UseSslForWinRmSession is True
Docker Client Version is 18.09.6
Docker Server Version is 18.09.6
Removing Desktop shortcuts
Fetching all docker images
Fetching all docker volumes
Disabling SSL on the container as you have configured -forceHttpWithTraefik
Using image w1:20
PublicDnsName is dev.domain.com
Disabling Health Check (always report healthy)
Creating Container ContainerName
Style: onprem
Multitenant: No
Version: 20.0.37253.38230
Platform: 20.0.37114.38150
Generic Tag: 1.0.2.13
Container OS Version: 10.0.17763.437 (ltsc2019)
Host OS Version: 10.0.17763.5576 (ltsc2019)
Host OS and Base Image Container OS doesn't match, recommended isolation mode is hyperv. HyperV is not installed, recommending process isolation instead.
Using process isolation
Using locale en-US
Adding special CheckHealth.ps1 to enable Traefik support
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file C:\licence.flf
Additional Parameters:
--expose 5986
-e webserverinstance=ContainerName
-e publicdnsname=dev.domain.com
-l "traefik.protocol=http"
-l "traefik.web.frontend.rule=PathPrefix:/ContainerName"
-l "traefik.web.port=80"
-l "traefik.soap.frontend.rule=PathPrefix:/ContainerNamesoap;ReplacePathRegex: ^/ContainerNamesoap(.*) /BC$1"
-l "traefik.soap.port=7047"
-l "traefik.rest.frontend.rule=PathPrefix:/ContainerNamerest;ReplacePathRegex: ^/ContainerNamerest(.*) /BC$1"
-l "traefik.rest.port=7048"
-l "traefik.dev.frontend.rule=PathPrefix:/ContainerNamedev;ReplacePathRegex: ^/ContainerNamedev(.*) /BC$1"
-l "traefik.dev.port=7049"
-l "traefik.snap.frontend.rule=PathPrefix:/ContainerNamesnap;ReplacePathRegex: ^/ContainerNamesnap(.*) /BC$1"
-l "traefik.snap.port=7083"
-l "traefik.dl.frontend.rule=PathPrefixStrip:/ContainerNamedl"
-l "traefik.dl.port=8080"
-l "traefik.dl.protocol=http"
-l "traefik.enable=true"
-l "traefik.frontend.entryPoints=https"
--env customNavSettings=EnableTaskScheduler=True,PublicODataBaseUrl=https://dev.domain.com/ContainerNamerest/odata,PublicSOAPBaseUrl=https://dev.domain.com/ContainerNamesoap/ws,PublicWebBaseUrl=https://dev.domain.com/ContainerName
Files in c:\programdata\navcontainerhelper\Extensions\ContainerName\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- CheckHealth.ps1
- HelperFunctions.ps1
- license.flf
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container ContainerName from image w1:20
b19470dda40173ed1bf3454807baef599cd9f63c4a78d96f8724910dadfb8848
Waiting for container ContainerName to be ready
Initializing...
Setting host.containerhelper.internal to 172.19.208.1 in container hosts file
Starting Container
Hostname is ContainerName
PublicDnsName is dev.domain.com
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 325E06958E7EAAD6F74C90F3F45869196AA041B8
DNS identity dev.domain.com
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting EnableTaskScheduler to True
Setting PublicODataBaseUrl to https://dev.domain.com/ContainerNamerest/odata
Setting PublicSOAPBaseUrl to https://dev.domain.com/ContainerNamesoap/ws
Setting PublicWebBaseUrl to https://dev.domain.com/ContainerName
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: ContainerName
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\ContainerName
Create the application pool ContainerName
Create website: NavWebApplicationContainer without SSL
Update configuration: navsettings.json
Done Configuring Web Client
Using license file 'c:\run\my\license.flf'
Import License
Creating http download site
Setting SA Password and enabling SA
Creating admin as SQL User and add to sysadmin
Creating SUPER user
Assign Premium plan for ADMIN
Enable PSRemoting and setup user for winrm
The term 'pwsh.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at <ScriptBlock>, C:\Run\my\AdditionalSetup.ps1: line 6
at <ScriptBlock>, C:\Run\navstart.ps1: line 240
at <ScriptBlock>, C:\Run\start.ps1: line 384
at <ScriptBlock>, <No file>: line 1Error
Initializing...
Setting host.containerhelper.internal to 172.19.208.1 in container hosts file
Starting Container
Hostname is ContainerName
PublicDnsName is dev.domain.com
Using NavUserPassword Authentication
Starting Local SQL Server
Starting Internet Information Server
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 325E06958E7EAAD6F74C90F3F45869196AA041B8
DNS identity dev.domain.com
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting EnableTaskScheduler to True
Setting PublicODataBaseUrl to https://dev.domain.com/ContainerNamerest/odata
Setting PublicSOAPBaseUrl to https://dev.domain.com/ContainerNamesoap/ws
Setting PublicWebBaseUrl to https://dev.domain.com/ContainerName
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: ContainerName
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\ContainerName
Create the application pool ContainerName
Create website: NavWebApplicationContainer without SSL
Update configuration: navsettings.json
Done Configuring Web Client
Using license file 'c:\run\my\license.flf'
Import License
Creating http download site
Setting SA Password and enabling SA
Creating admin as SQL User and add to sysadmin
Creating SUPER user
Assign Premium plan for ADMIN
Enable PSRemoting and setup user for winrm
The term 'pwsh.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at <ScriptBlock>, C:\Run\my\AdditionalSetup.ps1: line 6
at <ScriptBlock>, C:\Run\navstart.ps1: line 240
at <ScriptBlock>, C:\Run\start.ps1: line 384
at <ScriptBlock>, <No file>: line 1
New-BCContainer Telemetry Correlation Id: 4b1a35f0-9277-486a-85cc-38ac93f3aa1c
Initialization of container ContainerName failed
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.26\ContainerHandling\Wait-NavContainerReady.ps1:42 char:17
+ ...             throw "Initialization of container $containerName failed" ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Initialization ...V20-test failed:String) [], RuntimeException
    + FullyQualifiedErrorId : Initialization of container ContainerName failed

Additional context

Please let me know if I've misunderstood or overlooked any details.

similar-issues-ai[bot] commented 2 weeks ago

We've found some similar issues:

If any of the above are duplicates, please consider closing this issue out and adding additional context in the original issue.

Note: You can give me feedback by 👍 or 👎 this comment.

freddydk commented 2 weeks ago

The problem is that you are using an outdated generic image. Add -alwaysPull to your New-BcContainer and you should be good.

lbev7 commented 2 weeks ago

Hi Freddy, you are correct, an outdated generic image caused this issue. This raises another question. We've used premade BC images to speed up build time. Now with -alwaysPull build time increases significantly, even in some situations builds would fail due to unavailablity of servers or low latency, making this approach unpractical.

We're planning now to refresh BC images on a monthly basis, especially before the BCContainerHelper upgrades. However, I am wondering if there is any more flexible solution for us that you could suggest?

freddydk commented 2 weeks ago

Generic images are updated every month (around the 15th) and you should uptake every update to stay secure and functional.

lbev7 commented 2 weeks ago

Great, we'll adjust our jobs to update images at monthly basis somtime after 15th. Thanks for your assistance.