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

Tenant being created when using UploadImportAndApply-ConfigPackageInBcContainer #2835

Closed domingosbarreto closed 1 year ago

domingosbarreto commented 1 year ago

Describe the issue When using Run-AlPipeline, when overriding the NewBcContainer parameter to add a call to UploadImportAndApply-ConfigPackageInBcContainer this runs correctly but then a new tenant named "True" is created. The intention is to use always the default tenant.

I don't know and cannot find where this is being triggered, an this causes the failure when installing apps that requires the data previously imported with UploadImportAndApply-ConfigPackageInBcContainer (that is imported to the default tenant) and the installation is being preformed on the newly created tenant (named True).

Scripts used to create container and cause the issue

Run-AlPipeline @params `
    -pipelinename $pipelineName `
    -containerName $containerName `
    -imageName $imageName `
    -bcAuthContext $authContext `
    -environment $environmentName `
    -artifact $artifact.replace('{INSIDERSASTOKEN}',$insiderSasToken) `
    -memoryLimit $memoryLimit `
    -baseFolder $baseFolder `
    -sharedFolder "" `
    -licenseFile $LicenseFile `
    -installApps $installApps `
    -installTestApps $installTestApps `
    -previousApps $previousApps `
    -appFolders $appFolders `
    -testFolders $testFolders `
    -doNotRunTests:$doNotRunTests `
    -testResultsFile $testResultsFile `
    -testResultsFormat 'JUnit' `
    -installTestRunner:$installTestRunner `
    -installTestFramework:$installTestFramework `
    -installTestLibraries:$installTestLibraries `
    -installPerformanceToolkit:$installPerformanceToolkit `
    -enableCodeCop:$enableCodeCop `
    -enableAppSourceCop:$enableAppSourceCop `
    -enablePerTenantExtensionCop:$enablePerTenantExtensionCop `
    -enableUICop:$enableUICop `
    -azureDevOps:($environment -eq 'AzureDevOps') `
    -gitLab:($environment -eq 'GitLab') `
    -gitHubActions:($environment -eq 'GitHubActions') `
    -failOn 'error' `
    -AppSourceCopMandatoryAffixes $appSourceCopMandatoryAffixes `
    -AppSourceCopSupportedCountries $appSourceCopSupportedCountries `
    -additionalCountries $additionalCountries `
    -buildArtifactFolder $buildArtifactFolder `
    -CreateRuntimePackages:$CreateRuntimePackages `
    -appBuild $appBuild -appRevision $appRevision `
    -enableTaskScheduler $true `
    -NewBcContainer { Param([Hashtable]$parameters)
        New-BcContainer @parameters; 
        Invoke-ScriptInBcContainer $parameters.ContainerName -scriptblock { $progressPreference = 'SilentlyContinue' } 

        #Handling Config. Packages
        $tmpConfigPackageFolder = Join-Path ($env:TEMP) ([guid]::NewGuid().ToString())
        $configPackage = Join-Path $tmpConfigPackageFolder "PackageDEMOCOMPANY.rapidstart"
        Download-File -sourceUrl $configPackageFile -destinationFile $configPackage 
        UploadImportAndApply-ConfigPackageInBcContainer -containerName $parameters.ContainerName -companyName "My Company" -configPackage $configPackage -Credential $parameters.credential -packageId "DEMOCOMPANY" -tenant "default"
    }

Full output of scripts

2022-12-22T17:56:45.8467511Z BcContainerHelper is version 4.0.7
2022-12-22T17:56:45.8479285Z BcContainerHelper is running as administrator
...
2022-12-22T17:58:00.7765302Z Initialization took 66 seconds
2022-12-22T17:58:01.4350260Z Ready for connections!
2022-12-22T17:58:02.3842980Z Reading CustomSettings.config from devdocker-pbptlangpack-ci
2022-12-22T17:58:02.8380327Z Creating Desktop Shortcuts for devdocker-pbptlangpack-ci
2022-12-22T17:58:02.9902908Z Container devdocker-pbptlangpack-ci successfully created
2022-12-22T17:58:07.5395821Z 
2022-12-22T17:58:07.5433150Z Use:
2022-12-22T17:58:07.5463043Z Get-BcContainerEventLog -containerName devdocker-pbptlangpack-ci to retrieve a snapshot of the event log from the container
2022-12-22T17:58:07.5478091Z Get-BcContainerDebugInfo -containerName devdocker-pbptlangpack-ci to get debug information about the container
2022-12-22T17:58:07.5503453Z Enter-BcContainer -containerName devdocker-pbptlangpack-ci to open a PowerShell prompt inside the container
2022-12-22T17:58:07.5538905Z Remove-BcContainer -containerName devdocker-pbptlangpack-ci to remove the container again
2022-12-22T17:58:07.5550631Z docker logs devdocker-pbptlangpack-ci to retrieve information about URL's again
2022-12-22T17:58:07.9986763Z Downloading C:\Users\DOMING~1.BAR\AppData\Local\Temp\ef7bfe01-c57f-462e-b3c0-0f301db590a5\PackageDEMOCOMPANY.rapidstart
2022-12-22T17:58:09.2508548Z Invoke GET on http://172.20.89.137:7048/BC/api/v1.0/companies?$filter=name%20eq%20'My%20Company'&tenant=default
2022-12-22T17:58:20.9511706Z Deleting Configuration Package DEMOCOMPANY (if exists)
2022-12-22T17:58:21.3219900Z Invoke DELETE on http://172.20.89.137:7048/BC/api/microsoft/automation/v1.0/companies(5567bae5-9381-ed11-aad5-000d3a245498)/configurationPackages('DEMOCOMPANY')?tenant=default
2022-12-22T17:58:26.8561225Z Ignoring error while deleting configuration package
2022-12-22T17:58:26.8571109Z Creating Configuration Package DEMOCOMPANY
2022-12-22T17:58:27.2981863Z Invoke POST on http://172.20.89.137:7048/BC/api/microsoft/automation/v1.0/companies(5567bae5-9381-ed11-aad5-000d3a245498)/configurationPackages?tenant=default
2022-12-22T17:58:28.6516322Z Uploading Configuration Package DEMOCOMPANY
2022-12-22T17:58:29.0220489Z Invoke PATCH on http://172.20.89.137:7048/BC/api/microsoft/automation/v1.0/companies(5567bae5-9381-ed11-aad5-000d3a245498)/configurationPackages('DEMOCOMPANY')/file('DEMOCOMPANY')/content?tenant=default
2022-12-22T17:58:30.0328865Z Importing Configuration Package DEMOCOMPANY
2022-12-22T17:58:30.4019316Z Invoke POST on http://172.20.89.137:7048/BC/api/microsoft/automation/v1.0/companies(5567bae5-9381-ed11-aad5-000d3a245498)/configurationPackages('DEMOCOMPANY')/Microsoft.NAV.import?tenant=default
2022-12-22T17:58:37.7943528Z Completed
2022-12-22T17:58:37.7963136Z Applying Configuration Package DEMOCOMPANY
2022-12-22T17:58:38.2040662Z Invoke POST on http://172.20.89.137:7048/BC/api/microsoft/automation/v1.0/companies(5567bae5-9381-ed11-aad5-000d3a245498)/configurationPackages('DEMOCOMPANY')/Microsoft.NAV.apply?tenant=default
2022-12-22T17:58:45.5759039Z Completed
2022-12-22T17:58:46.1063053Z Creating Tenant True on devdocker-pbptlangpack-ci
2022-12-22T17:58:46.1720325Z Copying Database on localhost\SQLEXPRESS from tenant to True
2022-12-22T17:58:46.5832294Z Taking database tenant offline
2022-12-22T17:58:46.6746429Z Copying database files
2022-12-22T17:58:49.5789602Z Attaching files as new Database True
2022-12-22T17:58:59.7400477Z Putting database tenant back online
2022-12-22T17:58:59.9169650Z Mounting Database for True on server localhost\SQLEXPRESS with AllowAppDatabaseWrite = False
2022-12-22T17:59:00.6523709Z Sync'ing Tenant
2022-12-22T17:59:01.0674386Z Setting devdocker-pbptlangpack-ci-True to 172.20.89.137 in host hosts file
2022-12-22T17:59:01.1812322Z Setting devdocker-pbptlangpack-ci-True to 172.20.89.137 in container hosts file
2022-12-22T17:59:01.1848744Z Tenant successfully created
2022-12-22T17:59:01.3534342Z Creating User admin
2022-12-22T17:59:01.8847705Z Assigning Permission Set SUPER to admin
2022-12-22T17:59:05.0107000Z 
2022-12-22T17:59:05.0126034Z Creating container took 140 seconds
2022-12-22T17:59:05.0131239Z 
2022-12-22T17:59:05.0140551Z  _____                _       _                   _                           _                 _          
2022-12-22T17:59:05.0151233Z |  __ \              | |     (_)                 | |                         | |               (_)         
2022-12-22T17:59:05.0161590Z | |__) |___ ___  ___ | |_   ___ _ __   __ _    __| | ___ _ __   ___ _ __   __| | ___ _ __   ___ _  ___ ___ 
2022-12-22T17:59:05.0172239Z |  _  // _ \ __|/ _ \| \ \ / / | '_ \ / _` |  / _` |/ _ \ '_ \ / _ \ '_ \ / _` |/ _ \ '_ \ / __| |/ _ \ __|
2022-12-22T17:59:05.0182913Z | | \ \  __\__ \ (_) | |\ V /| | | | | (_| | | (_| |  __/ |_) |  __/ | | | (_| |  __/ | | | (__| |  __\__ \
2022-12-22T17:59:05.0194501Z |_|  \_\___|___/\___/|_| \_/ |_|_| |_|\__, |  \__,_|\___| .__/ \___|_| |_|\__,_|\___|_| |_|\___|_|\___|___/
2022-12-22T17:59:05.0205776Z                                        __/ |            | |                                                
2022-12-22T17:59:05.0217984Z                                       |___/             |_|                                                
2022-12-22T17:59:05.0223165Z 
2022-12-22T17:59:05.1012909Z Sorted App folders
2022-12-22T17:59:05.1029677Z - C:\agent\_work\32\s\app
2022-12-22T17:59:05.1037997Z External dependencies
2022-12-22T17:59:05.1060904Z xxx
2022-12-22T17:59:05.1073781Z xxx
2022-12-22T17:59:05.1087934Z xxx
2022-12-22T17:59:05.1099470Z xxx
2022-12-22T17:59:05.1121542Z Sorted TestApp folders
2022-12-22T17:59:05.1152960Z - None
2022-12-22T17:59:05.1157943Z 
2022-12-22T17:59:05.1170156Z   _____           _        _ _ _                                     
2022-12-22T17:59:05.1181304Z  |_   _|         | |      | | (_)                                    
2022-12-22T17:59:05.1191267Z    | |  _ __  ___| |_ __ _| | |_ _ __   __ _    __ _ _ __  _ __  ___ 
2022-12-22T17:59:05.1202550Z    | | | '_ \/ __| __/ _` | | | | '_ \ / _` |  / _` | '_ \| '_ \/ __|
2022-12-22T17:59:05.1212397Z   _| |_| | | \__ \ |_ (_| | | | | | | | (_| | | (_| | |_) | |_) \__ \
2022-12-22T17:59:05.1223564Z  |_____|_| |_|___/\__\__,_|_|_|_|_| |_|\__, |  \__,_| .__/| .__/|___/
2022-12-22T17:59:05.1234969Z                                         __/ |       | |   | |        
2022-12-22T17:59:05.1246075Z                                        |___/        |_|   |_|        
2022-12-22T17:59:05.1253466Z 
2022-12-22T17:59:05.1402241Z Downloading xxx
2022-12-22T17:59:09.1994055Z Publishing xxx
2022-12-22T17:59:20.5626365Z Synchronizing xxx on tenant True
2022-12-22T17:59:20.9052237Z Installing xxx on tenant True
2022-12-22T17:59:39.8803215Z App xxx successfully published
2022-12-22T17:59:39.9663572Z Publishing yyy
2022-12-22T17:59:53.2156198Z Synchronizing yyy on tenant True
2022-12-22T17:59:59.6158316Z Installing yyy on tenant True
2022-12-22T18:00:24.4156676Z Could not install the extension 'yyy' (version '000') on tenant 'true' and company 'My Company' due to the following error: 'The Company Information does not exist. Identification fields and values: Primary Key=''' and AL stack trace: 
2022-12-22T18:00:24.4170515Z "AAA"(CodeUnit 50000).Init line 5 - YYY by ZZZ
...
domingosbarreto commented 1 year ago

Nevermind, the enableTaskScheduler is a switch... Resolved by changing to this:

    ...
    -appBuild $appBuild -appRevision $appRevision `
    -enableTaskScheduler `
    -NewBcContainer { Param([Hashtable]$parameters)
    ...