Skip to content

Commit af56acc

Browse files
Initial commit
0 parents  commit af56acc

24 files changed

Lines changed: 3429 additions & 0 deletions

.AL-Go/cloudDevEnv.ps1

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#
2+
# Script for creating cloud 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] $environmentName = "",
8+
[bool] $reuseExistingEnvironment,
9+
[switch] $fromVSCode,
10+
[switch] $clean
11+
)
12+
13+
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
14+
15+
function DownloadHelperFile {
16+
param(
17+
[string] $url,
18+
[string] $folder,
19+
[switch] $notifyAuthenticatedAttempt
20+
)
21+
22+
$prevProgressPreference = $ProgressPreference; $ProgressPreference = 'SilentlyContinue'
23+
$name = [System.IO.Path]::GetFileName($url)
24+
Write-Host "Downloading $name from $url"
25+
$path = Join-Path $folder $name
26+
try {
27+
Invoke-WebRequest -UseBasicParsing -uri $url -OutFile $path
28+
}
29+
catch {
30+
if ($notifyAuthenticatedAttempt) {
31+
Write-Host -ForegroundColor Red "Failed to download $name, trying authenticated download"
32+
}
33+
Invoke-WebRequest -UseBasicParsing -uri $url -OutFile $path -Headers @{ "Authorization" = "token $(gh auth token)" }
34+
}
35+
$ProgressPreference = $prevProgressPreference
36+
return $path
37+
}
38+
39+
try {
40+
Clear-Host
41+
Write-Host
42+
Write-Host -ForegroundColor Yellow @'
43+
_____ _ _ _____ ______
44+
/ ____| | | | | __ \ | ____|
45+
| | | | ___ _ _ __| | | | | | _____ __ |__ _ ____ __
46+
| | | |/ _ \| | | |/ _` | | | | |/ _ \ \ / / __| | '_ \ \ / /
47+
| |____| | (_) | |_| | (_| | | |__| | __/\ V /| |____| | | \ V /
48+
\_____|_|\___/ \__,_|\__,_| |_____/ \___| \_/ |______|_| |_|\_/
49+
50+
'@
51+
52+
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString())"
53+
New-Item -Path $tmpFolder -ItemType Directory -Force | Out-Null
54+
$GitHubHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/Github-Helper.psm1' -folder $tmpFolder -notifyAuthenticatedAttempt
55+
$ALGoHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/AL-Go-Helper.ps1' -folder $tmpFolder
56+
DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/settings.schema.json' -folder $tmpFolder | Out-Null
57+
DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/Packages.json' -folder $tmpFolder | Out-Null
58+
59+
Import-Module $GitHubHelperPath
60+
. $ALGoHelperPath -local
61+
62+
$baseFolder = GetBaseFolder -folder $PSScriptRoot
63+
$project = GetProject -baseFolder $baseFolder -projectALGoFolder $PSScriptRoot
64+
65+
Write-Host @'
66+
67+
This script will create a cloud based development environment (Business Central SaaS Sandbox) for your project.
68+
All apps and test apps will be compiled and published to the environment in the development scope.
69+
The script will also modify launch.json to have a "Cloud Sandbox (<name>)" configuration point to your environment.
70+
71+
'@
72+
73+
if (Test-Path (Join-Path $PSScriptRoot "NewBcContainer.ps1")) {
74+
Write-Host -ForegroundColor Red "WARNING: The project has a NewBcContainer override defined. Typically, this means that you cannot run a cloud development environment"
75+
}
76+
77+
Write-Host
78+
79+
if (-not $environmentName) {
80+
$environmentName = Enter-Value `
81+
-title "Environment name" `
82+
-question "Please enter the name of the environment to create" `
83+
-default "$($env:USERNAME)-sandbox" `
84+
-trimCharacters @('"',"'",' ')
85+
}
86+
87+
if ($PSBoundParameters.Keys -notcontains 'reuseExistingEnvironment') {
88+
$reuseExistingEnvironment = (Select-Value `
89+
-title "What if the environment already exists?" `
90+
-options @{ "Yes" = "Reuse existing environment"; "No" = "Recreate environment" } `
91+
-question "Select behavior" `
92+
-default "No") -eq "Yes"
93+
}
94+
95+
CreateDevEnv `
96+
-kind cloud `
97+
-caller local `
98+
-environmentName $environmentName `
99+
-reuseExistingEnvironment:$reuseExistingEnvironment `
100+
-baseFolder $baseFolder `
101+
-project $project `
102+
-clean:$clean
103+
}
104+
catch {
105+
Write-Host -ForegroundColor Red "Error: $($_.Exception.Message)`nStacktrace: $($_.scriptStackTrace)"
106+
}
107+
finally {
108+
if ($fromVSCode) {
109+
Read-Host "Press ENTER to close this window"
110+
}
111+
}

.AL-Go/localDevEnv.ps1

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
}

.AL-Go/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/settings.schema.json",
3+
"country": "us",
4+
"appFolders": [],
5+
"testFolders": [],
6+
"bcptTestFolders": []
7+
}

.github/AL-Go-Settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/AL-Go/ab2f5319ed073c542e03914f8ae6c0fda029ee1e/Actions/settings.schema.json",
3+
"type": "PTE",
4+
"templateUrl": "https://github.com/microsoft/AL-Go-PTE@preview",
5+
"templateSha": "e74753260f6cc4bc3009c414b8e84b328cb282c9"
6+
}

0 commit comments

Comments
 (0)