microsoft / navcontainerhelper

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

Problem with UploadImportAndApply-ConfigPackageInBcContainer #1826

Closed fridrichovsky closed 3 years ago

fridrichovsky commented 3 years ago

Describe the issue Hello I am trying use function UploadImportAndApply-ConfigPackageInBcContainer. I don't know what I am doing wrong, but I get this message "Couldn't import configuration package". I didn't find details for this error so I don't know what is wrong. My test are bellow. Last test was only for sure that I can use file path from local machine. When command ends with "Couldn't import configuration package" I can find package in Configurations Packages, but it exists without content (data and table/field configuration)

Can you help me?

Command use file from my machine but folder is shared to container

UploadImportAndApply-ConfigPackageInBcContainer -containerName $ContainerName -tenant default -Credential $credential -configPackage "C:\Containers\TEST-Container\Backups\RapidStarts\NAV17.5.W1.ENU.EVALUATION.rapidstart"

Full output of scripts

Invoke GET on http://172.22.3.73:7048/BC/api/v1.0/companies?$filter=name%20eq%20'CRONUS%20International%20Ltd.'&tenant=default
Deleting Configuration Package NAV17.5.W1.ENU.EVALU (if exists)
Invoke DELETE on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages('NAV17.5.W1.ENU.EVALU')?tenant=default
Creating Configuration Package NAV17.5.W1.ENU.EVALU
Invoke POST on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages?tenant=default
Uploading Configuration Package NAV17.5.W1.ENU.EVALU
Invoke PATCH on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages('NAV17.5.W1.ENU.EVALU')/file('NAV17.5.W1.ENU.EVALU')/content?tenant=default
Importing Configuration Package NAV17.5.W1.ENU.EVALU
Invoke POST on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages('NAV17.5.W1.ENU.EVALU')/Microsoft.NAV.import?tenant=default
Error 
Couldn't import configuration package
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.7\ConfigPackageHandling\UploadImportAndApply-ConfigPackageInBcContainer.ps1:140 char:13
+             throw "Couldn't import configuration package"
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (Couldn't import configuration package:String) [], RuntimeException
+ FullyQualifiedErrorId : Couldn't import configuration package

Command use package name from "C:\ConfigurationPackages" in container

UploadImportAndApply-ConfigPackageInBcContainer -containerName $ContainerName -tenant default -Credential $credential -configPackage "STANDARD"

Full output of scripts

Copy from container TEST-Container (C:\ConfigurationPackages\NAV17.5.W1.ENU.STANDARD.rapidstart) to C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\NAV17.5.W1.ENU.STANDARD.rapidstart
Invoke GET on http://172.22.3.73:7048/BC/api/v1.0/companies?$filter=name%20eq%20'CRONUS%20International%20Ltd.'&tenant=default
Deleting Configuration Package STANDARD (if exists)
Invoke DELETE on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages('STANDARD')?tenant=default
Ignoring error while deleting configuration package
Creating Configuration Package STANDARD
Invoke POST on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages?tenant=default
Uploading Configuration Package STANDARD
Invoke PATCH on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages('STANDARD')/file('STANDARD')/content?tenant=default
Importing Configuration Package STANDARD
Invoke POST on http://172.22.3.73:7048/BC/api/microsoft/automation/v1.0/companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages('STANDARD')/Microsoft.NAV.import?tenant=default
Error
Couldn't import configuration package
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.7\ConfigPackageHandling\UploadImportAndApply-ConfigPackageInBcContainer.ps1:140 char:13
+             throw "Couldn't import configuration package"
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (Couldn't import configuration package:String) [], RuntimeException
+ FullyQualifiedErrorId : Couldn't import configuration package

Command use package file name from "C:\ConfigurationPackages\NAV17.5.W1.ENU.STANDARD.rapidstart" in container

UploadImportAndApply-ConfigPackageInBcContainer -containerName $ContainerName -tenant default -Credential $credential -configPackage "C:\ConfigurationPackages\NAV17.5.W1.ENU.STANDARD.rapidstart"

Full output of scripts

The filename, directory name, or volume label syntax is incorrect.

at <ScriptBlock>, <No file>: line 2
at Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.7\ContainerHandling\Invoke-ScriptInNavContainer.ps1: line 44
at UploadImportAndApply-ConfigPackageInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.7\ConfigPackageHandling\UploadImportAndApply-ConfigPackageInBcContainer.ps1: line 44
at <ScriptBlock>, <No file>: line 1
The filename, directory name, or volume label syntax is incorrect.
At C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.7\ContainerHandling\Invoke-ScriptInNavContainer.ps1:45 char:13
+             throw $_.Exception.Message
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (The filename, d...is incorrect.
:String) [], RuntimeException
    + FullyQualifiedErrorId : The filename, directory name, or volume label syntax is incorrect.
freddydk commented 3 years ago

Could you share the script and full output of the container generation, so that I can try to repro this? Thanks

fridrichovsky commented 3 years ago

Hello here is output

BcContainerHelper is version 2.0.7
BcContainerHelper is running as administrator
Host is Microsoft Windows 10 Enterprise - 20H2
Docker Client Version is 20.10.5
Docker Server Version is 20.10.5
Removing TEST-Container from host hosts file
Removing TEST-Container-* from host hosts file
Removing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container
Fetching all docker images
Fetching all docker volumes
Pulling image mcr.microsoft.com/businesscentral:10.0.19042.867
10.0.19042.867: Pulling from businesscentral
Digest: sha256:2471a68787c625b4b5243fc5ed3cf3ebc26f42b524ccc1aba18cf994e5906be7
Status: Image is up to date for mcr.microsoft.com/businesscentral:10.0.19042.867
mcr.microsoft.com/businesscentral:10.0.19042.867
Using image mcr.microsoft.com/businesscentral:10.0.19042.867
Creating Container TEST-Container
Version: 17.5.22499.22546-w1
Style: onprem
Multitenant: No
Platform: 17.0.22463.22540
Generic Tag: 1.0.1.4
Container OS Version: 10.0.19042.867 (20H2)
Host OS Version: 10.0.19042.867 (20H2)
Using process isolation
Using locale en-US
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file \\srv-file01\Produkty\Licence\D365BC170\Latest\4805287.flf
Additional Parameters:
--cpu-count 4 --dns=8.8.8.8 -e customnavsettings=ClientServicesMaxUploadSize=2000,MaxStreamReadSize=1000000000,SqlManagementCommandTimeout=-1,SOAPServicesOperationTimeout=00:10:00,NavHttpClientMaxTimeout=00:10:00,NavHttpClientMaxResponseContentSize=15,EnableTaskScheduler=True
--volume C:\Containers\TEST-Container\RapidStarts:C:\Temp\RapidStarts
--volume C:\Containers\TEST-Container\TempFiles:C:\Temp\TempFiles
--volume C:\Containers\TEST-Container\Agent:C:\Agent
--volume C:\Containers\TEST-Container\Packages:C:\Temp\Packages
--volume C:\Containers\TEST-Container\Backups:C:\Temp\Backups
Files in C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\my:
- AdditionalOutput.ps1
- AdditionalSetup.ps1
- license.flf
- MainLoop.ps1
- SetupVariables.ps1
- updatehosts.ps1
Creating container TEST-Container from image mcr.microsoft.com/businesscentral:10.0.19042.867
f7ab1230eba335bc8f7856fcbb94eebb99ddc3a0f9d9b932b63722138e8d2ab4
Waiting for container TEST-Container to be ready
Using artifactUrl https://bcartifacts.azureedge.net/onprem/17.5.22499.22546/w1
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\onprem\17.5.22499.22546\w1\database\Demo Database NAV (17-0).bak
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 115 seconds
Installation complete
Initializing...
Setting host.docker.internal to 192.168.2.170 in container hosts file (copy from host hosts file)
Setting gateway.docker.internal to 192.168.2.170 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.26.64.1 in container hosts file
Starting Container
Hostname is TEST-Container
PublicDnsName is TEST-Container
Using NavUserPassword Authentication
Creating Self Signed Certificate
Self Signed Certificate Thumbprint E06787C9FC1F39A6E2F4A710C40CEA912A5E5458
Modifying Service Tier Config File with Instance Specific Settings
Modifying Service Tier Config File with settings from environment variable
Setting ClientServicesMaxUploadSize to 2000
Setting MaxStreamReadSize to 1000000000
Setting SqlManagementCommandTimeout to -1
Setting SOAPServicesOperationTimeout to 00:10:00
Setting NavHttpClientMaxTimeout to 00:10:00
Setting NavHttpClientMaxResponseContentSize to 15
Setting EnableTaskScheduler to True
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 Admin as SQL User and add to sysadmin
Creating SUPER user
Container IP Address: 172.26.77.220
Container Hostname  : TEST-Container
Container Dns Name  : TEST-Container
Web Client          : http://TEST-Container/BC/
Dev. Server         : http://TEST-Container
Dev. ServerInstance : BC
Setting TEST-Container to 172.26.77.220 in host hosts file
Files:
http://TEST-Container:8080/ALLanguage.vsix
Container Total Physical Memory is 31.8Gb
Container Free Physical Memory is 8.4Gb
Initialization took 33 seconds
Ready for connections!
Reading CustomSettings.config from TEST-Container
Creating Desktop Shortcuts for TEST-Container
Publishing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\c704782f-9769-4ba1-9507-24afa9272e95\Microsoft_Test Runner.app
Synchronizing Test Runner on tenant default
Installing Test Runner on tenant default
App Microsoft_Test Runner.app successfully published
Publishing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\558fa19d-8255-4f85-8fd5-648c60882111\Microsoft_Any.app
Synchronizing Any on tenant default
Installing Any on tenant default
App Microsoft_Any.app successfully published
Publishing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\163af151-8899-425a-acfc-cebab0b87d1b\Microsoft_Library Assert.app
Synchronizing Library Assert on tenant default
Installing Library Assert on tenant default
App Microsoft_Library Assert.app successfully published
Publishing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\54029c5f-e6bd-4cb6-8375-2eedd5277233\Microsoft_Library Variable Storage.app
Synchronizing Library Variable Storage on tenant default
Installing Library Variable Storage on tenant default
App Microsoft_Library Variable Storage.app successfully published
Publishing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\94fb5ad5-7824-46e3-bc9e-984b0aa6a097\Microsoft_System Application Test Library.app
Synchronizing System Application Test Library on tenant default
Installing System Application Test Library on tenant default
App Microsoft_System Application Test Library.app successfully published
Publishing C:\ProgramData\BcContainerHelper\Extensions\TEST-Container\4d7a55aa-6093-453c-8fc0-2da91193497e\Microsoft_Tests-TestLibraries.app
Synchronizing Tests-TestLibraries on tenant default
Installing Tests-TestLibraries on tenant default
App Microsoft_Tests-TestLibraries.app successfully published
TestToolkit successfully imported
Container TEST-Container successfully created
Use:
Get-BcContainerEventLog -containerName TEST-Container to retrieve a snapshot of the event log from the container
Get-BcContainerDebugInfo -containerName TEST-Container to get debug information about the container
Enter-BcContainer -containerName TEST-Container to open a PowerShell prompt inside the container
Remove-BcContainer -containerName TEST-Container to remove the container again
docker logs TEST-Container to retrieve information about URL's again
freddydk commented 3 years ago

You are using the onprem container - isn't the package you are trying to apply already part of the demo data?

fridrichovsky commented 3 years ago

Hello, OnPrem contains demo data it is true.

I have this package only W1.ENU.EXTENDED | Microsoft Dynamics 365 Business Central | 1033 | NAV17.5

After function is run I have these packages W1.ENU.EXTENDED | Microsoft Dynamics 365 Business Central | 1033 | NAV17.5 NAV17.5.W1.ENU.EVALU | NAV17.5.W1.ENU.EVALU | 0 |

Packate NAV17.5.W1.ENU.EVALU is created as header only without content and table/fields configuration.

freddydk commented 3 years ago

Ok, I must admit that I don't know a lot about configuration packages. What happens if you do the steps manually? can you actually apply the config package to the existing demo data?

fridrichovsky commented 3 years ago

Hello, I can import package manually (with many questions :-) from application). I tried use api directly and I get error also with error detail. Please add "importError" and "applyError" to your error messages it helps with investigation where problem is.

Rapidstart have problem during import so it is not problem with applying. Import returns result bellow. Where is error message with different package codes. I found where problem is. Your function create rapidstart package with code "NAV17.5.W1.ENU.EVALU" (its from file name), but API requires this code "W1.ENU.EVALUATION". When I called API functions with "W1.ENU.EVALUATION" everything worked.

I don't know if it is possible read package code from RapidStart package file directly.

{
    "@odata.context": "http://172.26.66.235:7048/BC/api/microsoft/automation/v1.0/$metadata#companies(53103c6b-2a78-eb11-bb8a-00155df3a615)/configurationPackages/$entity",
    "@odata.etag": "W/\"JzQ0O045bHVHbng1OVB3ZFM4Mi9MU2FoVktvaWk5dlFOOC8zaGZTeVNweklqcUE9MTswMDsn\"",
    "code": "NAV17.5.W1.ENU.EVALU",
    "packageName": "NAV17.5.W1.ENU.EVALU",
    "languageId": 0,
    "productVersion": "",
    "processingOrder": 0,
    "excludeConfigurationTables": false,
    "numberOfTables": 0,
    "numberOfRecords": 0,
    "numberOfErrors": 0,
    "importStatus": "Error",
    "importError": "The package code specified on the configuration package must be the same as the package name in the imported package.",
    "applyStatus": "No",
    "applyError": ""
}
fridrichovsky commented 3 years ago

Hello Freddy, please can you change mentioned errors?

If you don't mind I tried to find a solution by loading the package code. Because the package is essentially a gzip file, I tried to load it and get the necessary information from the file. The function is made that it reads only the necessary info and skips the rest of the file.

Function Get-PackageInfoFromRapidStartFile{
    Param(
        $infile
        )
    # RapidStartPackage is gzip file
    $input = New-Object System.IO.FileStream $inFile, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
    $gzipStream = New-Object System.IO.Compression.GzipStream $input, ([IO.Compression.CompressionMode]::Decompress)
    $buffer = New-Object byte[](1024)
    $packageInfo = $null
    while($true){
        $read = $gzipstream.Read($buffer, 0, 1024)
        if ($read -le 0){break}
        $readText = [System.Text.Encoding]::Unicode.GetString($buffer)
        $readText.Split([Environment]::NewLine) | ForEach-Object {
            if ($_.IndexOf('DataList') -ne -1 ) {
                [xml]$package = ($_ + '</DataList>')
                $package.'DataList'
                break
            }
        }
    }
    $gzipStream.Close()
    $input.Close()
    $packageInfo
}

Get-PackageInfoFromRapidStartFile "C:\MyRapidFile.rapidstart"

RESULT:
ExcludeConfigTables : 1
LanguageID          : 1033
ProductVersion      : TSTW114.00.00
PackageName         : TEST Setup
Code                : TEST_SETUP
freddydk commented 3 years ago

Sorry for the late response I can see that this is a duplicate of #1710, which was resolved by adding a packageId parameter. If not specified, packageId is calculated based on the filename as earlier.

I will add the additional info on the errors (importError and applyError)

freddydk commented 3 years ago

Shipped in 2.0.13