microsoft / navcontainerhelper

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

New-BcContainer fails at Install-package SqlServer #3461

Closed NielsLeeflang closed 7 months ago

NielsLeeflang commented 7 months ago

New-BcContainer fails at Install-package SqlServer -Force -RequiredVersion 21.1.18256

Scripts used to create container and cause the issue

$containerName = 'bc23-240403'
$password = 'P@ssw0rd'
$securePassword = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object pscredential 'admin', $securePassword
$auth = 'UserPassword'
$artifactUrl = Get-BcArtifactUrl -type 'Sandbox' -country 'nl' -select 'Latest'
$licenseFile = 'C:\License\4804774_BC23_NL.bclicense'
New-BcContainer `
    -accept_eula `
    -containerName $containerName `
    -credential $credential `
    -auth $auth `
    -artifactUrl $artifactUrl `
    -licenseFile $licenseFile `
    -memoryLimit 10G `
    -updateHosts

Full output of scripts

BcContainerHelper is version 6.0.12
BcContainerHelper is running as administrator
HyperV is Enabled
UsePsSession is True
UsePwshForBc24 is True
Host is Microsoft Windows 10 Enterprise - 10.0.19045.4170
Docker Client Version is 25.0.3
Docker Server Version is 25.0.3
Removing entries from hosts
Removing bc23-240403 from container hosts file
Removing bc23-240403-* from container hosts file
Removing Desktop shortcuts
Removing C:\ProgramData\BcContainerHelper\Extensions\bc23-240403
Fetching all docker images
Fetching all docker volumes
Using image mcr.microsoft.com/businesscentral:ltsc2019
Creating Container bc23-240403
Style: sandbox
Multitenant: Yes
Version: 24.0.16410.18040
Platform: 24.0.18028.0
Generic Tag: 1.0.2.17
Container OS Version: 10.0.17763.5576 (ltsc2019)
Host OS Version: 10.0.19045.4170 (22H2)
Using hyperv isolation
Using locale nl-NL
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file C:\License\4804774_BC23_NL.bclicense
Files in C:\ProgramData\BcContainerHelper\Extensions\bc23-240403\my:
- AdditionalOutput.ps1
- HelperFunctions.ps1
- license.bclicense
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container bc23-240403 from image mcr.microsoft.com/businesscentral:ltsc2019
7a991a54e51ed87905332711126af4ac9a5a2dd8b7e7c86bca18ae1d38512299
Waiting for container bc23-240403 to be ready
Using artifactUrl https://bcartifacts.azureedge.net/sandbox/24.0.16410.18040/nl
Using installer from C:\Run\240
Installing Business Central: multitenant=True, installOnly=False, filesOnly=False, includeTestToolkit=False, includeTestLibrariesOnly=False, includeTestFrameworkOnly=False, includePerformanceToolkit=False, appArtifactPath=c:\dl\sandbox\24.0.1
6410.18040\nl, platformArtifactPath=c:\dl\sandbox\24.0.16410.18040\platform, databasePath=c:\dl\sandbox\24.0.16410.18040\nl\BusinessCentral-NL.bak, licenseFilePath=c:\dl\sandbox\24.0.16410.18040\nl\Cronus.bclicense, rebootContainer=True
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
c:\dl\sandbox\24.0.16410.18040\platform\ServiceTier\Program Files
c:\dl\sandbox\24.0.16410.18040\platform\ServiceTier\System64Folder
Copying Web Client Files
c:\dl\sandbox\24.0.16410.18040\platform\WebClient\Microsoft Dynamics NAV
Copying ModernDev Files
c:\dl\sandbox\24.0.16410.18040\platform
c:\dl\sandbox\24.0.16410.18040\platform\ModernDev\program files\Microsoft Dynamics NAV
Copying additional files
Copying ConfigurationPackages
C:\dl\sandbox\24.0.16410.18040\nl\ConfigurationPackages
Copying Test Assemblies
C:\dl\sandbox\24.0.16410.18040\platform\Test Assemblies
Copying Extensions
C:\dl\sandbox\24.0.16410.18040\nl\Extensions
Copying Applications
C:\dl\sandbox\24.0.16410.18040\platform\Applications
Copying Applications.NL
C:\dl\sandbox\24.0.16410.18040\nl\Applications.NL
Copying dependencies
Importing PowerShell Modules
Restoring CRONUS Demo Database
Setting CompatibilityLevel for tenant on localhost\SQLEXPRESS
Exporting Application to CRONUS
Removing Application from tenant
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Starting Business Central Service Tier
Importing license file
Copying Database on localhost\SQLEXPRESS from tenant to default
Taking database tenant offline
Copying database files
Attaching files as new Database default
Putting database tenant back online
Mounting tenant database
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Stopping Business Central Service Tier
Installation took 143 seconds
Installation complete
Initializing...
Setting host.docker.internal to 192.169.1.43 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.169.1.43 in container hosts file (copy from host hosts file)
Setting kubernetes.docker.internal to 127.0.0.1 in container hosts file (copy from host hosts file)
Setting host.containerhelper.internal to 172.29.0.1 in container hosts file
Starting Container
Hostname is bc23-240403
PublicDnsName is bc23-240403
WARNING: DNS resolution not working from within the container.
WARNING: Container starts with TimeZone = West-Europa (standaardtijd), which is not recognized in the list of TimeZones.
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint 356D502DDFABFDDF73BB9E22091A169B81A672BA
DNS identity bc23-240403
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using application pool name: BC
Using default container name: NavWebApplicationContainer
Copy files to WWW root C:\inetpub\wwwroot\BC
Create the application pool BC
Create website: NavWebApplicationContainer without SSL
Update configuration: navsettings.json
Done Configuring Web Client
Enabling Financials User Experience
Using license file 'c:\run\my\license.bclicense'
Import License
Dismounting Tenant
Mounting Tenant
Mounting Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Tenant is Operational
Creating http download site
Setting SA Password and enabling SA
Creating admin as SQL User and add to sysadmin
WARNING: This license is not compatible with this version of Business Central.
Creating SUPER user
WARNING: This license is not compatible with this version of Business Central.
WARNING: This license is not compatible with this version of Business Central.
Container IP Address: 172.29.5.114
Container Hostname  : bc23-240403
Container Dns Name  : bc23-240403
Web Client          : http://bc23-240403/BC/?tenant=default
Dev. Server         : http://bc23-240403
Dev. ServerInstance : BC
Dev. Server Tenant  : default
Setting bc23-240403 to 172.29.5.114 in host hosts file
Setting bc23-240403-default to 172.29.5.114 in host hosts file
Setting bc23-240403-default to 172.29.5.114 in container hosts file

Files:
http://bc23-240403:8080/ALLanguage.vsix

Container Total Physical Memory is 10.5Gb
Container Free Physical Memory is 6.2Gb

Initialization took 34 seconds
Ready for connections!

Hit Line breakpoint on 'C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.12\ContainerHandling\Invoke-ScriptInNavContainer.ps1:292'
[DBG]: PS C:\WINDOWS\system32>> $containerName
bc23-240403

[DBG]: PS C:\WINDOWS\system32>> $shell
pwsh

[DBG]: PS C:\WINDOWS\system32>> $containerFile
C:\ProgramData\BcContainerHelper\b56f24c8-e636-4502-97b7-297a3acb3249.ps1

[DBG]: PS C:\WINDOWS\system32>> 
Installing SqlServer module
New-BcContainer Telemetry Correlation Id: 7f56b388-c6b1-49eb-bcb8-94ff91950a5e
docker : Install-Package: C:\Run\my\HelperFunctions.ps1:5
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\6.0.12\ContainerHandling\Invoke-ScriptInNavContainer.ps1:292 char:17
+ ...              docker exec $containerName $shell $containerFile | Out-H ...
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Install-...tions.ps1:5:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
...

b56f24c8-e636-4502-97b7-297a3acb3249.ps1 Script

$runPath = "c:\Run"
$myPath = Join-Path $runPath "my"

function Get-MyFilePath([string]$FileName)
{
    if ((Test-Path $myPath -PathType Container) -and (Test-Path (Join-Path $myPath $FileName) -PathType Leaf)) {
        (Join-Path $myPath $FileName)
    } else {
        (Join-Path $runPath $FileName)
    }
}

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

. (Get-MyFilePath "prompt.ps1") -silent | Out-Null
. (Get-MyFilePath "ServiceSettings.ps1") | Out-Null
. (Get-MyFilePath "HelperFunctions.ps1") | Out-Null

$txt2al = ""
if ($roleTailoredClientFolder) {
    $txt2al = Join-Path $roleTailoredClientFolder "txt2al.exe"
    if (!(Test-Path $txt2al)) {
        $txt2al = ""
    }
}

Set-Location $runPath
$ErrorActionPreference = "Stop"
$startTime = [DateTime]::Now

$WarningPreference = 'SilentlyContinue'

$containerName = 'bc23-240403'

$result = Invoke-Command -ScriptBlock { try {
            $boo = $true
            while (Get-NAVServerInstance | Get-NavTenant | Where-Object { $_.State -eq "Mounting" }) {
                if ($boo) { Write-Host "Waiting for tenants to be mounted"; $boo = $false }
                Start-Sleep -Seconds 1
            }
        } catch { "::EXCEPTION::$($_.Exception.Message)" } }
$exception = $result | Where-Object { $_ -like "::EXCEPTION::*" }
if ($exception) {
    $errorMessage = $exception.SubString(13)
    Write-Host -ForegroundColor Red "$errorMessage"
    Write-Host
    try {
       $isOutOfMemory = Invoke-Command -ScriptBlock { Param($containerName, $startTime)
            $cimInstance = Get-CIMInstance Win32_OperatingSystem
            Write-Host "Container Free Physical Memory: $(($cimInstance.FreePhysicalMemory/1024/1024).ToString('F1',[CultureInfo]::InvariantCulture))Gb"
            $any = $false
            Write-Host "`nServices in container $($containerName):"
            Get-Service |
                Where-Object { $_.Name -like "MicrosoftDynamics*" -or $_.Name -like "MSSQL`$*" } |
                Select-Object -Property name, Status |
                ForEach-Object {
                    if ($_.Status -eq "Running") {
                        Write-Host "- $($_.Name) is $($_.Status)"
                    }
                    else {
                        Write-Host -ForegroundColor Red "- $($_.Name) is $($_.Status)"
                    }
                    $any = $true
                }
            if (!$any) { Write-Host -ForegroundColor Red "- No services found" }
            Write-Host
            $any = $false
            $isOutOfMemory = $false
            Get-EventLog -LogName Application | 
                Where-Object { $_.EntryType -eq "Error" -and $_.TimeGenerated -gt $startTime -and ($_.Source -like "MicrosoftDynamics*" -or $_.Source -like "MSSQL`$*") } | 
                Select-Object -Property TimeGenerated, Source, Message |
                ForEach-Object {
                    if (!$any) {
                        Write-Host "`nRelevant event log from container $($containerName):"
                    }
                    Write-Host -ForegroundColor Red "- $($_.TimeGenerated.ToString('yyyyMMdd hh:mm:ss')) - $($_.Source)"
                    $message = @($_.Message.Split("`n") | Select-Object -First 15) -join "`n  "
                    Write-Host -ForegroundColor Gray "`n  $($message)`n"
                    if ($_.Message.Contains('OutOfMemoryException')) { $isOutOfMemory = $true }
                    $any = $true
                }
            $isOutOfMemory
        } -ArgumentList $containerName, $startTime
        if ($isOutOfMemory) {
            $errorMessage = "Out Of Memory Exception thrown inside container $containerName"
        }
    } catch {}

    $result = @("::EXCEPTION::$errorMessage") + @($result | Where-Object { $_ -notlike "::EXCEPTION::*" })
}
if ($result -ne $null) { [System.Management.Automation.PSSerializer]::Serialize($result) | Set-Content -Encoding utf8 "C:\ProgramData\BcContainerHelper\b56f24c8-e636-4502-97b7-297a3acb3249.ps1.output" }
...

HelperFunctions.ps1 Script

# Invoke default behavior
          . (Join-Path $runPath $MyInvocation.MyCommand.Name)

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" } }
...

Screenshots If applicable, add screenshots to help explain your problem. image

Additional context

freddydk commented 7 months ago

Duplicate of #3460