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 246 forks source link

Setup-BCContainerTestUsers does not work with modified Base App #1399

Closed ChrisBlankDe closed 4 years ago

ChrisBlankDe commented 4 years ago

Describe the issue We use a container with an modified base app and try to create test users to test essential, premium and team member users. If we run Setup-BCContainerTestUsers (with replace dependencies) we ran into an error. probably source of error is that the script tries to replace dependencie of a runtime package.

Scripts used to create container and cause the issue

$Credential = get-credential
$artifactUrl = Get-BCArtifactUrl -type Sandbox -country de -select Latest
clear
Write-Host  "$('-'*20) Create New Container $('-'*20)"
New-BCContainer -accept_eula -accept_outdated -containerName navserver -credential $Credential -licenseFile "C:\temp\lic.flf" -auth NavUserPassword -shortcuts CommonStartMenu -updateHosts -useSSL -installCertificateOnHost -assignPremiumPlan -enableTaskScheduler -useNewDatabase -multitenant -artifactUrl $artifactUrl -memoryLimit 12GB -isolation hyperv 
Write-Host  "$('-'*20) Publish Base App $('-'*20)"
Publish-BcContainerApp -appFile "C:\git\Product_PSA_AL\MegaApp_DE\app\Kumavision AG_Project MegaApp_17.0.16993.0.app" -containerName navserver -credential $Credential -install -scope Global -skipVerification -sync

Write-Host  "$('-'*20) Publish Application App $('-'*20)"
Publish-BcContainerApp -appFile "C:\GIT\Product_PSA_AL\Application\app\Kumavision AG_Application_17.0.0.0.app" -containerName navserver -credential $Credential -install -scope Global -skipVerification -sync
Write-Host  "$('-'*20) Import Test Toolkit $('-'*20)"
Import-TestToolkitToBcContainer -containerName navserver -credential $Credential -includeTestFrameworkOnly -scope Global 
Write-Host  "$('-'*20) Setup Test Users $('-'*20)"
$Replacer = @{ "437dbf0e-84ff-417a-965d-ed2bb9650972" = @{ "id" = '34773a55-7539-486e-a55a-************'; "name" = 'Project MegaApp'; "publisher" = 'Kumavision AG'; "minversion" = '17.0.0.0' }}
Setup-BCContainerTestUsers -containerName navserver -credential $Credential -Password $($Credential.Password) -replaceDependencies $Replacer 

Full output of scripts

-------------------- Create New Container --------------------
BcContainerHelper is version 1.0.10
BcContainerHelper is running as administrator
Host is Microsoft Windows 10 Enterprise - 1909
Docker Client Version is 19.03.13
Docker Server Version is 19.03.13
Removing container navserver
Removing navserver from host hosts file
Removing navserver-* from host hosts file
Certificate with thumbprint A18D3BC3D9C78238C6118F43ADAF8BCDA835CDA9 removed successfully
Removing C:\ProgramData\BcContainerHelper\Extensions\navserver
Fetching all docker images
Using image mcr.microsoft.com/dynamicsnav:10.0.18363.1082-generic
Creating Container navserver
Version: 17.0.17126.18016-DE
Style: sandbox
Multitenant: Yes
Platform: 17.0.17020.17989
Generic Tag: 0.1.0.24
Container OS Version: 10.0.18363.1082 (1909)
Host OS Version: 10.0.18363.1082 (1909)
Using hyperv isolation
Using locale de-DE
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file C:\temp\lic.flf
Additional Parameters:
--env customNavSettings=EnableTaskScheduler=True
Files in C:\ProgramData\BcContainerHelper\Extensions\navserver\my:
- AdditionalOutput.ps1
- license.flf
- MainLoop.ps1
- SetupNavUsers.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container navserver from image mcr.microsoft.com/dynamicsnav:10.0.18363.1082-generic
e7c9907a58a63b0e0cbf911a9226eb83c14153df82f3cd851b29c3d0a9b4e18d
Waiting for container navserver to be ready
Using artifactUrl https://bcartifacts.azureedge.net/sandbox/17.0.17126.18016/de
Using installer from C:\Run\150-new
Installing Business Central
Installing from artifacts
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
Copying PowerShell Scripts
Copying dependencies
Copying ReportBuilder
Importing PowerShell Modules
Determining Database Collation from c:\dl\sandbox\17.0.17126.18016\de\BusinessCentral-DE.bak
Restoring CRONUS Demo Database
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 Extensions
Copying Applications
Copying Applications.DE
Starting Business Central Service Tier
Importing license file
Stopping Business Central Service Tier
Installation took 108 seconds
Installation complete
Initializing...
Setting host.docker.internal to 192.168.0.122 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.0.122 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.30.176.1 in container hosts file
Starting Container
Hostname is navserver
PublicDnsName is navserver
WARNING: Container starts with TimeZone = Mitteleuropäische Zeit, which is not recognized in the list of TimeZones.
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint A2038A248A43D9C4787D654EBF86E4F112017C88
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting EnableTaskScheduler to True
Starting Service Tier
Registering event sources
Creating DotNetCore Web Server Instance
Enabling Financials User Experience
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
Container IP Address: 172.30.182.234
Container Hostname  : navserver
Container Dns Name  : navserver
Web Client          : https://navserver/BC/
Dev. Server         : https://navserver
Dev. ServerInstance : BC
Setting navserver to 172.30.182.234 in host hosts file

Files:
http://navserver:8080/ALLanguage.vsix
http://navserver:8080/certificate.cer

Container Total Physical Memory is 12.5Gb
Container Free Physical Memory is 10.0Gb

Initialization took 39 seconds
Ready for connections!
Reading CustomSettings.config from navserver
Certificate with thumbprint A2038A248A43D9C4787D654EBF86E4F112017C88 imported successfully
Creating Desktop Shortcuts for navserver
Stopping ServiceTier in order to replace database
Copying Database on localhost\SQLEXPRESS from CRONUS to mytempdb
Taking database CRONUS offline
Copying database files
Attaching files as new Database mytempdb
Putting database CRONUS back online
Removing Database CRONUS from localhost\SQLEXPRESS
Creating new database CRONUS on localhost\SQLEXPRESS with Collation Latin1_General_100_CS_AS
Copying table [Entitlement] from original database
Copying table [Entitlement Set] from original database
Copying table [Membership Entitlement] from original database
Removing Database mytempdb from localhost\SQLEXPRESS
Starting Service Tier
Synchronizing
Importing license file
Importing License C:\ProgramData\BcContainerHelper\Extensions\navserver\my\license.flf
Creating user admin
Creating User admin
Assigning Permission Set SUPER to admin
Publishing System Symbols
Copy from container navserver (C:\Program Files\Microsoft Dynamics NAV\170\AL Development Environment\System.app) to C:\ProgramData\BcContainerHelper\Extensions\navserver\_System.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_System.app
App successfully published
Creating Company
Creating company My Company in default
Company successfully created
Publishing System Application
Copy from container navserver (C:\Applications\System Application\Source\Microsoft_System Application.app) to C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_System Application.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_System Application.app
Synchronizing System Application on tenant default
Installing System Application on tenant default
App successfully published
Switching to multitenant
Copying Database on localhost\SQLEXPRESS from CRONUS to tenant
Taking database CRONUS offline
Copying database files
Attaching files as new Database tenant
Putting database CRONUS back online
Removing Database CRONUS from localhost\SQLEXPRESS
Exporting Application to CRONUS
Removing Application from tenant
WARNUNG: The new settings value will not take effect until you stop and restart the service.
Creating Tenant default on navserver
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 Database for default on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
Sync'ing Tenant
Setting navserver-default to 172.30.182.234 in host hosts file
Tenant successfully created
Container navserver successfully created

Use:
Get-BcContainerEventLog -containerName navserver to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName navserver to get debug information about the container
Enter-BcContainer -containerName navserver to open a PowerShell prompt inside the container
Remove-BcContainer -containerName navserver to remove the container again
docker logs navserver to retrieve information about URL's again
-------------------- Publish Base App --------------------
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Kumavision AG_Project MegaApp_17.0.16993.0.app
Synchronizing Project MegaApp on tenant default
Installing Project MegaApp on tenant default
App successfully published
-------------------- Publish Application App --------------------
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Kumavision AG_Application_17.0.0.0.app
Synchronizing Application on tenant default
Installing Application on tenant default
App successfully published
-------------------- Import Test Toolkit --------------------
Copy from container navserver (C:\ProgramData\BcContainerHelper\Extensions\sandbox-Applications-17.0.17126.18016-DE\Microsoft_Any_17.0.17126.18016.runtime.app) to C:\ProgramData\BcContainerHelper\Extensions\navserver\_Micros
oft_Any_17.0.17126.18016.runtime.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_Any_17.0.17126.18016.runtime.app
Synchronizing Any on tenant default
Installing Any on tenant default
App successfully published
Copy from container navserver (C:\ProgramData\BcContainerHelper\Extensions\sandbox-Applications-17.0.17126.18016-DE\Microsoft_Library Assert_17.0.17126.18016.runtime.app) to C:\ProgramData\BcContainerHelper\Extensions\navser
ver\_Microsoft_Library Assert_17.0.17126.18016.runtime.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_Library Assert_17.0.17126.18016.runtime.app
Synchronizing Library Assert on tenant default
Installing Library Assert on tenant default
App successfully published
Copy from container navserver (C:\ProgramData\BcContainerHelper\Extensions\sandbox-Applications-17.0.17126.18016-DE\Microsoft_Library Variable Storage_17.0.17126.18016.runtime.app) to C:\ProgramData\BcContainerHelper\Extensi
ons\navserver\_Microsoft_Library Variable Storage_17.0.17126.18016.runtime.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_Library Variable Storage_17.0.17126.18016.runtime.app
Synchronizing Library Variable Storage on tenant default
Installing Library Variable Storage on tenant default
App successfully published
Copy from container navserver (C:\ProgramData\BcContainerHelper\Extensions\sandbox-Applications-17.0.17126.18016-DE\Microsoft_Test Runner.runtime.app) to C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_Test 
Runner.runtime.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_Test Runner.runtime.app
Synchronizing Test Runner on tenant default
Installing Test Runner on tenant default
App successfully published
TestToolkit successfully imported
-------------------- Setup Test Users --------------------
Copy from container navserver (C:\Applications\system application\test\Microsoft_System Application Test Library.app) to C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_System Application Test Library.app
Checking dependencies in C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_System Application Test Library.app
Publishing C:\ProgramData\BcContainerHelper\Extensions\navserver\_Microsoft_System Application Test Library.app
Synchronizing System Application Test Library on tenant default
Installing System Application Test Library on tenant default
App successfully published
Downloading C:\Users\ADMINI~1\AppData\Local\Temp\CreateTestUsers.app
Checking dependencies in C:\Users\ADMINI~1\AppData\Local\Temp\CreateTestUsers.app
Exception calling "Open" with "3" argument(s): "File contains corrupted data."
at <ScriptBlock>, <No file>: line 36
Exception calling "Open" with "3" argument(s): "File contains corrupted data."
In C:\Program Files\WindowsPowerShell\Modules\bccontainerhelper\1.0.10\ContainerHandling\Invoke-ScriptInNavContainer.ps1:39 Zeichen:13
+             Invoke-Command -Session $session -ScriptBlock $scriptbloc ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileFormatException
    + PSComputerName        : e7c9907a58a63b0e0cbf911a9226eb83c14153df82f3cd851b29c3d0a9b4e18d

...
freddydk commented 4 years ago

The default app used is a runtime package and that one cannot replace dependencies- You can try to download the app from here: https://businesscentralapps.blob.core.windows.net/createtestusers/16.0.10221.0/apps.zip, unzip and specify that to:

-createTestUsersAppUrl "<appfilename>"

to the Setup-BcContainerTestsUsers call.

freddydk commented 4 years ago

In the latest preview you can specify

-createTestUsersAppUrl "https://businesscentralapps.blob.core.windows.net/createtestusers/16.0.10221.0/apps.zip"

that should work for you as a workaround.