-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathcreateCreateFunctionAppComponents.ts
More file actions
203 lines (169 loc) · 9.84 KB
/
createCreateFunctionAppComponents.ts
File metadata and controls
203 lines (169 loc) · 9.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AppInsightsCreateStep, AppInsightsListStep, AppKind, AppServicePlanCreateStep, AppServicePlanListStep, CustomLocationListStep, LogAnalyticsCreateStep, SiteNameStep, WebsiteOS, type IAppServiceWizardContext } from "@microsoft/vscode-azext-azureappservice";
import { CommonRoleDefinitions, createRoleId, LocationListStep, ResourceGroupCreateStep, ResourceGroupListStep, RoleAssignmentExecuteStep, StorageAccountCreateStep, StorageAccountKind, StorageAccountListStep, StorageAccountPerformance, StorageAccountReplication, type INewStorageAccountDefaults, type Role } from "@microsoft/vscode-azext-azureutils";
import { type AzureWizardExecuteStep, type AzureWizardPromptStep, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { FuncVersion, latestGAVersion, tryParseFuncVersion } from "../../FuncVersion";
import { DurableBackend, funcVersionSetting } from "../../constants";
import { tryGetLocalFuncVersion } from "../../funcCoreTools/tryGetLocalFuncVersion";
import { type ICreateFunctionAppContext } from "../../tree/SubscriptionTreeItem";
import { createActivityContext } from "../../utils/activityUtils";
import { durableUtils } from "../../utils/durableUtils";
import { getRootFunctionsWorkerRuntime, getWorkspaceSetting, getWorkspaceSettingFromAnyFolder } from "../../vsCodeConfig/settings";
import { AuthenticationPromptStep } from "./AuthenticationPromptStep";
import { FunctionAppCreateStep } from "./FunctionAppCreateStep";
import { allAvailableFunctionAppHostingPlans, FunctionAppHostingPlans, FunctionAppHostingPlanStep } from "./FunctionAppHostingPlanStep";
import { type IFunctionAppWizardContext } from "./IFunctionAppWizardContext";
import { ConfigureCommonNamesStep } from "./UniqueNamePromptStep";
import { ContainerizedFunctionAppCreateStep } from "./containerImage/ContainerizedFunctionAppCreateStep";
import { DeployWorkspaceProjectStep } from "./containerImage/DeployWorkspaceProjectStep";
import { detectDockerfile } from "./containerImage/detectDockerfile";
import { FunctionAppStackStep } from "./stacks/FunctionAppStackStep";
export async function createCreateFunctionAppComponents(context: ICreateFunctionAppContext,
subscription: ISubscriptionContext,
language?: string | undefined): Promise<{
wizardContext: IFunctionAppWizardContext;
promptSteps: AzureWizardPromptStep<IFunctionAppWizardContext>[];
executeSteps: AzureWizardExecuteStep<IFunctionAppWizardContext>[];
}> {
const version: FuncVersion = await getDefaultFuncVersion(context);
context.telemetry.properties.projectRuntime = version;
const wizardContext: IFunctionAppWizardContext = Object.assign(context, subscription, {
newSiteKind: AppKind.functionapp,
resourceGroupDeferLocationStep: true,
version,
language,
...(await createActivityContext())
});
wizardContext.activityChildren = [];
const promptSteps: AzureWizardPromptStep<IFunctionAppWizardContext>[] = [];
const executeSteps: AzureWizardExecuteStep<IFunctionAppWizardContext>[] = [];
const storageAccountCreateOptions: INewStorageAccountDefaults = {
kind: StorageAccountKind.StorageV2,
performance: StorageAccountPerformance.Standard,
replication: StorageAccountReplication.LRS
};
wizardContext.dockerfilePath = await detectDockerfile(wizardContext);
if (wizardContext.workspaceFolder) {
wizardContext.durableStorageType = await durableUtils.getStorageTypeFromWorkspace(language, wizardContext.workspaceFolder.uri.fsPath);
wizardContext.telemetry.properties.durableStorageType = wizardContext.durableStorageType;
}
promptSteps.push(new SiteNameStep(wizardContext.dockerfilePath ? "containerizedFunctionApp" : "functionApp"));
if (wizardContext.dockerfilePath) {
const containerizedfunctionAppWizard = await createContainerizedFunctionAppWizard();
promptSteps.push(...containerizedfunctionAppWizard.promptSteps);
executeSteps.push(...containerizedfunctionAppWizard.executeSteps);
} else {
const functionAppWizard = await createFunctionAppWizard(wizardContext);
promptSteps.push(...functionAppWizard.promptSteps);
executeSteps.push(...functionAppWizard.executeSteps);
}
promptSteps.push(new AuthenticationPromptStep());
if (!wizardContext.advancedCreation) {
LocationListStep.addStep(wizardContext, promptSteps);
// if the user is deploying to a container app, do not use a flex consumption plan
wizardContext.useFlexConsumptionPlan = !wizardContext.dockerfilePath;
wizardContext.stackFilter = getRootFunctionsWorkerRuntime(wizardContext.language);
promptSteps.push(new ConfigureCommonNamesStep());
executeSteps.push(new ResourceGroupCreateStep());
executeSteps.push(new StorageAccountCreateStep(storageAccountCreateOptions));
executeSteps.push(new AppInsightsCreateStep());
if (!wizardContext.dockerfilePath) {
executeSteps.push(new AppServicePlanCreateStep());
executeSteps.push(new LogAnalyticsCreateStep());
}
} else {
promptSteps.push(new ResourceGroupListStep());
promptSteps.push(new StorageAccountListStep(
storageAccountCreateOptions,
{
// The account type must support blobs, queues, and tables.
// See: https://aka.ms/Cfqnrc
kind: [
// Blob-only accounts don't support queues and tables
StorageAccountKind.BlobStorage
],
performance: [
// Premium performance accounts don't support queues and tables
StorageAccountPerformance.Premium
],
learnMoreLink: 'https://aka.ms/Cfqnrc'
}
));
promptSteps.push(new AppInsightsListStep());
}
executeSteps.push(new RoleAssignmentExecuteStep(() => {
const role: Role = {
scopeId: wizardContext?.storageAccount?.id,
roleDefinitionId: createRoleId(wizardContext?.subscriptionId, CommonRoleDefinitions.storageBlobDataContributor),
roleDefinitionName: CommonRoleDefinitions.storageBlobDataContributor.roleName
};
return [role];
}));
const storageProvider = 'Microsoft.Storage';
LocationListStep.addProviderForFiltering(wizardContext, storageProvider, 'storageAccounts');
return {
wizardContext,
promptSteps,
executeSteps
};
}
async function getDefaultFuncVersion(context: ICreateFunctionAppContext): Promise<FuncVersion> {
const settingValue: string | undefined = context.workspaceFolder ? getWorkspaceSetting(funcVersionSetting, context.workspaceFolder) : getWorkspaceSettingFromAnyFolder(funcVersionSetting);
// Try to get VS Code setting for version (aka if they have a project open)
let version: FuncVersion | undefined = tryParseFuncVersion(settingValue);
context.telemetry.properties.runtimeSource = 'VSCodeSetting';
if (version === undefined) {
// Try to get the version that matches their local func cli
version = await tryGetLocalFuncVersion(context, undefined);
context.telemetry.properties.runtimeSource = 'LocalFuncCli';
}
if (version === undefined) {
version = latestGAVersion;
context.telemetry.properties.runtimeSource = 'Backup';
}
return version;
}
async function createFunctionAppWizard(wizardContext: IFunctionAppWizardContext): Promise<{ promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[], executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] }> {
const promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[] = [];
const executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] = [];
promptSteps.push(new FunctionAppHostingPlanStep(
getAvailableFunctionAppHostingPlans(wizardContext) /** availablePlans */,
));
CustomLocationListStep.addStep(wizardContext, promptSteps);
promptSteps.push(new FunctionAppStackStep());
if (wizardContext.advancedCreation) {
promptSteps.push(new AppServicePlanListStep())
}
if (wizardContext.version === FuncVersion.v1) { // v1 doesn't support linux
wizardContext.newSiteOS = WebsiteOS.windows;
}
executeSteps.push(new FunctionAppCreateStep());
return { promptSteps, executeSteps };
}
async function createContainerizedFunctionAppWizard(): Promise<{ promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[], executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] }> {
const promptSteps: AzureWizardPromptStep<IAppServiceWizardContext>[] = [];
const executeSteps: AzureWizardExecuteStep<IAppServiceWizardContext>[] = [];
executeSteps.push(new DeployWorkspaceProjectStep());
executeSteps.push(new ContainerizedFunctionAppCreateStep());
return { promptSteps, executeSteps };
}
function getAvailableFunctionAppHostingPlans(context: IFunctionAppWizardContext): Set<FunctionAppHostingPlans> {
const availablePlans: Set<FunctionAppHostingPlans> = new Set();
switch (true) {
case context.useFlexConsumptionPlan:
availablePlans.add(FunctionAppHostingPlans.Flex);
break;
case context.durableStorageType === DurableBackend.DTS:
if (context.advancedCreation) {
availablePlans.add(FunctionAppHostingPlans.Premium);
}
availablePlans.add(FunctionAppHostingPlans.Flex);
break;
default:
return allAvailableFunctionAppHostingPlans;
}
return availablePlans;
}