-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcreateContainerApp.ts
More file actions
80 lines (68 loc) · 4 KB
/
createContainerApp.ts
File metadata and controls
80 lines (68 loc) · 4 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { LocationListStep, VerifyProvidersStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, IActionContext, ICreateChildImplContext, createSubscriptionContext, nonNullProp } 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/activityUtils";
import { localize } from "../../utils/localize";
import { containerAppEnvironmentExperience } from "../../utils/pickContainerApp";
import { ImageSourceListStep } from "../deploy/ImageSourceListStep";
import { ContainerAppCreateStep } from "./ContainerAppCreateStep";
import { ContainerAppNameStep } from "./ContainerAppNameStep";
import { EnableIngressStep } from "./EnableIngressStep";
import { IContainerAppContext, IContainerAppWithActivityContext } from "./IContainerAppContext";
import { showContainerAppCreated } from "./showContainerAppCreated";
export async function createContainerApp(context: IActionContext & Partial<ICreateChildImplContext> & Partial<IContainerAppContext>, node?: ManagedEnvironmentItem): Promise<ContainerAppItem> {
node ??= await containerAppEnvironmentExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider, {
title: localize('createContainerApp', 'Create Container App'),
});
const wizardContext: IContainerAppWithActivityContext = {
...context,
...createSubscriptionContext(node.subscription),
subscription: node.subscription,
managedEnvironmentId: node.managedEnvironment.id,
...(await createActivityContext())
};
const title: string = localize('createContainerApp', 'Create Container App');
const promptSteps: AzureWizardPromptStep<IContainerAppWithActivityContext>[] = [
new ContainerAppNameStep(),
new ImageSourceListStep(),
new EnableIngressStep(),
];
const executeSteps: AzureWizardExecuteStep<IContainerAppWithActivityContext>[] = [
new VerifyProvidersStep([webProvider]),
new ContainerAppCreateStep(),
];
wizardContext.newResourceGroupName = node.resource.resourceGroup;
await LocationListStep.setLocation(wizardContext, nonNullProp(node.resource, 'location'));
const wizard: AzureWizard<IContainerAppWithActivityContext> = new AzureWizard(wizardContext, {
title,
promptSteps,
executeSteps,
showLoadingPrompt: true
});
// we want to add the quick start image _only_ for the create scenairo
wizardContext.useQuickStartImage = true;
await wizard.prompt();
const newContainerAppName = nonNullProp(wizardContext, 'newContainerAppName');
await ext.state.showCreatingChild(
node.managedEnvironment.id,
localize('creatingContainerApp', 'Creating Container App "{0}"...', newContainerAppName),
async () => {
wizardContext.activityTitle = localize('createNamedContainerApp', 'Create Container App "{0}"', newContainerAppName);
try {
await wizard.execute();
} finally {
// refresh this node even if create fails because container app provision failure throws an error, but still creates a container app
// ext.state.notifyChildrenChanged(node.managedEnvironment.id);
}
});
const createdContainerApp = nonNullProp(wizardContext, 'containerApp');
void showContainerAppCreated(createdContainerApp);
return new ContainerAppItem(node.subscription, createdContainerApp);
}