-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcreateContainerApp.ts
More file actions
82 lines (71 loc) · 3.99 KB
/
createContainerApp.ts
File metadata and controls
82 lines (71 loc) · 3.99 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ResourceGroup } from "@azure/arm-resources";
import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, createSubscriptionContext, nonNullProp, nonNullValue, nonNullValueAndProp, type IActionContext } from "@microsoft/vscode-azext-utils";
import { ImageSource } from "../../constants";
import { ext } from "../../extensionVariables";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
import { createActivityContext } from "../../utils/activityUtils";
import { isAzdExtensionInstalled } from "../../utils/azdUtils";
import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep";
import { localize } from "../../utils/localize";
import { pickEnvironment } from "../../utils/pickItem/pickEnvironment";
import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep";
import { type ContainerAppCreateContext } from "./ContainerAppCreateContext";
import { ContainerAppCreateStep } from "./ContainerAppCreateStep";
import { ContainerAppNameStep } from "./ContainerAppNameStep";
import { showContainerAppNotification } from "./showContainerAppNotification";
export async function createContainerApp(context: IActionContext, node?: ManagedEnvironmentItem): Promise<ContainerAppItem> {
// If an incompatible tree item is passed, treat it as if no item was passed
if (node && !ManagedEnvironmentItem.isManagedEnvironmentItem(node)) {
node = undefined;
}
node ??= await pickEnvironment(context);
const wizardContext: ContainerAppCreateContext = {
...context,
...createSubscriptionContext(node.subscription),
...await createActivityContext(true),
subscription: node.subscription,
managedEnvironment: node.managedEnvironment,
imageSource: ImageSource.QuickstartImage,
};
if (isAzdExtensionInstalled()) {
wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true';
}
// Use the same resource group and location as the parent resource (managed environment)
const resourceGroupName: string = nonNullValueAndProp(node.resource, 'resourceGroup');
const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(wizardContext);
wizardContext.resourceGroup = nonNullValue(resourceGroups.find(rg => rg.name === resourceGroupName));
await LocationListStep.setLocation(wizardContext, nonNullProp(node.resource, 'location'));
const wizard: AzureWizard<ContainerAppCreateContext> = new AzureWizard(wizardContext, {
title: localize('createContainerApp', 'Create container app'),
promptSteps: [
new ContainerAppNameStep(),
new ImageSourceListStep(),
],
executeSteps: [
getVerifyProvidersStep<ContainerAppCreateContext>(),
new ContainerAppCreateStep(),
],
showLoadingPrompt: true
});
await wizard.prompt();
const newContainerAppName = nonNullProp(wizardContext, 'newContainerAppName');
await ext.state.showCreatingChild(
node.managedEnvironment.id,
localize('creating', 'Creating "{0}"...', newContainerAppName),
async () => {
wizardContext.activityTitle = localize('createNamedContainerApp', 'Create container app "{0}"', newContainerAppName);
await wizard.execute();
}
);
const createdContainerApp = nonNullProp(wizardContext, 'containerApp');
if (!wizardContext.suppressNotification) {
void showContainerAppNotification(createdContainerApp);
}
return new ContainerAppItem(node.subscription, createdContainerApp);
}