Skip to content

Nav container helper #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AppHandling/Sort-AppFoldersByDependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function Sort-AppFoldersByDependencies {
}
}

$apps | Where-Object { $_.Name -eq "Application" } | ForEach-Object { AddAnApp -anApp $_ }
$apps | ForEach-Object { AddAnApp -AnApp $_ }

$script:sortedApps | ForEach-Object {
Expand Down
70 changes: 37 additions & 33 deletions ContainerHandling/New-NavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -373,29 +373,6 @@ function New-NavContainer {
$memoryLimit = "4G"
}

$SqlServerMemoryLimit = 0
if ($SqlMemoryLimit) {
if ($SqlMemoryLimit.EndsWith('%')) {
if ($memoryLimit -ne "") {
if ($memoryLimit -like '*M') {
$mbytes = [int]($memoryLimit.TrimEnd('mM'))
}
else {
$mbytes = [int](1024*([double]($memoryLimit.TrimEnd('gG'))))
}
$sqlServerMemoryLimit = [int]($mbytes * ([int]$SqlMemoryLimit.TrimEnd('%')) / 100)
}
}
else {
if ($SqlMemoryLimit -like '*M') {
$SqlServerMemoryLimit = [int]($SqlMemoryLimit.TrimEnd('mM'))
}
else {
$SqlServerMemoryLimit = [int](1024*([double]($SqlMemoryLimit.TrimEnd('gG'))))
}
}
}

# Remove if it already exists
Remove-NavContainer $containerName

Expand Down Expand Up @@ -1078,6 +1055,10 @@ function New-NavContainer {
}
Write-Host "Using $isolation isolation"

if ("$memoryLimit" -eq "" -and $isolation -eq "hyperv") {
$memoryLimit = "4G"
}

$myFolder = Join-Path $containerFolder "my"
New-Item -Path $myFolder -ItemType Directory -ErrorAction Ignore | Out-Null

Expand Down Expand Up @@ -1556,15 +1537,38 @@ if (-not `$restartingInstance) {

Write-Host "Reading CustomSettings.config from $containerName"
$customConfig = Get-NavContainerServerConfiguration -ContainerName $containerName

if ($SqlServerMemoryLimit -and $customConfig.databaseServer -eq "localhost" -and $customConfig.databaseInstance -eq "SQLEXPRESS") {
Write-Host "Set SQL Server memory limit to $SqlServerMemoryLimit MB"
Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($SqlServerMemoryLimit)
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE;"
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'max server memory', $SqlServerMemoryLimit RECONFIGURE WITH OVERRIDE;"
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 0 RECONFIGURE WITH OVERRIDE;"
} -argumentList ($SqlServerMemoryLimit)
}

$SqlServerMemoryLimit = 0
if ($SqlMemoryLimit) {
if ($SqlMemoryLimit.EndsWith('%')) {
if ($memoryLimit -ne "") {
if ($memoryLimit -like '*M') {
$mbytes = [int]($memoryLimit.TrimEnd('mM'))
}
else {
$mbytes = [int](1024*([double]($memoryLimit.TrimEnd('gG'))))
}
$sqlServerMemoryLimit = [int]($mbytes * ([int]$SqlMemoryLimit.TrimEnd('%')) / 100)
}
}
else {
if ($SqlMemoryLimit -like '*M') {
$SqlServerMemoryLimit = [int]($SqlMemoryLimit.TrimEnd('mM'))
}
else {
$SqlServerMemoryLimit = [int](1024*([double]($SqlMemoryLimit.TrimEnd('gG'))))
}
}
}

if ($SqlServerMemoryLimit -and $customConfig.databaseServer -eq "localhost" -and $customConfig.databaseInstance -eq "SQLEXPRESS") {
Write-Host "Set SQL Server memory limit to $SqlServerMemoryLimit MB"
Invoke-ScriptInBCContainer -containerName $containerName -scriptblock { Param($SqlServerMemoryLimit)
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE;"
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'max server memory', $SqlServerMemoryLimit RECONFIGURE WITH OVERRIDE;"
Invoke-Sqlcmd -ServerInstance 'localhost\SQLEXPRESS' -Query "USE master EXEC sp_configure 'show advanced options', 0 RECONFIGURE WITH OVERRIDE;"
} -argumentList ($SqlServerMemoryLimit)
}

if ("$TimeZoneId" -ne "") {
Write-Host "Set TimeZone in Container to $TimeZoneId"
Expand Down Expand Up @@ -1647,7 +1651,7 @@ if (-not `$restartingInstance) {
Remove-NavContainerSession -containerName $containerName
}

if ($version -eq [System.Version]"16.0.11240.12076" -and $devCountry -ne "W1") {
if ((($version -eq [System.Version]"16.0.11240.12076") -or ($version -eq [System.Version]"16.0.11240.12085")) -and $devCountry -ne "W1") {
$url = "https://bcdocker.blob.core.windows.net/public/12076-patch/$($devCountry.ToUpper()).zip"
Write-Host "Downloading new test apps for this version from $url"
$zipName = Join-Path $containerFolder "16.0.11240.12076-$devCountry-Tests-Patch"
Expand Down
2 changes: 1 addition & 1 deletion ContainerHandling/New-NavContainerWizard.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function New-NavContainerWizard {

$script = Join-Path $PSScriptRoot "..\CreateScript.ps1"

Start-Process $pslink @($script, "-skipContainerHelperCheck")
Start-Process $pslink @("-File ""$script""", "-skipContainerHelperCheck")

}
Set-Alias -Name New-BCContainerWizard -Value New-NavContainerWizard
Expand Down
22 changes: 19 additions & 3 deletions ContainerHandling/New-NavImage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,30 @@ function New-NavImage {
}

if ($hostOsVersion -eq $containerOsVersion) {
if ($isolation -eq "") { $isolation = "process" }
if ($isolation -eq "") {
$isolation = "process"
}
}
else {
if ($isolation -eq "") {
$isolation = "hyperv"
if ($isAdministrator) {
$feature = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online
if (($feature) -and ($feature.State -eq "Enabled")) {
$isolation = "hyperv"
}
else {
$isolation = "process"
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match and Hyper-V is not installed. If you encounter issues, you could try to install Hyper-V."
}
}
else {
$isolation = "hyperv"
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match. If you encounter issues, you could try to specify -isolation process"
}

}
elseif ($isolation -eq "process") {
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match and process isolation is specified. If you encounter issues, please try hyperv instead."
Write-Host "WARNING: Host OS and Base Image Container OS doesn't match and process isolation is specified. If you encounter issues, you could try to specify -isolation hyperv"
}
}

Expand Down
1 change: 1 addition & 0 deletions ContainerInfo/Get-NavContainerImageLabels.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Get-NavContainerImageLabels {
[PSCredential] $registryCredential
)

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$webclient = New-Object System.Net.WebClient

if ($imageName.IndexOf("/") -lt 0) {
Expand Down
1 change: 1 addition & 0 deletions ContainerInfo/Get-NavContainerImageTags.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function Get-NavContainerImageTags {
[int] $pageSize = -1
)

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$webclient = New-Object System.Net.WebClient

$registry = $imageName.Split("/")[0]
Expand Down
4 changes: 2 additions & 2 deletions CreateScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ $Step.NavContainerHelper {
Write-Host -ForegroundColor Red "Use 'Install-Module NavContainerHelper -force' to install in PowerShell"
return
}
elseif ($module.Version -eq [Version]"0.0") {
elseif ($module.Version -eq "0.0") {
$function = $module.ExportedFunctions.GetEnumerator() | Where-Object { $_.Key -eq "Get-BcArtifactUrl" }
if (!($function)) {
Write-Host -ForegroundColor Red "Your version of the NavContainerHelper PowerShell module is not up-to-date."
Expand All @@ -379,7 +379,7 @@ $Step.NavContainerHelper {
Write-Host -ForegroundColor Green "Running a cloned version of NavContainerHelper, which seems to be OK"
Write-Host
}
elseif ($module.Version -lt [Version]"0.7.0.9") {
elseif ([Version]$module.Version -lt [Version]"0.7.0.9") {
Write-Host -ForegroundColor Red "Your version of the NavContainerHelper PowerShell module is not up-to-date."
Write-Host -ForegroundColor Red "Please update the module using: Update-Module NavContainerHelper -force"
return
Expand Down
16 changes: 14 additions & 2 deletions Misc/Download-File.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
Destinatin for the downloaded file
.Parameter dontOverwrite
Specify dontOverwrite if you want top skip downloading if the file already exists
.Parameter timeout
Timeout in seconds for the download
.Parameter timeout
Timeout in seconds for the download
.Example
Download-File -sourceUrl "https://myurl/file.zip" -destinationFile "c:\temp\file.zip" -dontOverwrite
#>
Expand All @@ -24,6 +24,18 @@ function Download-File {
[int] $timeout = 100
)

$replaceUrls = @{
"https://go.microsoft.com/fwlink/?LinkID=844461" = "https://bcartifacts.azureedge.net/prerequisites/DotNetCore.1.0.4_1.1.1-WindowsHosting.exe"
"https://download.microsoft.com/download/C/9/E/C9E8180D-4E51-40A6-A9BF-776990D8BCA9/rewrite_amd64.msi" = "https://bcartifacts.azureedge.net/prerequisites/rewrite_2.0_rtw_x64.msi"
"https://download.microsoft.com/download/5/5/3/553C731E-9333-40FB-ADE3-E02DC9643B31/OpenXMLSDKV25.msi" = "https://bcartifacts.azureedge.net/prerequisites/OpenXMLSDKv25.msi"
"https://download.microsoft.com/download/A/1/2/A129F694-233C-4C7C-860F-F73139CF2E01/ENU/x86/ReportViewer.msi" = "https://bcartifacts.azureedge.net/prerequisites/ReportViewer.msi"
"https://download.microsoft.com/download/1/3/0/13089488-91FC-4E22-AD68-5BE58BD5C014/ENU/x86/SQLSysClrTypes.msi" = "https://bcartifacts.azureedge.net/prerequisites/SQLSysClrTypes.msi"
}

if ($replaceUrls.ContainsKey($sourceUrl)) {
$sourceUrl = $replaceUrls[$sourceUrl]
}

if (Test-Path $destinationFile -PathType Leaf) {
if ($dontOverwrite) {
return
Expand Down
17 changes: 16 additions & 1 deletion NavContainerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,28 @@ $containerHelperFolder = "C:\ProgramData\NavContainerHelper"

$NavContainerHelperVersion = Get-Content (Join-Path $PSScriptRoot "Version.txt")

Write-Host -ForegroundColor Red @'
__ __ _ _
\ \ / / (_) | |
\ \ /\ / /_ _ _ __ _ __ _ _ __ __ _| |
\ \/ \/ / _` | '__| '_ \| | '_ \ / _` | |
\ /\ / (_| | | | | | | | | | | (_| |_|
\/ \/ \__,_|_| |_| |_|_|_| |_|\__, (_)
__/ |
|___/
'@
Write-Host -ForegroundColor Red "NavContainerHelper is end of life, but still works!"
Write-Host -ForegroundColor Red "Please shift to BcContainerHelper as soon as possible."
Write-Host -ForegroundColor Red "Note: You need to remove all containers from the computer before you make the switch."
Write-Host -ForegroundColor Red "Read more here: https://freddysblog.com/2020/08/11/bccontainerhelper/"

$sessions = @{}

function Get-ContainerHelperConfig {
if (!((Get-Variable -scope Script navContainerHelperConfig -ErrorAction SilentlyContinue) -and $navContainerHelperConfig)) {
Set-Variable -scope Script -Name navContainerHelperConfig -Value @{
"bcartifactsCacheFolder" = "c:\bcartifacts.cache"
"genericImageName" = 'mcr.microsoft.com/dynamicsnav:{0}-generic'
"genericImageName" = 'mcr.microsoft.com/businesscentral:{0}-0.1.0.25'
"usePsSession" = $isAdministrator
"use7zipIfAvailable" = $true
"defaultNewContainerParameters" = @{ }
Expand Down
39 changes: 0 additions & 39 deletions PublishNavContainerHelper.ps1

This file was deleted.

21 changes: 21 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
0.7.0.27
Issue #1243 - Get-BcContainerImageTags and Get-BcContainerImageLabels doesn't work if TLS 1.2 isn't enabled
Use generic image from mcr.microsoft.com/businesscentral (SQL 2017 version)
Include Warning banner at startup

0.7.0.26
Sort-AppFoldersByDependencies didn't take custom Application apps into account

0.7.0.25
Fix missing pre-requisites

0.7.0.24
Issue #1186 New-BcContainer cannot import test toolkit from 16.0 onprem artifacts
Issue #1187 Running an image with hyperv isolation sometimes doesn't allowcate memory automatically

0.7.0.23
Issue #1180 New-BcContainerWizard doesn't work in 0.7.0.18 - 0.7.0.22 (if NavContainerHelper is installed in standard path)

0.7.0.22
Issue #1174 building image defaults to hyperv even if hyperv isn't installed

0.7.0.21
Issue #1160 autobuilding image fails if there is only one image on the machine before building

Expand Down
2 changes: 1 addition & 1 deletion Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0.21
0.7.0.27