-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProject.ts
More file actions
103 lines (89 loc) · 6.34 KB
/
deployWorkspaceProject.ts
File metadata and controls
103 lines (89 loc) · 6.34 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { parseAzureResourceId } from "@microsoft/vscode-azext-azureutils";
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/deployWorkspaceProjectTelemetryProps";
import { ContainerAppItem, isIngressEnabled, type ContainerAppModel } from "../../tree/ContainerAppItem";
import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
import { localize } from "../../utils/localize";
import { type IContainerAppContext } from "../IContainerAppContext";
import { type DeployWorkspaceProjectResults } from "../api/vscode-azurecontainerapps.api";
import { browseContainerApp } from "../browseContainerApp";
import { type DeployWorkspaceProjectContext } from "./DeployWorkspaceProjectContext";
import { type DeploymentConfiguration } from "./deploymentConfiguration/DeploymentConfiguration";
import { getTreeItemDeploymentConfiguration } from "./deploymentConfiguration/getTreeItemDeploymentConfiguration";
import { getWorkspaceDeploymentConfiguration } from "./deploymentConfiguration/workspace/getWorkspaceDeploymentConfiguration";
import { formatSectionHeader } from "./formatSectionHeader";
import { getDeployWorkspaceProjectResults } from "./getDeployWorkspaceProjectResults";
import { type DeployWorkspaceProjectInternalContext } from "./internal/DeployWorkspaceProjectInternalContext";
import { deployWorkspaceProjectInternal } from "./internal/deployWorkspaceProjectInternal";
import { convertV1ToV2SettingsSchema } from "./settings/convertSettings/convertV1ToV2SettingsSchema";
export const deployWorkspaceProjectCommandName: string = localize('deployWorkspaceProject', 'Deploy Project from Workspace...');
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 = item?.subscription ?? await subscriptionExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider);
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription);
const containerAppContext: IContainerAppContext = Object.assign(context, {
...subscriptionContext,
subscription
});
ext.outputChannel.appendLog(
formatSectionHeader(localize('prepareDeploymentConfiguration', 'Prepare workspace deployment configuration'))
);
let deploymentConfiguration: DeploymentConfiguration;
if (item) {
ext.outputChannel.appendLog(localize('treeItemConfiguration', 'Loading deployment configuration from user provided tree item "{0}".', parseAzureResourceId(item.id).resourceName));
deploymentConfiguration = await getTreeItemDeploymentConfiguration({ ...containerAppContext }, item);
} else {
const { rootFolder } = await convertV1ToV2SettingsSchema({ ...containerAppContext });
deploymentConfiguration = await getWorkspaceDeploymentConfiguration({ ...containerAppContext, rootFolder });
}
context.telemetry.properties.choseExistingWorkspaceConfiguration = deploymentConfiguration.configurationIdx !== undefined ? 'true' : 'false';
const deployWorkspaceProjectInternalContext: DeployWorkspaceProjectInternalContext = Object.assign(containerAppContext, {
...deploymentConfiguration,
});
const deployWorkspaceProjectContext: DeployWorkspaceProjectContext = await deployWorkspaceProjectInternal(deployWorkspaceProjectInternalContext, {
suppressActivity: false,
suppressConfirmation: false,
suppressContainerAppCreation: false,
suppressProgress: false,
suppressWizardTitle: false
});
displayNotification(deployWorkspaceProjectContext);
return await getDeployWorkspaceProjectResults(deployWorkspaceProjectContext);
}
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}`));
}
}