-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProject.ts
More file actions
75 lines (65 loc) · 4.47 KB
/
deployWorkspaceProject.ts
File metadata and controls
75 lines (65 loc) · 4.47 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { callWithTelemetryAndErrorHandling, createSubscriptionContext, nonNullProp, subscriptionExperience, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { type AzureSubscription } from "@microsoft/vscode-azureresources-api";
import { window } from "vscode";
import { ext } from "../../extensionVariables";
import { type SetTelemetryProps } from "../../telemetry/SetTelemetryProps";
import { type DeployWorkspaceProjectNotificationTelemetryProps as NotificationTelemetryProps } from "../../telemetry/commandTelemetryProps";
import { ContainerAppItem, isIngressEnabled, type ContainerAppModel } from "../../tree/ContainerAppItem";
import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
import { localize } from "../../utils/localize";
import { type DeployWorkspaceProjectResults } from "../api/vscode-azurecontainerapps.api";
import { browseContainerApp } from "../browseContainerApp";
import { type DeployWorkspaceProjectContext } from "./DeployWorkspaceProjectContext";
import { deployWorkspaceProjectInternal, type DeployWorkspaceProjectInternalContext } from "./deployWorkspaceProjectInternal";
import { getDeployWorkspaceProjectResults } from "./getDeployWorkspaceProjectResults";
export async function deployWorkspaceProject(context: IActionContext & Partial<DeployWorkspaceProjectContext>, item?: ContainerAppItem | ManagedEnvironmentItem): Promise<DeployWorkspaceProjectResults> {
// 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);
const deployWorkspaceProjectInternalContext: DeployWorkspaceProjectInternalContext = Object.assign(context, {
...subscriptionContext,
subscription
});
const deployWorkspaceProjectResultContext: DeployWorkspaceProjectContext = await deployWorkspaceProjectInternal(deployWorkspaceProjectInternalContext, item, {
suppressActivity: false,
suppressConfirmation: false,
suppressContainerAppCreation: false,
suppressProgress: false,
suppressWizardTitle: false
});
displayNotification(deployWorkspaceProjectResultContext);
return await getDeployWorkspaceProjectResults(deployWorkspaceProjectResultContext);
}
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}`));
}
}