microsoft / navcontainerhelper

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

Copy-FileToBCContainer: error if hostHelperFolder is changed in BcContainerHelper.config.json #1671

Closed ti-jalopez closed 3 years ago

ti-jalopez commented 3 years ago

Describe the issue BcContainerHelper version 2.0.3 I've changed BcContainerHelper.config.json to change hostHelperFolder to "C:\ContainerHelper" instead of default value "c:\ProgramData\BcContainerHelper".

When I use Copy-FileToBCContainer an error occurs: "Access to the path 'C:\ProgramData\BcContainerHelper\662029ee-c613-4bc2-b4a1-82dc8e692388' is denied. at , : line 9".

I think the problem is "Copy-FileToBCContainer" uses the default hostHelperFolder instead of the new value changed.

This script ran successfully with NavContainerHelper and default hostHelperFolder in my old laptop.

Scripts used to create container and cause the issue

$containerName = 'BC17LATEST'
$assemblyProbingPath = "C:\Program Files\Microsoft Dynamics NAV\170\Service\Add-Ins\"  
$dllFolders = @("C:\temp\add-ins\")

foreach ($dllFolder in $dllFolders) {
    Get-ChildItem -Path $dllFolder -Filter "*.*" -Recurse  | ForEach-Object {
        Copy-FileToBCContainer -containerName $containerName -localPath $_.FullName -containerPath (Join-Path $assemblyProbingPath $_)
    }
}

The source folder only contains a subfolder and a file. I think it run fine before change my laptop and install bccontainerhelper instead of navcontainerhelper, and I change the default hostHelperFolder

C:\temp>dir /s
 El volumen de la unidad C es OS
 El número de serie del volumen es: C486-3DEB

 Directorio de C:\temp

02/02/2021  08:57    <DIR>          .
02/02/2021  08:57    <DIR>          ..
02/02/2021  08:58    <DIR>          _Datanet
               0 archivos              0 bytes

 Directorio de C:\temp\_Datanet

02/02/2021  08:58    <DIR>          .
02/02/2021  08:58    <DIR>          ..
17/10/2018  09:29             4.608 DataNet_Zip.dll
               1 archivos          4.608 bytes

     Total de archivos en la lista:
               1 archivos          4.608 bytes

Full output of scripts

PS C:\Windows\system32>     foreach ($dllFolder in $dllFolders) {
        Get-ChildItem -Path $dllFolder -Filter "*.*" -Recurse  | ForEach-Object {
            Copy-FileToBCContainer -containerName $containerName -localPath $_.FullName -containerPath (Join-Path $assemblyProbingPath $_)
        }
    }

Copy C:\temp\_Datanet to container BC17LATEST (C:\Program Files\Microsoft Dynamics NAV\170\Service\Add-Ins\_Datanet\_Datanet)
Access to the path 'C:\ProgramData\BcContainerHelper\36b99af9-f7b2-4568-b5bd-9829007ae84e' is denied.
at <ScriptBlock>, <No file>: line 9
en Invoke-ScriptInBcContainer, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.3\ContainerHandling\Invoke-ScriptInNav
Container.ps1: línea 44
en Copy-FileToBcContainer<Process>, C:\Program Files\WindowsPowerShell\Modules\BcContainerHelper\2.0.3\Misc\Copy-FileToNavContainer.ps
1: línea 35
en <ScriptBlock>, <sin archivo>: línea 3
en <ScriptBlock>, <sin archivo>: línea 2
Get-ChildItem : Access to the path 'C:\ProgramData\BcContainerHelper\36b99af9-f7b2-4568-b5bd-9829007ae84e' is denied.
En línea: 2 Carácter: 9
+         Get-ChildItem -Path $dllFolder -Filter "*.*" -Recurse  | ForE ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Access to the p...84e' is denied.:String) [Get-ChildItem], RuntimeException
    + FullyQualifiedErrorId : Access to the path 'C:\ProgramData\BcContainerHelper\36b99af9-f7b2-4568-b5bd-9829007ae84e' is denied., 
   Microsoft.PowerShell.Commands.GetChildItemCommand

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

Additional context

freddydk commented 3 years ago

Very strange, this bug should be fixed here: https://github.com/microsoft/navcontainerhelper/pull/1171 How do you configure the HostHelperFolder? Could you share your bcContainerHelper.config.json?

Thanks

freddydk commented 3 years ago

Ok, so your hostHelperFolder is not set. Also you are trying to copy the folder and not the filename as it looks (Copy C:\temp_Datanet to container BC17LATEST (C:\Program Files\Microsoft Dynamics NAV\170\Service\Add-Ins_Datanet_Datanet) )

freddydk commented 3 years ago

In order to set the hosthelperfolder, it must be specified in c:\programdata\bccontainerhelper\bccontainerhelper.config.json - that file does not move and hosthelperfolder cannot be set at runtime. https://freddysblog.com/2020/10/10/bccontainerhelper-configuration/

ti-jalopez commented 3 years ago

This is the content of C:\ProgramData\BcContainerHelper\BcContainerHelper.config.json The hostHelperFolder is setup ok, because when I create containers the extension subforders are create in C:\ContainerHelper\Extensions

{
    "use7zipIfAvailable":  true,
    "digestAlgorithm":  "SHA256",
    "mapCountryCode":  {
                           "ae":  "w1",
                           "br":  "w1",
                           "co":  "w1",
                           "ee":  "w1",
                           "fo":  "dk",
                           "gl":  "dk",
                           "hk":  "w1",
                           "hr":  "w1",
                           "hu":  "w1",
                           "id":  "w1",
                           "ie":  "w1",
                           "jp":  "w1",
                           "kr":  "w1",
                           "lt":  "w1",
                           "lv":  "w1",
                           "my":  "w1",
                           "pe":  "w1",
                           "ph":  "w1",
                           "pl":  "w1",
                           "rs":  "w1",
                           "ro":  "w1",
                           "sg":  "w1",
                           "si":  "w1",
                           "th":  "w1",
                           "tw":  "w1",
                           "vn":  "w1",
                           "za":  "w1"
                       },
    "hostHelperFolder":  "C:\\ContainerHelper",
    "timeStampServer":  "http://timestamp.digicert.com",
    "bcartifactsCacheFolder":  "c:\\bcartifacts.cache",
    "containerHelperFolder":  "C:\\ProgramData\\BcContainerHelper",
    "genericImageName":  "mcr.microsoft.com/businesscentral:{0}",
    "sandboxContainersAreMultitenantByDefault":  true,
    "defaultContainerName":  "bcserver",
    "usePsSession":  true,
    "defaultNewContainerParameters":  {                                    }
}

image

ti-jalopez commented 3 years ago

Ok, so your hostHelperFolder is not set. Also you are trying to copy the folder and not the filename as it looks (Copy C:\temp_Datanet to container BC17LATEST (C:\Program Files\Microsoft Dynamics NAV\170\Service\Add-Ins_Datanet_Datanet) )

This is true, _Datanet is a folder, but I think somethink is wrong, because the folder in the error message 'C:\ProgramData\BcContainerHelper' should be "C:\ContainerHelper". I tested it without folders and it run fine, so maybe only have a strange behavior about the folder name. I think you can close this case, since I do your proposal in https://github.com/microsoft/navcontainerhelper/issues/1673#issuecomment-771475675 to replace Copy-FileToBCContainer by a shared folder for add-ins.

Thanks 👍

freddydk commented 3 years ago

The reason for this is that the error comes from inside the container and since your containerHelperFolder is still c:\programdata\bccontainerhelper, then you get this error. Mystery solved.

ti-jalopez commented 3 years ago

Ok, I understand, the folder "c:\programdata\bccontainerhelper" is the name inside the container, not the local folder in containerHelperFolder on host machine

👍