microsoft / navcontainerhelper

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

Publish-NewApplicationToBCContainer; (use saveData); error: Unprocessable Entity #634

Closed finn777 closed 5 years ago

finn777 commented 5 years ago

Publish-NewApplicationToBCContainer; (use saveData); error: Unprocessable Entity

I used Windows 10

New-BCContainer  -accept_eula:$accept_eula `
                 -containername $containername `
                 -alwaysPull `
                 -Credential $credential `
                 -usessl:$false `
                 -updateHosts `
                 -licenseFile $licenseFile `
                 -assignPremiumPlan `
                 -shortcuts Desktop `
                 -imageName $navdockerimage `
                 -auth Windows `
                 -includeAL `
                 -useBestContainerOS
Setup-NavContainerTestUsers -containerName $containername -password $credential.Password

$alProjectFolder = "C:\ProgramData\NavContainerHelper\AL\BaseApp"
Create-AlProjectFolderFromBCContainer -containerName $containername `
                                      -alProjectFolder $alProjectFolder `
                      -useBaseAppProperties `
                      -useBaseLine

add dummy modification via VS Code and run Package

Publish-NewApplicationToBCContainer -appFile "D:\Microsoft_Base Application_15.0.36145.1.app" -containerName $containerName -saveData

result:

PS C:\WINDOWS\system32> Publish-NewApplicationToBCContainer -appFile "D:\Microsoft_Base Application_15.0.36145.1.app" -containerName $containerName -saveData
Publishing _Microsoft_Base Application_15.0.36145.1.app to http://172.17.89.89:7049/BC/dev/apps?SchemaUpdateMode=synchronize&tenant=default
Status Code 422 : Unprocessable Entity
At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.6.4.3\AppHandling\Publish-NavContainerApp.ps1:191 char:17
+ ...             throw "Status Code $($result.StatusCode) : $($result.Reas ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Status Code 422 : Unprocessable Entity:String) [], RuntimeException
    + FullyQualifiedErrorId : Status Code 422 : Unprocessable Entity
NAVspecialist commented 5 years ago

Does the app-file exist?

finn777 commented 5 years ago

app-file exist? - yes

freddydk commented 5 years ago

Unprocessible entity is 9 out of 10 times lack of memory. If you get the event log from the container you will whether there are any clues there, Also, you should include the full output of your new-navcontainer in issues here, please use the small 'insert code' button in the toolbar to format commands and output as code. and include the full script.

finn777 commented 5 years ago

just re-test it, fresh image, VS Code App updated, the error still the same

PS C:\WINDOWS\system32> $accept_eula = $true
$containername = 'PREVIEW-BASE'
$navdockerimage = 'bcinsider.azurecr.io/bcsandbox-master:base-ltsc2019'
$credential = get-credential -UserName $env:USERNAME -Message "Using Windows Authentication. Please enter your Windows credentials."
$licenseFile = "D:\_DEVDOCKER\build.flf"

New-BCContainer  -accept_eula:$accept_eula `
                 -containername $containername `
                 -alwaysPull `
                 -Credential $credential `
                 -usessl:$false `
                 -updateHosts `
                 -licenseFile $licenseFile `
                 -assignPremiumPlan `
                 -shortcuts Desktop `
                 -imageName $navdockerimage `
                 -auth Windows `
                 -includeAL `
                 -useBestContainerOS
Setup-NavContainerTestUsers -containerName $containername -password $credential.Password
NavContainerHelper is version 0.6.4.3
Host is Microsoft Windows 10 Enterprise - 1903
Docker Client Version is 19.03.2
Docker Server Version is 19.03.2
Pulling image bcinsider.azurecr.io/bcsandbox-master:base-ltsc2019
base-ltsc2019: Pulling from bcsandbox-master
Using image bcinsider.azurecr.io/bcsandbox-master:base-ltsc2019
Removing container PREVIEW-BASE
Removing PREVIEW-BASE from hosts
Removing C:\ProgramData\NavContainerHelper\Extensions\PREVIEW-BASE
Creating Container PREVIEW-BASE
Version: 15.0.36545.0-W1
Style: sandbox
Platform: 15.0.36510.0
Generic Tag: 0.0.9.95
Container OS Version: 10.0.17763.737 (ltsc2019)
Host OS Version: 10.0.18362.356 (1903)
A better Generic Container OS exists for your host (1903)
Using generic image mcr.microsoft.com/dynamicsnav:generic-1903
Pulling image mcr.microsoft.com/dynamicsnav:generic-1903
generic-1903: Pulling from dynamicsnav
Generic Container OS Version: 10.0.18362.356 (1903)
Generic Tag of better generic: 0.0.9.95
Using locale en-US
Using process isolation
Disabling the standard eventlog dump to container log every 2 seconds (use -dumpEventLog to enable)
Using license file D:\_DEVDOCKER\build.flf
Files in C:\ProgramData\NavContainerHelper\Extensions\PREVIEW-BASE\my:
- AdditionalOutput.ps1
- license.flf
- MainLoop.ps1
- SetupNavUsers.ps1
- updatehosts.ps1
Creating container PREVIEW-BASE from image mcr.microsoft.com/dynamicsnav:generic-1903
f07daf2192714722a066ef1b8e810e011a65d156a0727bdc3a3840bf78b38d65
Waiting for container PREVIEW-BASE to be ready
Installing Business Central
Installing Url Rewrite
Installing OpenXML
Installing DotNetCore
Starting Local SQL Server
Starting Internet Information Server
Copying Service Tier Files
Copying Web Client Files
Copying Client Files
Copying ModernDev Files
Copying PowerShell Scripts
Copying ConfigurationPackages
Copying Test Assemblies
Copying Applications
Copying ReportBuilder
Changing Database Server Collation to Latin1_General_100_CS_AS
SQL Server 2017 transmits information about your installation experience, as well as other usage and performance data, to Microsoft to help improve the product. To learn more about SQL Server 2017 data processing and
 privacy controls, please see the Privacy Statement.
Copying Cronus database
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
Installation took 201 seconds
Installation complete
Initializing...
Starting Container
Hostname is PREVIEW-BASE
PublicDnsName is PREVIEW-BASE
Using Windows Authentication
Modifying Service Tier Config File with Instance Specific Settings
Restarting 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
Creating Windows user alexef
Setting SA Password and enabling SA
Creating SUPER user
Assign Premium plan for PREVIEW-BASE\ALEXEF
Container IP Address: 172.17.87.154
Container Hostname  : PREVIEW-BASE
Container Dns Name  : PREVIEW-BASE
Web Client          : http://PREVIEW-BASE/BC/
Dev. Server         : http://PREVIEW-BASE
Dev. ServerInstance : BC

Files:
http://PREVIEW-BASE:8080/al-4.0.176004.vsix

Initialization took 43 seconds
Ready for connections!
Reading CustomSettings.config from PREVIEW-BASE
Creating Desktop Shortcuts for PREVIEW-BASE
Creating .net Assembly Reference Folder for VS Code
Copying DLLs from C:\Windows\assembly to assemblyProbingPath
Copying DLLs from C:\Program Files\Microsoft Dynamics NAV\150\Service to assemblyProbingPath
Copying DLLs from C:\Program Files (x86)\Microsoft Dynamics NAV\150\RoleTailored Client to assemblyProbingPath
Copying DLLs from C:\Test Assemblies\Mock Assemblies to assemblyProbingPath
Copying DLLs from C:\Program Files (x86)\Open XML SDK to assemblyProbingPath
Container PREVIEW-BASE successfully created
Downloading C:\Users\alexef\AppData\Local\Temp\CreateTestUsers.app
Publishing C:\ProgramData\NavContainerHelper\Extensions\PREVIEW-BASE\_CreateTestUsers.app
Synchronizing CreateTestUsers on tenant default
Installing CreateTestUsers on tenant default
App successfully published
Invoke GET on http://172.17.87.154:7048/BC/api/beta/companies?$filter=name%20eq%20%27CRONUS%20International%20Ltd.%27&tenant=default
Invoke POST on http://172.17.87.154:7048/BC/api/Microsoft/Setup/beta/companies(17e25f50-1ae3-4c19-9d63-f42886b538d7)/testUsers?tenant=default
Uninstalling CreateTestUsers from tenant default
Unpublishing CreateTestUsers
App successfully unpublished

PS C:\WINDOWS\system32> docker images
REPOSITORY                                 TAG                        IMAGE ID            CREATED             SIZE
bcinsider.azurecr.io/bcsandbox-master      base-ltsc2019              8be8fc6308f2        24 minutes ago      8.66GB
bcinsider.azurecr.io/bcsandbox-master      <none>                     345fd4e166a6        12 days ago         8.66GB
mcr.microsoft.com/dynamicsnav              generic-1903               7dded545b001        13 days ago         6.58GB
mcr.microsoft.com/businesscentral/onprem   14.5.35970.0-w1-ltsc2019   809549bc39af        13 days ago         8.82GB

PS C:\WINDOWS\system32> $alProjectFolder = "C:\ProgramData\NavContainerHelper\AL\BaseApp"
Create-AlProjectFolderFromBCContainer -containerName $containername `
                                      -alProjectFolder $alProjectFolder `
                      -useBaseAppProperties `
                      -useBaseLine

Copying Al Source Files from C:\ProgramData\NavContainerHelper\Extensions\Original-15.0.36545.0-W1-al\* to C:\ProgramData\NavContainerHelper\AL\BaseApp
Al Project Folder Created

PS C:\WINDOWS\system32> install-module navcontainerhelper -force

PS C:\WINDOWS\system32> Get-InstalledModule -Name navcontainerhelper -AllVersions

Version    Name                                Repository           Description                                                                                                                                        
-------    ----                                ----------           -----------                                                                                                                                        
0.6.4.3    navcontainerhelper                  PSGallery            PowerShell module                                                                                                                                  

PS C:\WINDOWS\system32> Publish-NewApplicationToBCContainer -appFile "D:\Microsoft_Base Application_15.0.36545.1.app" -containerName $containerName -saveData
Publishing _Microsoft_Base Application_15.0.36545.1.app to http://172.17.87.154:7049/BC/dev/apps?SchemaUpdateMode=synchronize&tenant=default
Status Code 422 : Unprocessable Entity
At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.6.4.3\AppHandling\Publish-NavContainerApp.ps1:191 char:17
+ ...             throw "Status Code $($result.StatusCode) : $($result.Reas ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Status Code 422 : Unprocessable Entity:String) [], RuntimeException
    + FullyQualifiedErrorId : Status Code 422 : Unprocessable Entity
finn777 commented 5 years ago

Web from re-test; after an error I see in Web client: image

If install via Web Client (.1) version then success image The data is saved... interesting..

freddydk commented 5 years ago

You need to uninstall and unpublish the old base application. That is done by using -useCleanDatabase as described here: https://freddysblog.com/2019/07/31/preview-of-dynamics-365-business-central-2019-release-wave-2/ in the latest containerhelper you can also use -useNewDatabase (which will spin up a new database before publishing).

finn777 commented 5 years ago

event log from re-test

PS C:\WINDOWS\system32> Publish-NewApplicationToBCContainer -appFile "D:\Microsoft_Base Application_15.0.36545.1.app" -containerName $containerName -saveData
Publishing _Microsoft_Base Application_15.0.36545.1.app to http://172.17.80.42:7049/BC/dev/apps?SchemaUpdateMode=synchronize&tenant=default
Status Code 422 : Unprocessable Entity
At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.6.4.3\AppHandling\Publish-NavContainerApp.ps1:191 char:17
+ ...             throw "Status Code $($result.StatusCode) : $($result.Reas ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Status Code 422 : Unprocessable Entity:String) [], RuntimeException
    + FullyQualifiedErrorId : Status Code 422 : Unprocessable Entity
PS C:\WINDOWS\system32> Get-BCContainerEventLog PREVIEW-BASE
Getting event log for PREVIEW-BASE

image

error from Event log: Multiple published extensions match the specified parameter values. You must specify more information to indicate which extension to use. … StatusCode:422

freddydk commented 5 years ago

Exactly - you didn't remove it.

finn777 commented 5 years ago

-useCleanDatabase... hmmm my main goal save the demo data... Is it possible with this parameter?

freddydk commented 5 years ago

Which -useCleanDatabase with -saveData does -useNewDatabase obviously doesn't

freddydk commented 5 years ago

Read more here: https://freddysblog.com/2019/09/19/publishing-a-new-base-application/

freddydk commented 5 years ago

I guess you need to start from scratch with a new container as you managed to get two base apps installed - not sure how

finn777 commented 5 years ago

may be this story 309253 (MS internal ID), I've created .app file via VS Code

freddydk commented 5 years ago

That one is PTE's in online tenants, nothing to do with this. If you follow the blog-post step by step end 2 end - then it should work (I have run this script multiple times) - not sure what you do different and it is very hard to grab your script and do a repro when the script is not in code view, like this:

$accept_eula = $true
$containername = 'PREVIEW-BASE'
$navdockerimage = 'bcinsider.azurecr.io/bcsandbox-master:base-ltsc2019'
#$credential = get-credential -UserName $env:USERNAME -Message "Using Windows Authentication. Please enter your Windows credentials."
$credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String 'P@ssword1' -AsPlainText -Force)
$licenseFile = "C:\temp\license.flf"

New-BCContainer -accept_eula:$accept_eula -containername $containername `
    -alwaysPull -Credential $credential `
    -usessl:$false -updateHosts `
    -licenseFile $licenseFile -assignPremiumPlan `
    -shortcuts Desktop -imageName $navdockerimage `
    -auth userPassword -includeAL `
    -useBestContainerOS

Setup-NavContainerTestUsers -containerName $containername -password $credential.Password

$alProjectFolder = "C:\ProgramData\NavContainerHelper\AL\BaseApp"
Create-AlProjectFolderFromBCContainer -containerName $containername -alProjectFolder $alProjectFolder `
    -useBaseAppProperties `
    -useBaseLine

$appFile = Compile-AppInBCContainer -containerName $containerName -credential $credential -appProjectFolder $alProjectFolder

Publish-NewApplicationToBCContainer -appFile $appFile -containerName $containerName -saveData -credential $credential -useCleanDatabase

This script works - the question is just what you do different. But you should be able to find out - if this works.

finn777 commented 5 years ago

continue the test.. (I think key step - "modify app.json, increase version: 15.0.36545.1", without it no any error: Unprocessable Entity )

# step 1
# just add to Freddys working script -Credential $credential to Setup-NavContainerTestUsers and set right path to the license

$accept_eula = $true
$containername = 'PREVIEW-BASE'
$navdockerimage = 'bcinsider.azurecr.io/bcsandbox-master:base-ltsc2019'
#$credential = get-credential -UserName $env:USERNAME -Message "Using Windows Authentication. Please enter your Windows credentials."
$credential = New-Object pscredential 'admin', (ConvertTo-SecureString -String 'P@ssword1' -AsPlainText -Force)
$licenseFile = "D:\_DEVDOCKER\build.flf"

New-BCContainer -accept_eula:$accept_eula -containername $containername `
    -alwaysPull -Credential $credential `
    -usessl:$false -updateHosts `
    -licenseFile $licenseFile -assignPremiumPlan `
    -shortcuts Desktop -imageName $navdockerimage `
    -auth userPassword -includeAL `
    -useBestContainerOS

Setup-NavContainerTestUsers -containerName $containername -password $credential.Password -Credential $credential

$alProjectFolder = "C:\ProgramData\NavContainerHelper\AL\BaseApp"
Create-AlProjectFolderFromBCContainer -containerName $containername -alProjectFolder $alProjectFolder `
    -useBaseAppProperties `
    -useBaseLine
# step 2
# modify app.json, increase version: 15.0.36545.1 

image

#step 3
$appFile = Compile-AppInBCContainer -containerName $containerName -credential $credential -appProjectFolder $alProjectFolder
Publish-NewApplicationToBCContainer -appFile $appFile -containerName $containerName -saveData -credential $credential -useCleanDatabase

result:

Compilation ended at '11:50:12.35'.

C:\ProgramData\NavContainerHelper\AL\BaseApp\output\Microsoft_Base Application_15.0.36545.1.app successfully created in 97 seconds
Uninstalling Sales and Inventory Forecast
Uninstalling _Exclude_ClientAddIns_
Uninstalling Essential Business Headlines
Uninstalling Send remittance advice by email
Uninstalling _Exclude_APIV1_
Uninstalling PayPal Payments Standard
Uninstalling Business Central Intelligent Cloud
Uninstalling Intelligent Cloud Base
Uninstalling Base Application
Unpublishing Sales and Inventory Forecast
Unpublishing _Exclude_ClientAddIns_
Unpublishing Essential Business Headlines
Unpublishing Send remittance advice by email
Unpublishing _Exclude_APIV1_
Unpublishing PayPal Payments Standard
Unpublishing Business Central Intelligent Cloud
Unpublishing Intelligent Cloud Base
Unpublishing Base Application
Publishing Microsoft_Base Application_15.0.36545.1.app to http://172.17.105.22:7049/BC/dev/apps?SchemaUpdateMode=synchronize&tenant=default
Status Code 422 : Unprocessable Entity
At C:\Program Files\WindowsPowerShell\Modules\navcontainerhelper\0.6.4.3\AppHandling\Publish-NavContainerApp.ps1:191 char:17
+ ...             throw "Status Code $($result.StatusCode) : $($result.Reas ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Status Code 422 : Unprocessable Entity:String) [], RuntimeException
    + FullyQualifiedErrorId : Status Code 422 : Unprocessable Entity

Get-BCContainerEventLog PREVIEW-BASE

image

error from Event log: Cannot install the extension Base Application by Microsoft 15.0.36545.1 for the tenant default because an earlier version was already installed. Run Start-NAVAppDataUpgrade to upgrade the extension.

continue..

#step 4
Start-NavContainerAppDataUpgrade -appName "Base Application" -appVersion 15.0.36545.1 -containerName $containerName

Success... image

freddydk commented 5 years ago

Thanks for the detailed description - very very nice, and yes, of course we need a upgrade parameter on the publish-newapp (to run the upgrade during the publish/install)

The upgrade piece is next on my schedule of things to look at using containers, thanks

finn777 commented 5 years ago

Adopt my intial script. Now I see all extensions... The issue can be closed from my side.

# step 1
$accept_eula = $true
$containername = 'PREVIEW-BASE'
$navdockerimage = 'bcinsider.azurecr.io/bcsandbox-master:base-ltsc2019'
$credential = get-credential -UserName $env:USERNAME -Message "Using Windows Authentication. Please enter your Windows credentials."
$licenseFile = "D:\_DEVDOCKER\build.flf"

New-BCContainer  -accept_eula:$accept_eula `
                 -containername $containername `
                 -alwaysPull `
                 -Credential $credential `
                 -usessl:$false `
                 -updateHosts `
                 -licenseFile $licenseFile `
                 -assignPremiumPlan `
                 -shortcuts Desktop `
                 -imageName $navdockerimage `
                 -auth Windows `
                 -includeAL `
                 -useBestContainerOS
Setup-NavContainerTestUsers -containerName $containername -password $credential.Password

$alProjectFolder = "C:\ProgramData\NavContainerHelper\AL\BaseApp"
Create-AlProjectFolderFromBCContainer -containerName $containername `
                                      -alProjectFolder $alProjectFolder `
                      -useBaseAppProperties `
                      -useBaseLine

"# step 2 VS Code; AL:Download symbols; modify ItemList (remove description column); modify app.json, increase version: 15.0.36545.1; AL:Package; copy .app file to D:\"

# step 3
Publish-NewApplicationToBCContainer -appFile "D:\Microsoft_Base Application_15.0.36545.1.app" -containerName $containerName -saveData

"# after step 3 error: Status Code 422 : Unprocessable Entity; Get-BCContainerEventLog PREVIEW-BASE show: Multiple published extensions match the specified parameter values. You must specify more information to indicate which extension to use."

# step 4
Sync-BCContainerApp -appName "Base Application" -appVersion 15.0.36545.1 -containerName $containerName
# step 5
Start-BCContainerAppDataUpgrade -appName "Base Application" -appVersion 15.0.36545.1 -containerName $containerName

image

finn777 commented 5 years ago

add community post: https://community.dynamics.com/business/f/dynamics-365-business-central-forum/367663/info-how-customizing-the-base-application-with-save-data

freddydk commented 5 years ago

Thanks