microsoft / navcontainerhelper

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

Unable to create BC 16.0 container with tests #1623

Closed ti-jalopez closed 3 years ago

ti-jalopez commented 3 years ago

PLEASE DO NOT INCLUDE ANY PASSWORDS OR TOKENS IN YOUR ISSUE!!!

Describe the issue Create a BCContainer for BC 16.0 including test fails. The error is:

Cannot find path 'C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch\es' because it does not exist.
at <ScriptBlock>, <No file>: line 2
Cannot find path 'C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch\es' because it does not exist.
En C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\1.0.19\ContainerHandling\Invoke-ScriptInNavContainer.ps1: 39 
Carácter: 13
+             Invoke-Command -Session $session -ScriptBlock $scriptbloc ...

After that, I have been researching in BCContainerHelper source code, and I 've put a breakpoint on https://github.com/microsoft/navcontainerhelper/blob/c31a6ac484d678eae11e65e408ac73899772a377/ContainerHandling/New-NavContainer.ps1#L1713

The full output script show some values of variables after breakpoint enter in Invoke-ScriptInNavContainer.ps1 (see [DBG] on output). I think the problem is caused by I've changed settings for $bcContainerHelperConfig.hostHelperFolder to c:\containerhelper, and the code in https://github.com/microsoft/navcontainerhelper/blob/c31a6ac484d678eae11e65e408ac73899772a377/ContainerHandling/New-NavContainer.ps1#L1708 uses $containerhelper (the folder on host) that is different to the folder inside the container c:\ProgramData\bccontainerhelper.

Scripts used to create container and cause the issue


$bcContainerHelperConfig.hostHelperFolder = "C:\ContainerHelper"
$bcContainerHelperConfig | ConvertTo-Json | Set-Content "C:\ProgramData\BcContainerHelper\BcContainerHelper.config.json"

$containerName = 'BC16RTM'
$myLicense = '<my_license_file>'
$navcredential = Get-Credential
$myArtifactUrl = Get-BCArtifactUrl -type OnPrem -version 16.0 -country es -select Latest

New-BCContainer -auth NavUserPassword -Credential $navcredential -updateHosts -accept_eula -containername $containerName `
                -artifactUrl $myArtifactUrl -licenseFile $myLicense -accept_outdated -includeAL -includeTestToolkit

Full output of scripts

BcContainerHelper is version 1.0.19
BcContainerHelper is running as administrator
Host is Microsoft Windows 10 Pro - 20H2
Docker Client Version is 20.10.2
Docker Server Version is 20.10.2
Removing container BC16RTM
Removing BC16RTM from host hosts file
Removing BC16RTM-* from host hosts file
Removing C:\ContainerHelper\Extensions\BC16RTM
Fetching all docker images
Using image mcr.microsoft.com/businesscentral:10.0.19042.746
Creating Container BC16RTM
Version: 16.0.11240.12085-es
Style: onprem
Multitenant: No
Platform: 16.0.11233.12078
Generic Tag: 1.0.1.3
Container OS Version: 10.0.19042.746 (20H2)
Host OS Version: 10.0.19042.746 (20H2)
Using process isolation
Using locale es-ES
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file <my_license_file>
Files in C:\ContainerHelper\Extensions\BC16RTM\my:
- AdditionalOutput.ps1
- license.flf
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container BC16RTM from image mcr.microsoft.com/businesscentral:10.0.19042.746
2b47de1c87996e1676802e31f0523bcf09afe9fd4cb533ff40e1c959ff07b2d7
Waiting for container BC16RTM to be ready
Using artifactUrl https://bcartifacts.azureedge.net/onprem/16.0.11240.12085/es
Using installer from C:\Run\150-new
Installing Business Central
Installing from artifacts
Starting Local SQL Server
WARNING: Waiting for service 'SQL Server (SQLEXPRESS) (MSSQL$SQLEXPRESS)' to 
start...
WARNING: Waiting for service 'SQL Server (SQLEXPRESS) (MSSQL$SQLEXPRESS)' to 
start...
Starting Internet Information Server
Copying Service Tier Files
Copying PowerShell Scripts
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Determining Database Collation from c:\dl\onprem\16.0.11240.12085\es\database\Demo Database NAV (16-0).bak
Changing Database Server Collation to Modern_Spanish_100_CI_AS
Restoring CRONUS Demo Database
Setting CompatibilityLevel for CRONUS on localhost\SQLEXPRESS
Modifying Business Central Service Tier Config File for Docker
Creating Business Central Service Tier
Installing SIP crypto provider: 'C:\Windows\System32\NavSip.dll'
Copying Web Client Files
Copying Client Files
Copying ModernDev Files
Copying additional files
Copying ConfigurationPackages
Copying Test Assemblies
Copying Applications
Starting Business Central Service Tier
Importing license file
Stopping Business Central Service Tier
Installation took 229 seconds
Installation complete
Initializing...
Setting host.docker.internal to 192.168.0.27 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.0.27 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.144.1 in container hosts file
Starting Container
Hostname is BC16RTM
PublicDnsName is BC16RTM
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint E6A2D302CC36E5FC4599B536FDBBAF3E5140C942
Modifying Service Tier Config File with Instance Specific Settings
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Using license file 'c:\run\my\license.flf'
Import License
Creating http download site
Setting SA Password and enabling SA
Creating nav as SQL User and add to sysadmin
Creating SUPER user
Container IP Address: 172.29.153.58
Container Hostname  : BC16RTM
Container Dns Name  : BC16RTM
Web Client          : http://BC16RTM/BC/
Dev. Server         : http://BC16RTM
Dev. ServerInstance : BC
Setting BC16RTM to 172.29.153.58 in host hosts file

Files:
http://BC16RTM:8080/ALLanguage.vsix

Container Total Physical Memory is 31.8Gb
Container Free Physical Memory is 11.2Gb

Initialization took 315 seconds
Ready for connections!
Reading CustomSettings.config from BC16RTM
Creating Desktop Shortcuts for BC16RTM
Downloading new test apps for this version from https://bcdocker.blob.core.windows.net/public/12076-patch/ES.zip
Downloading C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch.zip
Extracting new test apps for this version 
Alcanzar Punto de interrupción de línea en 'C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\1.0.19\ContainerHandling\New-NavContainer.ps1:1778'
[DBG]: PS C:\Windows\system32>> Write-host $zipName
C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch

[DBG]: PS C:\Windows\system32>> $containerName
BC16RTM

[DBG]: PS C:\Windows\system32>> (Join-Path $zipName "$devCountry\*.app")
C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch\es\*.app

[DBG]: PS C:\Windows\system32>> 
using Expand-Archive

[DBG]: PS C:\Windows\system32>> 
Patching .app files in C:\Applications\BaseApp\Test due to issue #925

[DBG]: PS C:\Windows\system32>> 

[DBG]: PS C:\Windows\system32>> $containerName
BC16RTM

[DBG]: PS C:\Windows\system32>> $scriptblock
 Param($zipName, $devCountry)
            Copy-Item -Path (Join-Path $zipName "$devCountry\*.app") -Destination "c:\Applications\BaseApp\Test" -Force

[DBG]: PS C:\Windows\system32>> $argumentList
C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch
es

[DBG]: PS C:\Windows\system32>> 

[DBG]: PS C:\Windows\system32>> $useSession
True

[DBG]: PS C:\Windows\system32>> $session

 Id Name            ComputerName    ComputerType    State         ConfigurationName     Availability
 -- ----            ------------    ------------    -----         -----------------     ------------
  3 WinRM3          2b47de1c8799... Container       Opened                                 Available

[DBG]: PS C:\Windows\system32>> 
Cannot find path 'C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch\es' because it does not exist.
at <ScriptBlock>, <No file>: line 2
Cannot find path 'C:\ContainerHelper\Extensions\BC16RTM\16.0.11240.12076-es-Tests-Patch\es' because it does not exist.
En C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\1.0.19\ContainerHandling\Invoke-ScriptInNavContainer.ps1: 39 
Carácter: 13
+             Invoke-Command -Session $session -ScriptBlock $scriptbloc ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\ContainerHel...-Tests-Patch\es:String) [Copy-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
    + PSComputerName        : 2b47de1c87996e1676802e31f0523bcf09afe9fd4cb533ff40e1c959ff07b2d7
...

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

Additional context

freddydk commented 3 years ago

If you replace line 1715 in New-NavContainer.ps1 from this:

            } -argumentList $zipName, $devcountry

to

            } -argumentList (Get-BcContainerPath -containerName $containerName -path $zipName), $devcountry

Then it should work. If you can verify this, I will checkin the fix.

ti-jalopez commented 3 years ago

I've tested it and it runs fine 👍 I think the same problem will occur when you are patching for version "14.10.40471.0": https://github.com/microsoft/navcontainerhelper/blob/4e35247976412dcfa71a097386fd1f7c2d6f1b3e/ContainerHandling/New-NavContainer.ps1#L1695-L1701

Best regards,

beterna-cstuber commented 3 years ago

I've experienced a similar issue lately when using the onprem/16.0.11240.12085/de artifacts. However I discovered the following:

This throws an error when trying to create the image.

    New-BCContainer @Parameters `
        -doNotCheckHealth `
        -updateHosts `
        -containerName $containerName `
        -artifactUrl $artifactUrl `
        -auth "UserPassword" `
        -Credential $credential `
        -additionalParameters $additionalParameters `
        -includeTestToolkit `
        -includeTestLibrariesOnly `
        -doNotUseRuntimePackages `
        -enableTaskScheduler:$false

This creates the image and container without problems, patches the app files and then installs the test libraries.

    New-BCContainer @Parameters `
        -doNotCheckHealth `
        -updateHosts `
        -containerName $containerName `
        -artifactUrl $artifactUrl `
        -auth "UserPassword" `
        -Credential $credential `
        -additionalParameters $additionalParameters `
        -doNotUseRuntimePackages `
        -enableTaskScheduler:$false

    Import-TestToolkitToBcContainer -containerName $containerName -includeTestLibrariesOnly

So my issue seems to have been that New-BCImage doesn't use the patched apps.

freddydk commented 3 years ago

That might be, yes,

freddydk commented 3 years ago

Shipped in BcContainerHelper 2.0.0