-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProject.ts
More file actions
206 lines (168 loc) · 10.2 KB
/
deployWorkspaceProject.ts
File metadata and controls
206 lines (168 loc) · 10.2 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
204
205
206
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { LocationListStep, ResourceGroupCreateStep, VerifyProvidersStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, GenericTreeItem, IActionContext, ISubscriptionContext, createSubscriptionContext, nonNullProp, nonNullValueAndProp, subscriptionExperience } from "@microsoft/vscode-azext-utils";
import type { AzureSubscription } from "@microsoft/vscode-azureresources-api";
import { ProgressLocation, window } from "vscode";
import { activityInfoIcon, activitySuccessContext, appProvider, managedEnvironmentsId, operationalInsightsProvider, webProvider } from "../../constants";
import { ext } from "../../extensionVariables";
import { ContainerAppItem, ContainerAppModel, isIngressEnabled } from "../../tree/ContainerAppItem";
import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
import { createActivityChildContext, createActivityContext } from "../../utils/activity/activityUtils";
import { localize } from "../../utils/localize";
import { browseContainerApp } from "../browseContainerApp";
import { ContainerAppCreateStep } from "../createContainerApp/ContainerAppCreateStep";
import { LogAnalyticsCreateStep } from "../createManagedEnvironment/LogAnalyticsCreateStep";
import { ManagedEnvironmentCreateStep } from "../createManagedEnvironment/ManagedEnvironmentCreateStep";
import { ContainerAppOverwriteConfirmStep } from "../deployImage/ContainerAppOverwriteConfirmStep";
import { ContainerAppUpdateStep } from "../deployImage/ContainerAppUpdateStep";
import { ImageSourceListStep } from "../deployImage/imageSource/ImageSourceListStep";
import { IngressPromptStep } from "../ingress/IngressPromptStep";
import { DeployWorkspaceProjectConfirmStep } from "./DeployWorkspaceProjectConfirmStep";
import type { DeployWorkspaceProjectContext } from "./DeployWorkspaceProjectContext";
import { DeployWorkspaceProjectSaveSettingsStep } from "./DeployWorkspaceProjectSaveSettingsStep";
import { ShouldSaveDeploySettingsPromptStep } from "./ShouldSaveDeploySettingsPromptStep";
import { DefaultResourcesNameStep } from "./getDefaultValues/DefaultResourcesNameStep";
import { getDefaultContextValues } from "./getDefaultValues/getDefaultContextValues";
export async function deployWorkspaceProject(context: IActionContext, item?: ContainerAppItem | ManagedEnvironmentItem): Promise<void> {
ext.outputChannel.appendLog(localize('beginCommandExecution', '--------Initializing deploy workspace project--------'));
const subscription: AzureSubscription = await subscriptionExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider);
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription);
// Show loading indicator while we configure default values
let defaultContextValues: Partial<DeployWorkspaceProjectContext> | undefined;
await window.withProgress({
location: ProgressLocation.Notification,
cancellable: false,
title: localize('loadingWorkspaceTitle', 'Loading workspace project deployment configurations...')
}, async () => {
defaultContextValues = await getDefaultContextValues({ ...context, ...subscriptionContext }, item);
});
const wizardContext: DeployWorkspaceProjectContext = {
...context,
...subscriptionContext,
...await createActivityContext(),
...defaultContextValues,
activityChildren: [],
subscription,
};
const promptSteps: AzureWizardPromptStep<DeployWorkspaceProjectContext>[] = [
new DeployWorkspaceProjectConfirmStep(),
new DefaultResourcesNameStep()
];
const executeSteps: AzureWizardExecuteStep<DeployWorkspaceProjectContext>[] = [
new DeployWorkspaceProjectSaveSettingsStep()
];
const providers: string[] = [];
// Resource group
if (wizardContext.resourceGroup) {
const resourceGroupName: string = nonNullValueAndProp(wizardContext.resourceGroup, 'name');
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['useExistingResourceGroup', activitySuccessContext]),
label: localize('useResourceGroup', 'Using resource group "{0}"', resourceGroupName),
iconPath: activityInfoIcon
})
);
await LocationListStep.setLocation(wizardContext, wizardContext.resourceGroup.location);
ext.outputChannel.appendLog(localize('usingResourceGroup', 'Using resource group "{0}".', resourceGroupName));
} else {
executeSteps.push(new ResourceGroupCreateStep());
}
// Managed environment
if (wizardContext.managedEnvironment) {
const managedEnvironmentName: string = nonNullValueAndProp(wizardContext.managedEnvironment, 'name');
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['useExistingManagedEnvironment', activitySuccessContext]),
label: localize('useManagedEnvironment', 'Using container apps environment "{0}"', managedEnvironmentName),
iconPath: activityInfoIcon
})
);
await LocationListStep.setLocation(wizardContext, wizardContext.managedEnvironment.location);
ext.outputChannel.appendLog(localize('usingManagedEnvironment', 'Using container apps environment "{0}".', managedEnvironmentName));
ext.outputChannel.appendLog(localize('useLocation', 'Using location "{0}".', wizardContext.managedEnvironment.location));
} else {
executeSteps.push(
new LogAnalyticsCreateStep(),
new ManagedEnvironmentCreateStep()
);
providers.push(
appProvider,
operationalInsightsProvider
);
LocationListStep.addProviderForFiltering(wizardContext, appProvider, managedEnvironmentsId);
LocationListStep.addStep(wizardContext, promptSteps);
}
// Azure Container Registry
if (wizardContext.registry) {
const registryName: string = nonNullValueAndProp(wizardContext.registry, 'name');
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['useExistingAcr', activitySuccessContext]),
label: localize('useAcr', 'Using container registry "{0}"', registryName),
iconPath: activityInfoIcon
})
);
ext.outputChannel.appendLog(localize('usingAcr', 'Using Azure Container Registry "{0}".', registryName));
} else {
// ImageSourceListStep can already handle this creation logic
}
// Container app
if (wizardContext.containerApp) {
const containerAppName: string = nonNullValueAndProp(wizardContext.containerApp, 'name');
promptSteps.unshift(new ContainerAppOverwriteConfirmStep());
executeSteps.push(new ContainerAppUpdateStep());
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['useExistingContainerApp', activitySuccessContext]),
label: localize('useContainerApp', 'Using container app "{0}"', containerAppName),
iconPath: activityInfoIcon
})
);
ext.outputChannel.appendLog(localize('usingContainerApp', 'Using container app "{0}".', containerAppName));
} else {
executeSteps.push(new ContainerAppCreateStep());
}
promptSteps.push(
new ImageSourceListStep(),
new IngressPromptStep(),
);
providers.push(webProvider);
// Verify providers
executeSteps.push(new VerifyProvidersStep(providers));
// Save deploy settings
promptSteps.push(new ShouldSaveDeploySettingsPromptStep());
const wizard: AzureWizard<DeployWorkspaceProjectContext> = new AzureWizard(wizardContext, {
title: localize('deployWorkspaceProjectTitle', 'Deploy workspace project to a container app'),
promptSteps,
executeSteps,
showLoadingPrompt: true
});
await wizard.prompt();
wizardContext.activityTitle = localize('deployWorkspaceProjectActivityTitle', 'Deploy workspace project to container app "{0}"', wizardContext.containerApp?.name || nonNullProp(wizardContext, 'newContainerAppName'));
ext.outputChannel.appendLog(localize('beginCommandExecution', '--------Deploying workspace project to container app--------', wizardContext.containerApp?.name || nonNullProp(wizardContext, 'newContainerAppName')));
await wizard.execute();
displayNotification(wizardContext);
ext.branchDataProvider.refresh();
ext.outputChannel.appendLog(localize('finishCommandExecution', '--------Finished deploying workspace project to container app "{0}"--------', wizardContext.containerApp?.name));
}
function displayNotification(context: DeployWorkspaceProjectContext): void {
const browse: string = localize('browse', 'Browse');
const viewOutput: string = localize('viewOutput', 'View Output');
const message: string = localize('finishedDeploying', 'Finished deploying workspace project to container app "{0}".', context.containerApp?.name);
const buttonMessages: string[] = context.targetPort ? [browse, viewOutput] : [viewOutput];
const containerApp: ContainerAppModel = nonNullProp(context, 'containerApp');
void window.showInformationMessage(message, ...buttonMessages).then(async (result: string | undefined) => {
if (result === viewOutput) {
ext.outputChannel.show();
} else if (result === browse) {
await browseContainerApp(containerApp);
}
});
// Provide browse link automatically to output channel
if (isIngressEnabled(containerApp)) {
ext.outputChannel.appendLog(localize('browseContainerApp', 'Deployed to: {0}', `https://${containerApp.configuration.ingress.fqdn}`));
}
}