Skip to content

Commit 29fd844

Browse files
Add support to create PowerShell 7.0 and Java 11 function apps (#12167)
* Add support to create PowerShell 7.0 and Java 11 function apps * Addressing code review comments
1 parent 6984556 commit 29fd844

19 files changed

+7655
-5149
lines changed

src/Functions/Az.Functions.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ For information on Azure Functions, please visit the following: https://docs.mic
1313
DotNetFrameworkVersion = '4.7.2'
1414
RequiredAssemblies = './bin/Az.Functions.private.dll'
1515
FormatsToProcess = './Az.Functions.format.ps1xml', './custom/Functions.format.ps1xml'
16-
TypesToProcess = './custom/Functions.types.ps1xml'
16+
TypesToProcess = './custom/Functions.types.ps1xml'
1717
ScriptsToProcess = './custom/HelperFunctions.ps1'
1818
FunctionsToExport = 'Get-AzFunctionApp', 'Get-AzFunctionAppAvailableLocation', 'Get-AzFunctionAppPlan', 'Get-AzFunctionAppSetting', 'New-AzFunctionApp', 'New-AzFunctionAppPlan', 'Remove-AzFunctionApp', 'Remove-AzFunctionAppPlan', 'Remove-AzFunctionAppSetting', 'Restart-AzFunctionApp', 'Start-AzFunctionApp', 'Stop-AzFunctionApp', 'Update-AzFunctionApp', 'Update-AzFunctionAppPlan', 'Update-AzFunctionAppSetting'
1919
PrivateData = @{

src/Functions/custom/FunctionsStack/LinuxFunctionsStacks.json

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@
1010
"dependency": null,
1111
"majorVersions": [
1212
{
13-
"displayVersion": "",
13+
"displayVersion": "3.1",
1414
"supportedFunctionsExtensionVersions": [
15-
"1",
16-
"2",
17-
"3"
15+
"~3"
1816
],
19-
"runtimeVersion": null,
17+
"runtimeVersion": "dotnet|3.1",
2018
"isDefault": false,
2119
"minorVersions": [],
2220
"applicationInsights": true,
2321
"appSettingsDictionary": {
24-
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
22+
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
23+
"linuxFxVersion": "dotnet|3.1"
2524
},
2625
"siteConfigPropertiesDictionary": {
2726
"Use32BitWorkerProcess": false
@@ -48,7 +47,7 @@
4847
"displayVersion": "12",
4948
"runtimeVersion": "Node|12",
5049
"supportedFunctionsExtensionVersions": [
51-
"3"
50+
"~3"
5251
],
5352
"isDefault": true,
5453
"minorVersions": [],
@@ -68,8 +67,8 @@
6867
"displayVersion": "10",
6968
"runtimeVersion": "Node|10",
7069
"supportedFunctionsExtensionVersions": [
71-
"2",
72-
"3"
70+
"~2",
71+
"~3"
7372
],
7473
"isDefault": false,
7574
"minorVersions": [],
@@ -103,8 +102,8 @@
103102
"displayVersion": "3.6",
104103
"runtimeVersion": "Python|3.6",
105104
"supportedFunctionsExtensionVersions": [
106-
"2",
107-
"3"
105+
"~2",
106+
"~3"
108107
],
109108
"isDefault": false,
110109
"minorVersions": [],
@@ -124,8 +123,8 @@
124123
"displayVersion": "3.7",
125124
"runtimeVersion": "Python|3.7",
126125
"supportedFunctionsExtensionVersions": [
127-
"2",
128-
"3"
126+
"~2",
127+
"~3"
129128
],
130129
"isDefault": true,
131130
"minorVersions": [],
@@ -145,7 +144,7 @@
145144
"displayVersion": "3.8",
146145
"runtimeVersion": "Python|3.8",
147146
"supportedFunctionsExtensionVersions": [
148-
"3"
147+
"~3"
149148
],
150149
"isDefault": false,
151150
"minorVersions": [],
@@ -179,7 +178,7 @@
179178
"displayVersion": "8",
180179
"runtimeVersion": "Java|8",
181180
"supportedFunctionsExtensionVersions": [
182-
"3"
181+
"~3"
183182
],
184183
"isDefault": true,
185184
"minorVersions": [],
@@ -194,6 +193,26 @@
194193
"isPreview": false,
195194
"isDeprecated": false,
196195
"isHidden": false
196+
},
197+
{
198+
"displayVersion": "11",
199+
"runtimeVersion": "Java|11",
200+
"supportedFunctionsExtensionVersions": [
201+
"~3"
202+
],
203+
"isDefault": true,
204+
"minorVersions": [],
205+
"applicationInsights": true,
206+
"appSettingsDictionary": {
207+
"FUNCTIONS_WORKER_RUNTIME": "java"
208+
},
209+
"siteConfigPropertiesDictionary": {
210+
"Use32BitWorkerProcess": false,
211+
"linuxFxVersion": "Java|11"
212+
},
213+
"isPreview": false,
214+
"isDeprecated": false,
215+
"isHidden": false
197216
}
198217
],
199218
"frameworks": [],

src/Functions/custom/FunctionsStack/WindowsFunctionsStacks.json

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
"dependency": null,
1111
"majorVersions": [
1212
{
13-
"displayVersion": "",
13+
"displayVersion": "3.1",
1414
"runtimeVersion": null,
1515
"supportedFunctionsExtensionVersions": [
16-
"1",
17-
"2",
18-
"3"
16+
"~3"
1917
],
2018
"isDefault": true,
2119
"minorVersions": [],
@@ -46,7 +44,7 @@
4644
"displayVersion": "12",
4745
"runtimeVersion": "~12",
4846
"supportedFunctionsExtensionVersions": [
49-
"3"
47+
"~3"
5048
],
5149
"isDefault": true,
5250
"minorVersions": [],
@@ -64,8 +62,8 @@
6462
"displayVersion": "10",
6563
"runtimeVersion": "~10",
6664
"supportedFunctionsExtensionVersions": [
67-
"2",
68-
"3"
65+
"~2",
66+
"~3"
6967
],
7068
"isDefault": false,
7169
"minorVersions": [],
@@ -83,8 +81,8 @@
8381
"displayVersion": "8",
8482
"runtimeVersion": "~8",
8583
"supportedFunctionsExtensionVersions": [
86-
"1",
87-
"2"
84+
"~1",
85+
"~2"
8886
],
8987
"isDefault": false,
9088
"minorVersions": [],
@@ -97,25 +95,6 @@
9795
"isPreview": false,
9896
"isDeprecated": false,
9997
"isHidden": false
100-
},
101-
{
102-
"displayVersion": "6",
103-
"runtimeVersion": "~6",
104-
"supportedFunctionsExtensionVersions": [
105-
"1",
106-
"2"
107-
],
108-
"isDefault": false,
109-
"minorVersions": [],
110-
"applicationInsights": true,
111-
"appSettingsDictionary": {
112-
"FUNCTIONS_WORKER_RUNTIME": "node",
113-
"WEBSITE_NODE_DEFAULT_VERSION": "~6"
114-
},
115-
"siteConfigPropertiesDictionary": {},
116-
"isPreview": false,
117-
"isDeprecated": false,
118-
"isHidden": false
11998
}
12099
],
121100
"frameworks": [],
@@ -135,8 +114,25 @@
135114
"displayVersion": "8",
136115
"runtimeVersion": "1.8",
137116
"supportedFunctionsExtensionVersions": [
138-
"2",
139-
"3"
117+
"~2",
118+
"~3"
119+
],
120+
"isDefault": true,
121+
"minorVersions": [],
122+
"applicationInsights": true,
123+
"appSettingsDictionary": {
124+
"FUNCTIONS_WORKER_RUNTIME": "java"
125+
},
126+
"siteConfigPropertiesDictionary": {},
127+
"isPreview": false,
128+
"isDeprecated": false,
129+
"isHidden": false
130+
},
131+
{
132+
"displayVersion": "11",
133+
"runtimeVersion": "11",
134+
"supportedFunctionsExtensionVersions": [
135+
"~3"
140136
],
141137
"isDefault": true,
142138
"minorVersions": [],
@@ -160,15 +156,15 @@
160156
"type": "Microsoft.Web/availableStacks?osTypeSelected=WindowsFunctions",
161157
"properties": {
162158
"name": "powershell",
163-
"display": "Powershell Core",
159+
"display": "PowerShell Core",
164160
"dependency": null,
165161
"majorVersions": [
166162
{
167163
"displayVersion": "6.2",
168164
"runtimeVersion": "~6",
169165
"supportedFunctionsExtensionVersions": [
170-
"2",
171-
"3"
166+
"~2",
167+
"~3"
172168
],
173169
"isDefault": true,
174170
"minorVersions": [],
@@ -184,10 +180,10 @@
184180
"isHidden": false
185181
},
186182
{
187-
"displayVersion": "7.0",
183+
"displayVersion": "7.0",
188184
"runtimeVersion": "~7",
189185
"supportedFunctionsExtensionVersions": [
190-
"3"
186+
"~3"
191187
],
192188
"isDefault": true,
193189
"minorVersions": [],

src/Functions/custom/HelperFunctions.ps1

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ $constants["RuntimeToDefaultOSType"] = @{
5151
'Python' = 'Linux'
5252
}
5353

54-
# This are use for tab completion for the RuntimeVersion parameter in New-AzFunctionApp
54+
# These are used for tab completion for the RuntimeVersion parameter in New-AzFunctionApp.
5555
$constants["RuntimeVersions"] = @{
56-
'DotNet'= @(2, 3)
57-
'Node' = @(8, 10, 12)
58-
'Java' = @(8)
59-
'PowerShell' = @(6.2)
60-
'Python' = @(3.6, 3.7)
56+
'DotNet'= @('2', '3')
57+
'Node' = @('8', '10', '12')
58+
'Java' = @('8', '11')
59+
'PowerShell' = @('6.2', '7.0')
60+
'Python' = @('3.6', '3.7', '3.8')
6161
}
6262

6363
$constants["ReservedFunctionAppSettingNames"] = @(
@@ -223,6 +223,17 @@ function GetConnectionString
223223

224224
$resourceGroupName = ($storageAccountInfo.Id -split "/")[4]
225225
$keys = Az.Functions.internal\Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountInfo.Name @PSBoundParameters -ErrorAction SilentlyContinue
226+
227+
if (-not $keys)
228+
{
229+
$errorMessage = "Failed to get key for storage account '$StorageAccountName'."
230+
$exception = [System.InvalidOperationException]::New($errorMessage)
231+
ThrowTerminatingError -ErrorId "FailedToGetStorageAccountKey" `
232+
-ErrorMessage $errorMessage `
233+
-ErrorCategory ([System.Management.Automation.ErrorCategory]::InvalidOperation) `
234+
-Exception $exception
235+
}
236+
226237
if ([string]::IsNullOrEmpty($keys[0].Value))
227238
{
228239
$errorMessage = "Storage account '$StorageAccountName' has no key value."
@@ -1013,7 +1024,9 @@ function ValidateRuntimeAndRuntimeVersion
10131024
{
10141025
if ($majorVersion.DisplayVersion -eq $RuntimeVersion)
10151026
{
1016-
if ($majorVersion.SupportedFunctionsExtensionVersions -contains $FunctionsVersion)
1027+
# SupportedFunctionsExtensionVersions[0] is of the form '~int'
1028+
# Add '~' to the begining of FunctionsVersion
1029+
if ($majorVersion.SupportedFunctionsExtensionVersions -contains "~$FunctionsVersion")
10171030
{
10181031
$runtimeVersionIsSupported = $true
10191032
break
@@ -1518,13 +1531,15 @@ function NewIdentityUserAssignedIdentity
15181531
# Set Linux and Windows supported runtimes
15191532
Class Runtime {
15201533
[string]$Name
1521-
[Object[]]$MajorVersions
1534+
[MajorVersion[]]$MajorVersions
15221535
}
15231536

15241537
Class MajorVersion {
15251538
[string]$DisplayVersion
15261539
[string]$RuntimeVersion
15271540
[string[]]$SupportedFunctionsExtensionVersions
1541+
[hashtable]$AppSettingsDictionary
1542+
[hashtable]$SiteConfigPropertiesDictionary
15281543
}
15291544

15301545
$LinuxRuntimes = @{}
@@ -1552,12 +1567,38 @@ function SetLinuxandWindowsSupportedRuntimes
15521567
{
15531568
$majorVersion = [MajorVersion]::new()
15541569

1570+
$majorVersion.RuntimeVersion = $version.RuntimeVersion
1571+
$majorVersion.SupportedFunctionsExtensionVersions = $version.supportedFunctionsExtensionVersions
1572+
15551573
if ($version.displayVersion)
15561574
{
15571575
$majorVersion.DisplayVersion = $version.displayVersion
15581576
}
1559-
$majorVersion.RuntimeVersion = $version.RuntimeVersion
1560-
$majorVersion.SupportedFunctionsExtensionVersions = $version.supportedFunctionsExtensionVersions
1577+
1578+
if ($version.appSettingsDictionary)
1579+
{
1580+
$appSettings = @{}
1581+
1582+
foreach ($property in $version.appSettingsDictionary.PSObject.Properties)
1583+
{
1584+
$appSettings.Add($property.Name, $property.Value)
1585+
}
1586+
1587+
$majorVersion.appSettingsDictionary = $appSettings
1588+
}
1589+
1590+
if ($version.appSettingsDictionary)
1591+
{
1592+
$siteConfigProperties = @{}
1593+
1594+
foreach ($property in $version.siteConfigPropertiesDictionary.PSObject.Properties)
1595+
{
1596+
$siteConfigProperties.Add($property.Name, $property.Value)
1597+
}
1598+
1599+
$majorVersion.SiteConfigPropertiesDictionary = $siteConfigProperties
1600+
}
1601+
15611602
$runtime.MajorVersions += $majorVersion
15621603
}
15631604

src/Functions/custom/New-AzFunctionApp.ps1

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,6 @@ function New-AzFunctionApp {
278278

279279
$runtimeWorker = $Runtime.ToLower()
280280
$appSettings.Add((NewAppSetting -Name 'FUNCTIONS_WORKER_RUNTIME' -Value "$runtimeWorker"))
281-
282-
# Set Java version
283-
if ($Runtime -eq "Java")
284-
{
285-
$JavaVersion = GetWorkerVersion -FunctionsVersion $FunctionsVersion -Runtime $Runtime -RuntimeVersion $RuntimeVersion -OSType $OSType
286-
$siteCofig.JavaVersion = "$JavaVersion"
287-
}
288281
}
289282

290283
$servicePlan = $null
@@ -364,6 +357,18 @@ function New-AzFunctionApp {
364357
# Set default Node version
365358
$defaultNodeVersion = GetFunctionAppDefaultNodeVersion -FunctionsVersion $FunctionsVersion -Runtime $Runtime -RuntimeVersion $RuntimeVersion
366359
$appSettings.Add((NewAppSetting -Name 'WEBSITE_NODE_DEFAULT_VERSION' -Value $defaultNodeVersion))
360+
361+
# Set version for Java or PowerShell function apps
362+
if ($Runtime -eq "Java")
363+
{
364+
$JavaVersion = GetWorkerVersion -FunctionsVersion $FunctionsVersion -Runtime $Runtime -RuntimeVersion $RuntimeVersion -OSType $OSType
365+
$siteCofig.JavaVersion = "$JavaVersion"
366+
}
367+
elseif ($Runtime -eq "PowerShell")
368+
{
369+
$PowerShellWorkerVersion = GetWorkerVersion -FunctionsVersion $FunctionsVersion -Runtime $Runtime -RuntimeVersion $RuntimeVersion -OSType $OSType
370+
$siteCofig.PowerShellVersion = "$PowerShellWorkerVersion"
371+
}
367372
}
368373

369374
# Validate storage account and get connection string

0 commit comments

Comments
 (0)