|
| 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 | + [ValidateSet("UserPassword", "Windows")] |
| 9 | + [string] $auth = "", |
| 10 | + [pscredential] $credential = $null, |
| 11 | + [string] $licenseFileUrl = "", |
| 12 | + [switch] $fromVSCode, |
| 13 | + [switch] $accept_insiderEula, |
| 14 | + [switch] $clean |
| 15 | +) |
| 16 | + |
| 17 | +$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 |
| 18 | + |
| 19 | +function DownloadHelperFile { |
| 20 | + param( |
| 21 | + [string] $url, |
| 22 | + [string] $folder, |
| 23 | + [switch] $notifyAuthenticatedAttempt |
| 24 | + ) |
| 25 | + |
| 26 | + $prevProgressPreference = $ProgressPreference; $ProgressPreference = 'SilentlyContinue' |
| 27 | + $name = [System.IO.Path]::GetFileName($url) |
| 28 | + Write-Host "Downloading $name from $url" |
| 29 | + $path = Join-Path $folder $name |
| 30 | + try { |
| 31 | + Invoke-WebRequest -UseBasicParsing -uri $url -OutFile $path |
| 32 | + } |
| 33 | + catch { |
| 34 | + if ($notifyAuthenticatedAttempt) { |
| 35 | + Write-Host -ForegroundColor Red "Failed to download $name, trying authenticated download" |
| 36 | + } |
| 37 | + Invoke-WebRequest -UseBasicParsing -uri $url -OutFile $path -Headers @{ "Authorization" = "token $(gh auth token)" } |
| 38 | + } |
| 39 | + $ProgressPreference = $prevProgressPreference |
| 40 | + return $path |
| 41 | +} |
| 42 | + |
| 43 | +try { |
| 44 | +Clear-Host |
| 45 | +Write-Host |
| 46 | +Write-Host -ForegroundColor Yellow @' |
| 47 | + _ _ _____ ______ |
| 48 | + | | | | | __ \ | ____| |
| 49 | + | | ___ ___ __ _| | | | | | _____ __ |__ _ ____ __ |
| 50 | + | | / _ \ / __/ _` | | | | | |/ _ \ \ / / __| | '_ \ \ / / |
| 51 | + | |____ (_) | (__ (_| | | | |__| | __/\ V /| |____| | | \ V / |
| 52 | + |______\___/ \___\__,_|_| |_____/ \___| \_/ |______|_| |_|\_/ |
| 53 | +
|
| 54 | +'@ |
| 55 | + |
| 56 | +$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString())" |
| 57 | +New-Item -Path $tmpFolder -ItemType Directory -Force | Out-Null |
| 58 | +$GitHubHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/Github-Helper.psm1' -folder $tmpFolder -notifyAuthenticatedAttempt |
| 59 | +$ALGoHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/AL-Go-Helper.ps1' -folder $tmpFolder |
| 60 | +DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/settings.schema.json' -folder $tmpFolder | Out-Null |
| 61 | +DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/Packages.json' -folder $tmpFolder | Out-Null |
| 62 | + |
| 63 | +Import-Module $GitHubHelperPath |
| 64 | +. $ALGoHelperPath -local |
| 65 | + |
| 66 | +$baseFolder = GetBaseFolder -folder $PSScriptRoot |
| 67 | +$project = GetProject -baseFolder $baseFolder -projectALGoFolder $PSScriptRoot |
| 68 | + |
| 69 | +Write-Host @' |
| 70 | +
|
| 71 | +This script will create a docker based local development environment for your project. |
| 72 | +
|
| 73 | +NOTE: You need to have Docker installed, configured and be able to create Business Central containers for this to work. |
| 74 | +If this fails, you can setup a cloud based development environment by running cloudDevEnv.ps1 |
| 75 | +
|
| 76 | +All apps and test apps will be compiled and published to the environment in the development scope. |
| 77 | +The script will also modify launch.json to have a Local Sandbox configuration point to your environment. |
| 78 | +
|
| 79 | +'@ |
| 80 | + |
| 81 | +$settings = ReadSettings -baseFolder $baseFolder -project $project -userName $env:USERNAME -workflowName 'localDevEnv' |
| 82 | + |
| 83 | +Write-Host "Checking System Requirements" |
| 84 | +$dockerProcess = (Get-Process "dockerd" -ErrorAction Ignore) |
| 85 | +if (!($dockerProcess)) { |
| 86 | + Write-Host -ForegroundColor Red "Dockerd process not found. Docker might not be started, not installed or not running Windows Containers." |
| 87 | +} |
| 88 | +if ($settings.keyVaultName) { |
| 89 | + if (-not (Get-Module -ListAvailable -Name 'Az.KeyVault')) { |
| 90 | + 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)." |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +Write-Host |
| 95 | + |
| 96 | +if (-not $containerName) { |
| 97 | + $containerName = Enter-Value ` |
| 98 | + -title "Container name" ` |
| 99 | + -question "Please enter the name of the container to create" ` |
| 100 | + -default "bcserver" ` |
| 101 | + -trimCharacters @('"',"'",' ') |
| 102 | +} |
| 103 | + |
| 104 | +if (-not $auth) { |
| 105 | + $auth = Select-Value ` |
| 106 | + -title "Authentication mechanism for container" ` |
| 107 | + -options @{ "Windows" = "Windows Authentication"; "UserPassword" = "Username/Password authentication" } ` |
| 108 | + -question "Select authentication mechanism for container" ` |
| 109 | + -default "UserPassword" |
| 110 | +} |
| 111 | + |
| 112 | +if (-not $credential) { |
| 113 | + if ($auth -eq "Windows") { |
| 114 | + $credential = Get-Credential -Message "Please enter your Windows Credentials" -UserName $env:USERNAME |
| 115 | + $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName |
| 116 | + $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$credential.UserName,$credential.GetNetworkCredential().password) |
| 117 | + if ($null -eq $domain.name) { |
| 118 | + Write-Host -ForegroundColor Red "Unable to verify your Windows Credentials, you might not be able to authenticate to your container" |
| 119 | + } |
| 120 | + } |
| 121 | + else { |
| 122 | + $credential = Get-Credential -Message "Please enter username and password for your container" -UserName "admin" |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +if (-not $licenseFileUrl) { |
| 127 | + if ($settings.type -eq "AppSource App") { |
| 128 | + $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" |
| 129 | + $default = "none" |
| 130 | + } |
| 131 | + else { |
| 132 | + $description = "When developing PTEs, you can optionally specify a developer licensefile with permissions to object IDs of your dependant apps" |
| 133 | + $default = "none" |
| 134 | + } |
| 135 | + |
| 136 | + $licenseFileUrl = Enter-Value ` |
| 137 | + -title "LicenseFileUrl" ` |
| 138 | + -description $description ` |
| 139 | + -question "Local path or a secure download URL to license file " ` |
| 140 | + -default $default ` |
| 141 | + -doNotConvertToLower ` |
| 142 | + -trimCharacters @('"',"'",' ') |
| 143 | +} |
| 144 | + |
| 145 | +if ($licenseFileUrl -eq "none") { |
| 146 | + $licenseFileUrl = "" |
| 147 | +} |
| 148 | + |
| 149 | +CreateDevEnv ` |
| 150 | + -kind local ` |
| 151 | + -caller local ` |
| 152 | + -containerName $containerName ` |
| 153 | + -baseFolder $baseFolder ` |
| 154 | + -project $project ` |
| 155 | + -auth $auth ` |
| 156 | + -credential $credential ` |
| 157 | + -licenseFileUrl $licenseFileUrl ` |
| 158 | + -accept_insiderEula:$accept_insiderEula ` |
| 159 | + -clean:$clean |
| 160 | +} |
| 161 | +catch { |
| 162 | + Write-Host -ForegroundColor Red "Error: $($_.Exception.Message)`nStacktrace: $($_.scriptStackTrace)" |
| 163 | +} |
| 164 | +finally { |
| 165 | + if ($fromVSCode) { |
| 166 | + Read-Host "Press ENTER to close this window" |
| 167 | + } |
| 168 | +} |
0 commit comments