This commit is contained in:
Freddy Kristiansen 2021-11-12 18:12:35 +01:00
Родитель a52deed801
Коммит d5373b74d9
22 изменённых файлов: 82 добавлений и 41 удалений

Просмотреть файл

@ -44,7 +44,7 @@ function Run-AlCops {
$apps,
$affixes,
$supportedCountries,
$appPackagesFolder = (Join-Path $bcContainerHelperConfig.hostHelperFolder ([Guid]::NewGuid().ToString())),
$appPackagesFolder = (Join-Path $hosthelperfolder ([Guid]::NewGuid().ToString())),
[switch] $enableAppSourceCop,
[switch] $enableCodeCop,
[switch] $enableUICop,
@ -75,7 +75,7 @@ try {
throw "You cannot run AppSourceCop and PerTenantExtensionCop at the same time"
}
$appsFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder ([Guid]::NewGuid().ToString())
$appsFolder = Join-Path $hosthelperfolder ([Guid]::NewGuid().ToString())
New-Item -Path $appsFolder -ItemType Directory | Out-Null
$apps = Sort-AppFilesByDependencies -containerName $containerName -appFiles @(CopyAppFilesToFolder -appFiles $apps -folder $appsFolder) -WarningAction SilentlyContinue
@ -115,7 +115,7 @@ try {
$apps | % {
$appFile = $_
$tmpFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder ([Guid]::NewGuid().ToString())
$tmpFolder = Join-Path $hosthelperfolder ([Guid]::NewGuid().ToString())
try {
$artifactUrl = Get-BcContainerArtifactUrl -containerName $containerName

Просмотреть файл

@ -338,7 +338,7 @@ $version = [System.Version]::new($currentArtifactUrl.Split('/')[4])
$currentVersion = "$($version.Major).$($version.Minor)"
$validateVersion = "17.0"
$tmpAppsFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder ([Guid]::NewGuid().ToString())
$tmpAppsFolder = Join-Path $hosthelperfolder ([Guid]::NewGuid().ToString())
@(CopyAppFilesToFolder -appFiles @($installApps+$apps) -folder $tmpAppsFolder) | % {
$appFile = $_
$version = GetApplicationDependency -appFile $appFile -minVersion $validateVersion

Просмотреть файл

@ -57,7 +57,7 @@ try {
if (-not (Get-BcContainerAppInfo -containerName $containerName -credential $credential | Where-Object { $_.appId -eq $appJson.id })) {
Write-Host "Adding BCPTLogEntryAPI.app to extend existing Performance Toolkit with BCPTLogEntry API page"
Write-Host "Using Object Id $($bcContainerHelperConfig.ObjectIdForInternalUse) (set `$bcContainerHelperConfig.ObjectIdForInternalUse to change)"
$appExtFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\$([GUID]::NewGuid().ToString())"
$appExtFolder = Join-Path $hosthelperfolder "Extensions\$containerName\$([GUID]::NewGuid().ToString())"
New-Item $appExtFolder -ItemType Directory | Out-Null
$appJson.idRanges[0].from = $bcContainerHelperConfig.ObjectIdForInternalUse
$appJson.idRanges[0].to = $bcContainerHelperConfig.ObjectIdForInternalUse
@ -133,7 +133,7 @@ try {
Copy-Item -path "C:\Applications\testframework\TestRunner" -Destination "c:\run\my" -Recurse -Force
}
$location = Get-Location
Set-Location (Join-Path $bcContainerHelperConfig.hostHelperFolder "extensions\$containerName\my\TestRunner")
Set-Location (Join-Path $hosthelperfolder "extensions\$containerName\my\TestRunner")
$auth = $config.ClientServicesCredentialType

Просмотреть файл

@ -44,7 +44,7 @@ try {
throw "The app ($appFile)needs to be in a folder, which is shared with the container $containerName"
}
# $ExtensionsFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions"
# $ExtensionsFolder = Join-Path $hosthelperfolder "Extensions"
# $sharedPfxFile = Join-Path $ExtensionsFolder "$containerName\my\certificate.pfx"
# $removeSharedPfxFile = $true
# if ($pfxFile -like "https://*" -or $pfxFile -like "http://*") {
@ -62,7 +62,7 @@ try {
# }
# }
$ExtensionsFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions"
$ExtensionsFolder = Join-Path $hosthelperfolder "Extensions"
$sharedPfxFile = Join-Path $ExtensionsFolder "$containerName\my\$([GUID]::NewGuid().ToString()).pfx"
$removeSharedPfxFile = $true
if ($pfxFile -like "https://*" -or $pfxFile -like "http://*") {

Просмотреть файл

@ -47,7 +47,7 @@ try {
}
$successFileName = ""
if ($async) {
$successFileName = Join-Path $bcContainerHelperConfig.hostHelperFolder "$($databasePrefix)databasescreated.txt"
$successFileName = Join-Path $hosthelperfolder "$($databasePrefix)databasescreated.txt"
if (Test-Path $successFileName) { Remove-Item $successFileName -Force }
}
Write-Host "Starting Database Restore job from $($artifactUrl.split('?')[0])"

Просмотреть файл

@ -1,12 +1,18 @@
param(
[switch] $Silent,
[switch] $ExportTelemetryFunctions,
[string[]] $bcContainerHelperConfigFile = @())
[string[]] $bcContainerHelperConfigFile = @(),
[switch] $useVolumes
)
Get-ChildItem -Path $PSScriptRoot -Recurse | % { Unblock-File -Path $_.FullName }
Remove-Module NavContainerHelper -ErrorAction Ignore
Remove-Module BcContainerHelper -ErrorAction Ignore
if ($useVolumes) {
Write-Host "USE VOLUMES1"
}
$modulePath = Join-Path $PSScriptRoot "BcContainerHelper.psm1"
Import-Module $modulePath -DisableNameChecking -ArgumentList $Silent, $ExportTelemetryFunctions, $bcContainerHelperConfigFile
Import-Module $modulePath -DisableNameChecking -ArgumentList $Silent, $ExportTelemetryFunctions, $bcContainerHelperConfigFile, $useVolumes

Просмотреть файл

@ -3,7 +3,8 @@
param(
[switch] $Silent,
[switch] $ExportTelemetryFunctions,
[string[]] $bcContainerHelperConfigFile = @()
[string[]] $bcContainerHelperConfigFile = @(),
[switch] $useVolumes
)
Set-StrictMode -Version 2.0
@ -16,6 +17,10 @@ if ([intptr]::Size -eq 4) {
throw "ContainerHelper cannot run in Windows PowerShell (x86), need 64bit mode"
}
if ($useVolumes) {
Write-Host "USE VOLUMES"
}
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdministrator = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
try {
@ -78,6 +83,12 @@ function Get-ContainerHelperConfig {
"ObjectIdForInternalUse" = 88123
}
if ($useVolumes) {
$bcContainerHelperConfig.bcartifactsCacheFolder = "bcartifacts.cache"
$bcContainerHelperConfig.hostHelperFolder = "hostHelperFolder"
$bcContainerHelperConfig.useVolumeForMyFolder = $true
}
if ($bcContainerHelperConfigFile -notcontains "C:\ProgramData\BcContainerHelper\BcContainerHelper.config.json") {
$bcContainerHelperConfigFile = @("C:\ProgramData\BcContainerHelper\BcContainerHelper.config.json")+$bcContainerHelperConfigFile
}

Просмотреть файл

@ -52,7 +52,7 @@ try {
throw "You can only upload, import and apply one config package at a time ($configPackage matches multiple files inside the container)"
return
}
$configPackage = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$containerName\$([System.IO.Path]::GetFileName($containerConfigPackage))"
$configPackage = Join-Path $hosthelperfolder "Extensions\$containerName\$([System.IO.Path]::GetFileName($containerConfigPackage))"
if (Test-Path $configPackage) {
Remove-Item $configPackage -Force
}

Просмотреть файл

@ -18,7 +18,7 @@ function Enter-BcContainer {
)
Process {
if ((Get-ContainerHelperConfig).usePsSession) {
if ($bcContainerHelperConfig.usePsSession) {
$session = Get-BcContainerSession $containerName -silent
Enter-PSSession -Session $session
Invoke-Command -Session $session -ScriptBlock {

Просмотреть файл

@ -40,7 +40,7 @@ try {
}
if ($caches.Contains('all') -or $caches.Contains('bcartifacts') -or $caches.Contains('sandboxartifacts')) {
$bcartifactsCacheFolder = (Get-ContainerHelperConfig).bcartifactsCacheFolder
$bcartifactsCacheFolder = $bcartifactsCacheFolder
$subfolder = "*"
if (!($caches.Contains('all') -or $caches.Contains('bcartifacts'))) {
$subfolder = "sandbox"
@ -123,7 +123,7 @@ try {
"artifactUrl=https://bcprivate.azureedge.net/",
"artifactUrl=https://bcpublicpreview.azureedge.net/" | % {
if ($artifactUrl -like "$($_)*") {
$cacheFolder = Join-Path $bcContainerHelperConfig.bcartifactsCacheFolder $artifactUrl.SubString($_.Length)
$cacheFolder = Join-Path $bcartifactsCacheFolder $artifactUrl.SubString($_.Length)
if (-not (Test-Path $cacheFolder)) {
Write-Host "$imageName was built on artifacts which was removed from the cache, removing image"
if (-not (DockerDo -command rmi -parameters @("--force") -imageName $imageID -ErrorAction SilentlyContinue)) {

Просмотреть файл

@ -34,10 +34,10 @@ try {
}
if ($filesOnly) {
$genericImageNameSetting = (Get-ContainerHelperConfig).genericImageNameFilesOnly
$genericImageNameSetting = $bcContainerHelperConfig.genericImageNameFilesOnly
}
else {
$genericImageNameSetting = (Get-ContainerHelperConfig).genericImageName
$genericImageNameSetting = $bcContainerHelperConfig.genericImageName
}
$repo = $genericImageNameSetting.Split(':')[0]
$tag = $genericImageNameSetting.Split(':')[1].Replace('{0}','*')

Просмотреть файл

@ -1269,8 +1269,18 @@ try {
throw "EnableSymbolLoading is no longer needed in Dynamics 365 Business Central 2019 wave 2 release (1910 / 15.x)"
}
$myFolder = Join-Path $containerFolder "my"
New-Item -Path $myFolder -ItemType Directory -ErrorAction Ignore | Out-Null
if ($bcContainerHelperConfig.UseVolumeForMyFolder) {
$myVolumeName = "$containerName-my"
if ($allVolumes | Where-Object { $_ -like "*|$myVolumeName" }) {
throw "Fatal error, volume $myVolumeName already exists"
}
docker volume create $myVolumeName
$myFolder = ((docker volume inspect $myVolumeName) | ConvertFrom-Json).MountPoint
}
else {
$myFolder = Join-Path $containerFolder "my"
New-Item -Path $myFolder -ItemType Directory -ErrorAction Ignore | Out-Null
}
if ($useTraefik) {
Write-Host "Adding special CheckHealth.ps1 to enable Traefik support"
@ -1400,7 +1410,6 @@ try {
$parameters += @( "--env licenseFile=""$containerLicenseFile""" )
}
$parameters += @(
"--name $containerName",
"--hostname $containerName",
@ -1411,7 +1420,7 @@ try {
"--env databaseServer=""$databaseServer""",
"--env databaseInstance=""$databaseInstance""",
(getVolumeMountParameter -volumes $allVolumes -hostPath $hostHelperFolder -containerPath $containerHelperFolder),
"--volume ""$($myFolder):C:\Run\my""",
(getVolumeMountParameter -volumes $allVolumes -hostPath $myFolder -containerPath "C:\Run\my"),
"--isolation $isolation",
"--restart $restart"
)

Просмотреть файл

@ -116,7 +116,7 @@ try {
$hostOsVersion = [System.Version]::Parse("$($os.Version).$UBR")
$hostOs = "Unknown/Insider build"
$bestGenericImageName = Get-BestGenericImageName -onlyMatchingBuilds -filesOnly:$filesOnly
$isServerHost = $os.ProductType -eq 3
$isServerHost = $os.ProductType -eq 3
if ("$baseImage" -eq "") {
if ("$bestGenericImageName" -eq "") {
@ -412,13 +412,13 @@ try {
}
Write-Host "Using $isolation isolation"
$downloadsPath = (Get-ContainerHelperConfig).bcartifactsCacheFolder
$downloadsPath = $bcartifactsCacheFolder
if (!(Test-Path $downloadsPath)) {
New-Item $downloadsPath -ItemType Directory | Out-Null
}
do {
$buildFolder = Join-Path (Get-ContainerHelperConfig).bcartifactsCacheFolder ([System.IO.Path]::GetRandomFileName())
$buildFolder = Join-Path $bcartifactsCacheFolder ([System.IO.Path]::GetRandomFileName())
}
until (New-Item $buildFolder -ItemType Directory -ErrorAction SilentlyContinue)

Просмотреть файл

@ -44,13 +44,27 @@ try {
$tenantHostname = $hostname.insert($dotidx,"-*")
$containerFolder = Join-Path $ExtensionsFolder $containerName
$updateHostsScript = Join-Path $containerFolder "my\updatehosts.ps1"
$allVolumes = @(docker volume ls --format "{{.Mountpoint}}|{{.Name}}")
$myVolumeName = "$containerName-my"
$myVolume = $allVolumes | Where-Object { $_ -like "*|$myVolumeName" }
if ($myVolume) {
$myFolder = $myVolume.Split('|')[0]
}
else {
$myFolder = Join-Path $containerFolder "my"
}
$updateHostsScript = Join-Path $myFolder "updatehosts.ps1"
$updateHosts = Test-Path -Path $updateHostsScript -PathType Leaf
if ($updateHosts) {
. (Join-Path $PSScriptRoot "updatehosts.ps1") -hostsFile "c:\windows\system32\drivers\etc\hosts" -theHostname $hostname -theIpAddress ""
. (Join-Path $PSScriptRoot "updatehosts.ps1") -hostsFile "c:\windows\system32\drivers\etc\hosts" -theHostname $tenantHostname -theIpAddress ""
}
if ($myVolume) {
docker volume remove $myVolumeName
}
$thumbprintFile = Join-Path $containerFolder "thumbprint.txt"
if (Test-Path -Path $thumbprintFile) {
$thumbprint = Get-Content -Path $thumbprintFile

Просмотреть файл

@ -34,7 +34,7 @@ function Set-BcContainerKeyVaultAadAppAndCertificate {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$ExtensionsFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions"
$ExtensionsFolder = Join-Path $hosthelperfolder "Extensions"
$sharedPfxFile = Join-Path $ExtensionsFolder "$containerName\my\$([GUID]::NewGuid().ToString()).pfx"
$removeSharedPfxFile = $true
if ($pfxFile -like "https://*" -or $pfxFile -like "http://*") {
@ -81,9 +81,9 @@ try {
if (!$doNotRestartServiceTier) {
Write-Host "Restarting Service Tier"
Set-NAVServerInstance -ServerInstance $serverInstance -Restart
while (Get-NavTenant $serverInstance | Where-Object { $_.State -eq "Mounting" }) {
Start-Sleep -Seconds 1
}
while (Get-NavTenant $serverInstance | Where-Object { $_.State -eq "Mounting" }) {
Start-Sleep -Seconds 1
}
}
} -argumentList (Get-BcContainerPath -containerName $containerName -path $sharedPfxFile), $pfxPassword, $clientId, $enablePublisherValidation, $doNotRestartServiceTier
}

Просмотреть файл

@ -234,7 +234,7 @@ function Expand-7zipArchive {
$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"
$use7zip = $false
if ((Get-ContainerHelperConfig).use7zipIfAvailable -and (Test-Path -Path $7zipPath -PathType Leaf)) {
if ($bcContainerHelperConfig.use7zipIfAvailable -and (Test-Path -Path $7zipPath -PathType Leaf)) {
try {
$use7zip = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($7zipPath).FileMajorPart -ge 19
}

Просмотреть файл

@ -37,7 +37,7 @@ $telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -paramet
try {
if ($basePath -eq "") {
$basePath = (Get-ContainerHelperConfig).bcartifactsCacheFolder
$basePath = $bcartifactsCacheFolder
}
if (-not (Test-Path $basePath)) {

Просмотреть файл

@ -1,4 +1,5 @@
2.0.20
Add support for using Docker Volumes for HostHelperFolder, BcArtifacts Cache folder and my folder
2.0.19
New-BcAuthContext displays wrongly decoded names as accessToken is UTF8 encoded

Просмотреть файл

@ -250,8 +250,8 @@
$useCALTestFwk = $true
}
elseif ($runTestsInVersion -eq 14) {
Copy-Item -Path (Join-Path $PSScriptRoot "inserttests") -Destination (Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$runTestsContainerName") -Recurse -Force
$appProjectFolder = Join-Path (Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$runTestsContainerName") "inserttests"
Copy-Item -Path (Join-Path $PSScriptRoot "inserttests") -Destination (Join-Path $hosthelperfolder "Extensions\$runTestsContainerName") -Recurse -Force
$appProjectFolder = Join-Path (Join-Path $hosthelperfolder "Extensions\$runTestsContainerName") "inserttests"
Compile-AppInBCContainer -containerName $runTestsContainerName -credential $credential -appProjectFolder $appProjectFolder -appOutputFolder $appProjectFolder -appName "inserttests.app" -UpdateSymbols
Publish-NavContainerApp -containerName $runTestsContainerName -appFile (Join-Path $appProjectFolder "inserttests.app") -skipVerification -sync -install
$useCALTestFwk = $true
@ -267,7 +267,7 @@
$tests.Count | Should -be 2
$first = $true
$resultsFile = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$runTestsContainerName\result.xml"
$resultsFile = Join-Path $hosthelperfolder "Extensions\$runTestsContainerName\result.xml"
$tests | % {
$allpassed = Run-TestsInBcContainer -containerName $runTestsContainerName `
-credential $credential `

Просмотреть файл

@ -2,7 +2,7 @@
It 'Backup-NavContainerDatabases' {
$bakFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "mybak"
$bakFolder = Join-Path $hosthelperfolder "mybak"
$bakFile = "$bakFolder\database.bak"
Backup-NavContainerDatabases -containerName $navContainerName `
-sqlCredential $credential `
@ -25,7 +25,7 @@
}
It 'Export-NavContainerDatabasesAsBacpac' {
$bacpacFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "bacpac"
$bacpacFolder = Join-Path $hosthelperfolder "bacpac"
$bacpacFile = "$bacpacFolder\database.bacpac"
Export-NavContainerDatabasesAsBacpac -containerName $bcContainerName -sqlCredential $credential -bacpacFolder $bacpacFolder -doNotCheckEntitlements
@ -45,7 +45,7 @@
-updateHosts `
-multitenant
$bacpacFolder = Join-Path $bcContainerHelperConfig.hostHelperFolder "bacpac"
$bacpacFolder = Join-Path $hosthelperfolder "bacpac"
$appBacpacFile = "$bacpacFolder\app.bacpac"
$tenant = "default"
$tenantBacpacFile = "$bacpacFolder\$tenant.bacpac"

Просмотреть файл

@ -2,7 +2,7 @@
$bcImageName = New-BcImage -artifactUrl $bcArtifactUrl -skipIfImageAlreadyExists
$bcContainerName = 'bco'
$bcContainerPlatformVersion = '17.0.16974.0'
$bcContainerPath = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$bcContainerName"
$bcContainerPath = Join-Path $hosthelperfolder "Extensions\$bcContainerName"
$bcMyPath = Join-Path $bcContainerPath "my"
New-BCContainer -accept_eula `
-accept_outdated `
@ -22,7 +22,7 @@ $bcsArtifactUrl = Get-BCArtifactUrl -type "Sandbox" -version "17.1.18256.30573"
$bcsImageName = New-BcImage -artifactUrl $bcsArtifactUrl -skipIfImageAlreadyExists
$bcsContainerName = 'bcs'
$bcsContainerPlatformVersion = "17.0.18204.30560"
$bcsContainerPath = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$bcsContainerName"
$bcsContainerPath = Join-Path $hosthelperfolder "Extensions\$bcsContainerName"
$bcsMyPath = Join-Path $bcsContainerPath "my"
New-BCContainer -accept_eula `
-accept_outdated `

Просмотреть файл

@ -2,7 +2,7 @@
$navImageName = New-BcImage -artifactUrl $navArtifactUrl -skipIfImageAlreadyExists
$navContainerName = 'nav'
$navContainerPlatformVersion = '11.0.31747.0'
$navContainerPath = Join-Path $bcContainerHelperConfig.hostHelperFolder "Extensions\$navContainerName"
$navContainerPath = Join-Path $hosthelperfolder "Extensions\$navContainerName"
$navMyPath = Join-Path $navContainerPath "my"
New-NavContainer -accept_eula `
-accept_outdated `