-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProject.ts
More file actions
245 lines (200 loc) · 12.1 KB
/
deployWorkspaceProject.ts
File metadata and controls
245 lines (200 loc) · 12.1 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*---------------------------------------------------------------------------------------------
* 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, callWithTelemetryAndErrorHandling, 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 { SetTelemetryProps } from "../../telemetry/SetTelemetryProps";
import { DeployWorkspaceProjectNotificationTelemetryProps as NotificationTelemetryProps } from "../../telemetry/commandTelemetryProps";
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 { ContainerAppUpdateStep } from "../image/imageSource/ContainerAppUpdateStep";
import { ImageSourceListStep } from "../image/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--------'));
// If an incompatible tree item is passed, treat it as if no item was passed
if (item && !ContainerAppItem.isContainerAppItem(item) && !ManagedEnvironmentItem.isManagedEnvironmentItem(item)) {
item = undefined;
}
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) {
wizardContext.telemetry.properties.existingResourceGroup = 'true';
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 {
wizardContext.telemetry.properties.existingResourceGroup = 'false';
executeSteps.push(new ResourceGroupCreateStep());
}
// Managed environment
if (wizardContext.managedEnvironment) {
wizardContext.telemetry.properties.existingEnvironment = 'true';
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
})
);
if (!LocationListStep.hasLocation(wizardContext)) {
await LocationListStep.setLocation(wizardContext, wizardContext.managedEnvironment.location);
}
ext.outputChannel.appendLog(localize('usingManagedEnvironment', 'Using container apps environment "{0}".', managedEnvironmentName));
} else {
wizardContext.telemetry.properties.existingEnvironment = 'false';
executeSteps.push(
new LogAnalyticsCreateStep(),
new ManagedEnvironmentCreateStep()
);
providers.push(
appProvider,
operationalInsightsProvider
);
}
// Azure Container Registry
if (wizardContext.registry) {
wizardContext.telemetry.properties.existingRegistry = 'true';
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 {
wizardContext.telemetry.properties.existingRegistry = 'false';
// ImageSourceListStep can already handle this creation logic
}
// Container app
if (wizardContext.containerApp) {
wizardContext.telemetry.properties.existingContainerApp = 'true';
const containerAppName: string = nonNullValueAndProp(wizardContext.containerApp, 'name');
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));
if (!LocationListStep.hasLocation(wizardContext)) {
await LocationListStep.setLocation(wizardContext, wizardContext.containerApp.location);
}
} else {
wizardContext.telemetry.properties.existingContainerApp = 'false';
executeSteps.push(new ContainerAppCreateStep());
}
promptSteps.push(
new ImageSourceListStep(),
new IngressPromptStep(),
);
providers.push(webProvider);
// Verify providers
executeSteps.push(new VerifyProvidersStep(providers));
// Location
if (LocationListStep.hasLocation(wizardContext)) {
wizardContext.telemetry.properties.existingLocation = 'true';
ext.outputChannel.appendLog(localize('useLocation', 'Using location "{0}".', (await LocationListStep.getLocation(wizardContext)).name));
} else {
wizardContext.telemetry.properties.existingLocation = 'false';
LocationListStep.addProviderForFiltering(wizardContext, appProvider, managedEnvironmentsId);
LocationListStep.addStep(wizardContext, promptSteps);
}
// 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);
wizardContext.telemetry.properties.revisionMode = wizardContext.containerApp?.revisionsMode;
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) => {
await callWithTelemetryAndErrorHandling('deployWorkspaceProject.displayNotification',
async (telemetryContext: IActionContext & SetTelemetryProps<NotificationTelemetryProps>) => {
if (result === viewOutput) {
telemetryContext.telemetry.properties.userAction = 'viewOutput';
ext.outputChannel.show();
} else if (result === browse) {
telemetryContext.telemetry.properties.userAction = 'browse';
await browseContainerApp(containerApp);
} else {
telemetryContext.telemetry.properties.userAction = 'canceled';
}
}
);
});
// Provide browse link automatically to output channel
if (isIngressEnabled(containerApp)) {
ext.outputChannel.appendLog(localize('browseContainerApp', 'Deployed to: {0}', `https://${containerApp.configuration.ingress.fqdn}`));
}
}