DimeScheduler.BCContainer.ps1

<#PSScriptInfo
.VERSION 0.0.1.0
.GUID d700bd9c-42aa-41cc-8b3d-b3f2bb1e2a9d
.AUTHOR Hendrik Bulens
.ICONURI https://cdn.dimescheduler.com/dime-scheduler/v2/shape.png
#>


#Requires -Module BcContainerHelper

<#
.SYNOPSIS
Gets and deploys Business Central in a Docker container.
It's merely a wrapper around the BcContainerHelper module (https://github.com/microsoft/navcontainerhelper) that's ready to go.
 
.DESCRIPTION
Downloads the image from the registry and deploys it to a Docker container.
This is done using the NavContainerHelper PowerShell module.
 
.PARAMETER bcVersion
See this blog for more information: https://freddysblog.com/2020/06/25/working-with-artifacts/
 
.PARAMETER containerName
Name of the new container (if the container already exists it will be replaced)
 
.PARAMETER useShortcuts
Use this switch to create desktop shortcuts
 
.PARAMETER includeTestToolkit
Use this switch too include the test toolkit
 
.PARAMETER memoryLimit
Memory limit for the container (default is unlimited for Windows Server host else 4G)
 
.PARAMETER dns
Use this parameter to override the default dns settings in the container (corresponds to --dns on docker run)
 
.PARAMETER sharedDrive
The path of the shared drive where to drop the license file
 
.PARAMETER licensefile
The path of the license file
 
.PARAMETER user
The admin user name
 
.PARAMETER password
The admin password
#>

param(
    [Parameter(mandatory = $false, HelpMessage = "The BC version")]
    [String]$bcVersion = '24.0',

    [Parameter(mandatory = $false, HelpMessage = "The name of the container")]
    [String]$containerName = 'BC24',
   
    [Parameter(mandatory = $false, HelpMessage = "Switch to include shortcuts")]
    [Switch]$useShortcuts = $true,

    [Parameter(mandatory = $false, HelpMessage = "Switch to include test toolkit")]
    [Switch]$includeTestToolkit = $false,
    
    [Parameter(mandatory = $false, HelpMessage = "Memory limit for the container (default is unlimited for Windows Server host else 4G-8G should be enough)")]
    [string]$memoryLimit = "8G",
    
    [Parameter(mandatory = $false, HelpMessage = "Use this parameter to override the default dns settings in the container (corresponds to --dns on docker run)")]
    [string]$dns = '8.8.8.8',

    [Parameter(mandatory = $false, HelpMessage = "The local drive to share with the Docker container")]
    [String]$sharedDrive = 'C:\docker\DS',

    [Parameter(mandatory = $false, HelpMessage = "The BC license file")]
    [String]$licensefile = 'c:\temp\BC.bclicense',

    [Parameter(mandatory = $false, HelpMessage = "The BC admin")]
    [String]$user = 'admin',

    [Parameter(mandatory = $false, HelpMessage = "The BC admin password")]
    [String]$password = 'admin'
)

Write-Output ""
Write-Output ""
Write-Output "*"
Write-Output "**"
Write-Output "***"
Write-Output "****"
Write-Output "*****"
Write-Output "******"
Write-Output "*******"
Write-Output "********"
Write-Output "*********"
Write-Output "**********"
Write-Output "***********"
Write-Output "************"
Write-Output ""
Write-Output "_____ _ _____ _ _ _"
Write-Output "| __ \(_) / ____| | | | | | |"
Write-Output "| | | |_ _ __ ___ ___ | (___ ___| |__ ___ __| |_ _| | ___ _ __"
Write-Output "| | | | | '_ ` _ \ / _ \ \___ \ / __| '_ \ / _ \/ _` | | | | |/ _ \ '__|"
Write-Output "| |__| | | | | | | | __/_ ____) | (__| | | | __/ (_| | |_| | | __/ |"
Write-Output "|_____/|_|_| |_| |_|\___(_)_____/ \___|_| |_|\___|\__,_|\__,_|_|\___|_|"
Write-Output ""
Write-Output ""
Write-Output "Creating Docker container $containerName for version $bcVersion."
Write-Output ""
Write-Output "************"
Write-Output "***********"
Write-Output "**********"
Write-Output "*********"
Write-Output "********"
Write-Output "*******"
Write-Output "******"
Write-Output "*****"
Write-Output "****"
Write-Output "***"
Write-Output "**"
Write-Output "*"
Write-Output ""
Write-Output ""

if (-not (Get-Module BcContainerHelper -ListAvailable)) {
    Install-Module BcContainerHelper -Scope CurrentUser -Force
}

$accept_eula = $true
$appbacpacuri = ''
$tenantbacpacuri = ''

# Shared drive: map the parameter (by default, that is 'C:\docker\DS') to the local C:\dsfiles directory on Docker
$additionalParameters = @("-v" + $sharedDrive + ":c:\dsfiles")
if ($appbacpacuri -ne '' -and $tenantbacpacuri -ne '') {
    $additionalParameters += @("--env appbacpac=""$appbacpacuri""", "--env tenantBacpac=""$tenantbacpacuri""")
}

# Build credentials
$pw = ConvertTo-SecureString -String $password -AsPlainText -Force
$credential = New-Object PSCredential $user, $pw

# Fetch the URL of the requested container
$artifactUrl = Get-BCArtifactUrl -type OnPrem -version $bcVersion -country w1
Write-Output "Artifact URL for $bcVersion : $artifactUrl"

# Value for shortcuts: None, Desktop or StartMenu
$shortCuts = 'None';
if ($useShortcuts.IsPresent) {
    $shortCuts = 'Desktop';
}

New-BcContainer -accept_eula:$accept_eula `
    -containerName $containerName `
    -auth UserPassword `
    -Credential $credential `
    -alwaysPull `
    -doNotExportObjectsToText `
    -usessl:$false `
    -updateHosts `
    -assignPremiumPlan `
    -shortcuts $shortcuts `
    -artifactUrl $artifactUrl `
    -additionalParameters $additionalParameters `
    -ACCEPT_OUTDATED `
    -licenseFile $licensefile `
    -includeTestToolkit:$includeTestToolkit.IsPresent `
    -includetestlibrariesonly `
    -memoryLimit $memoryLimit `
    -dns $dns