-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcreateContainerApp.ts
More file actions
92 lines (76 loc) · 4.32 KB
/
createContainerApp.ts
File metadata and controls
92 lines (76 loc) · 4.32 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
/*---------------------------------------------------------------------------------------------
* 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, VerifyProvidersStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, IActionContext, createSubscriptionContext, nonNullProp, nonNullValue, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import { webProvider } from "../../constants";
import { ext } from "../../extensionVariables";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
import { createActivityContext } from "../../utils/activity/activityUtils";
import { isAzdExtensionInstalled } from "../../utils/azdUtils";
import { localize } from "../../utils/localize";
import { pickEnvironment } from "../../utils/pickItem/pickEnvironment";
import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep";
import { IngressPromptStep } from "../ingress/IngressPromptStep";
import { ContainerAppCreateStep } from "./ContainerAppCreateStep";
import { ContainerAppNameStep } from "./ContainerAppNameStep";
import type { CreateContainerAppContext } from "./CreateContainerAppContext";
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: CreateContainerAppContext = {
...context,
...createSubscriptionContext(node.subscription),
...await createActivityContext(),
subscription: node.subscription,
managedEnvironmentId: node.managedEnvironment.id,
alwaysPromptIngress: true
};
const title: string = localize('createContainerApp', 'Create container app');
const promptSteps: AzureWizardPromptStep<CreateContainerAppContext>[] = [
new ContainerAppNameStep(),
new ImageSourceListStep(),
new IngressPromptStep(),
];
const executeSteps: AzureWizardExecuteStep<CreateContainerAppContext>[] = [
new VerifyProvidersStep([webProvider]),
new ContainerAppCreateStep(),
];
if (isAzdExtensionInstalled()) {
context.telemetry.properties.isAzdWorkspaceProject = '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<CreateContainerAppContext> = new AzureWizard(wizardContext, {
title,
promptSteps,
executeSteps,
showLoadingPrompt: true
});
// we want to add the quick start image _only_ for the create scenairo
wizardContext.showQuickStartImage = 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);
}