|
| 1 | +# |
| 2 | +# Script for creating local development environment |
| 3 | +# Please do not modify this script as it will be auto-updated from the AL-Go Template |
| 4 | +# Recommended approach is to use as is or add a script (freddyk-devenv.ps1), which calls this script with the user specific parameters |
| 5 | +# |
| 6 | +Param( |
| 7 | + [string] $containerName = "", |
| 8 | + [string] $auth = "", |
| 9 | + [pscredential] $credential = $null, |
| 10 | + [string] $licenseFileUrl = "", |
| 11 | + [switch] $fromVSCode, |
| 12 | + [switch] $accept_insiderEula |
| 13 | +) |
| 14 | + |
| 15 | +$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 |
| 16 | + |
| 17 | +try { |
| 18 | +Clear-Host |
| 19 | +Write-Host |
| 20 | +Write-Host -ForegroundColor Yellow @' |
| 21 | + _ _ _____ ______ |
| 22 | + | | | | | __ \ | ____| |
| 23 | + | | ___ ___ __ _| | | | | | _____ __ |__ _ ____ __ |
| 24 | + | | / _ \ / __/ _` | | | | | |/ _ \ \ / / __| | '_ \ \ / / |
| 25 | + | |____ (_) | (__ (_| | | | |__| | __/\ V /| |____| | | \ V / |
| 26 | + |______\___/ \___\__,_|_| |_____/ \___| \_/ |______|_| |_|\_/ |
| 27 | +
|
| 28 | +'@ |
| 29 | + |
| 30 | +$webClient = New-Object System.Net.WebClient |
| 31 | +$webClient.CachePolicy = New-Object System.Net.Cache.RequestCachePolicy -argumentList ([System.Net.Cache.RequestCacheLevel]::NoCacheNoStore) |
| 32 | +$webClient.Encoding = [System.Text.Encoding]::UTF8 |
| 33 | +$GitHubHelperUrl = 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/v4.0/Github-Helper.psm1' |
| 34 | +Write-Host "Downloading GitHub Helper module from $GitHubHelperUrl" |
| 35 | +$GitHubHelperPath = "$([System.IO.Path]::GetTempFileName()).psm1" |
| 36 | +$webClient.DownloadFile($GitHubHelperUrl, $GitHubHelperPath) |
| 37 | +$ALGoHelperUrl = 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/v4.0/AL-Go-Helper.ps1' |
| 38 | +Write-Host "Downloading AL-Go Helper script from $ALGoHelperUrl" |
| 39 | +$ALGoHelperPath = "$([System.IO.Path]::GetTempFileName()).ps1" |
| 40 | +$webClient.DownloadFile($ALGoHelperUrl, $ALGoHelperPath) |
| 41 | + |
| 42 | +Import-Module $GitHubHelperPath |
| 43 | +. $ALGoHelperPath -local |
| 44 | + |
| 45 | +$baseFolder = GetBaseFolder -folder $PSScriptRoot |
| 46 | +$project = GetProject -baseFolder $baseFolder -projectALGoFolder $PSScriptRoot |
| 47 | + |
| 48 | +Write-Host @' |
| 49 | +
|
| 50 | +This script will create a docker based local development environment for your project. |
| 51 | +
|
| 52 | +NOTE: You need to have Docker installed, configured and be able to create Business Central containers for this to work. |
| 53 | +If this fails, you can setup a cloud based development environment by running cloudDevEnv.ps1 |
| 54 | +
|
| 55 | +All apps and test apps will be compiled and published to the environment in the development scope. |
| 56 | +The script will also modify launch.json to have a Local Sandbox configuration point to your environment. |
| 57 | +
|
| 58 | +'@ |
| 59 | + |
| 60 | +$settings = ReadSettings -baseFolder $baseFolder -project $project -userName $env:USERNAME -workflowName 'localDevEnv' |
| 61 | + |
| 62 | +Write-Host "Checking System Requirements" |
| 63 | +$dockerProcess = (Get-Process "dockerd" -ErrorAction Ignore) |
| 64 | +if (!($dockerProcess)) { |
| 65 | + Write-Host -ForegroundColor Red "Dockerd process not found. Docker might not be started, not installed or not running Windows Containers." |
| 66 | +} |
| 67 | +if ($settings.keyVaultName) { |
| 68 | + if (-not (Get-Module -ListAvailable -Name 'Az.KeyVault')) { |
| 69 | + Write-Host -ForegroundColor Red "A keyvault name is defined in Settings, you need to have the Az.KeyVault PowerShell module installed (use Install-Module az) or you can set the keyVaultName to an empty string in the user settings file ($($ENV:UserName).settings.json)." |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +Write-Host |
| 74 | + |
| 75 | +if (-not $containerName) { |
| 76 | + $containerName = Enter-Value ` |
| 77 | + -title "Container name" ` |
| 78 | + -question "Please enter the name of the container to create" ` |
| 79 | + -default "bcserver" ` |
| 80 | + -trimCharacters @('"',"'",' ') |
| 81 | +} |
| 82 | + |
| 83 | +if (-not $auth) { |
| 84 | + $auth = Select-Value ` |
| 85 | + -title "Authentication mechanism for container" ` |
| 86 | + -options @{ "Windows" = "Windows Authentication"; "UserPassword" = "Username/Password authentication" } ` |
| 87 | + -question "Select authentication mechanism for container" ` |
| 88 | + -default "UserPassword" |
| 89 | +} |
| 90 | + |
| 91 | +if (-not $credential) { |
| 92 | + if ($auth -eq "Windows") { |
| 93 | + $credential = Get-Credential -Message "Please enter your Windows Credentials" -UserName $env:USERNAME |
| 94 | + $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName |
| 95 | + $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$credential.UserName,$credential.GetNetworkCredential().password) |
| 96 | + if ($null -eq $domain.name) { |
| 97 | + Write-Host -ForegroundColor Red "Unable to verify your Windows Credentials, you might not be able to authenticate to your container" |
| 98 | + } |
| 99 | + } |
| 100 | + else { |
| 101 | + $credential = Get-Credential -Message "Please enter username and password for your container" -UserName "admin" |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +if (-not $licenseFileUrl) { |
| 106 | + if ($settings.type -eq "AppSource App") { |
| 107 | + $description = "When developing AppSource Apps for Business Central versions prior to 22, your local development environment needs the developer licensefile with permissions to your AppSource app object IDs" |
| 108 | + $default = "none" |
| 109 | + } |
| 110 | + else { |
| 111 | + $description = "When developing PTEs, you can optionally specify a developer licensefile with permissions to object IDs of your dependant apps" |
| 112 | + $default = "none" |
| 113 | + } |
| 114 | + |
| 115 | + $licenseFileUrl = Enter-Value ` |
| 116 | + -title "LicenseFileUrl" ` |
| 117 | + -description $description ` |
| 118 | + -question "Local path or a secure download URL to license file " ` |
| 119 | + -default $default ` |
| 120 | + -doNotConvertToLower ` |
| 121 | + -trimCharacters @('"',"'",' ') |
| 122 | +} |
| 123 | + |
| 124 | +if ($licenseFileUrl -eq "none") { |
| 125 | + $licenseFileUrl = "" |
| 126 | +} |
| 127 | + |
| 128 | +CreateDevEnv ` |
| 129 | + -kind local ` |
| 130 | + -caller local ` |
| 131 | + -containerName $containerName ` |
| 132 | + -baseFolder $baseFolder ` |
| 133 | + -project $project ` |
| 134 | + -auth $auth ` |
| 135 | + -credential $credential ` |
| 136 | + -licenseFileUrl $licenseFileUrl ` |
| 137 | + -accept_insiderEula:$accept_insiderEula |
| 138 | +} |
| 139 | +catch { |
| 140 | + Write-Host -ForegroundColor Red "Error: $($_.Exception.Message)`nStacktrace: $($_.scriptStackTrace)" |
| 141 | +} |
| 142 | +finally { |
| 143 | + if ($fromVSCode) { |
| 144 | + Read-Host "Press ENTER to close this window" |
| 145 | + } |
| 146 | +} |
0 commit comments