-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProjectApi.ts
More file actions
100 lines (86 loc) · 5.83 KB
/
deployWorkspaceProjectApi.ts
File metadata and controls
100 lines (86 loc) · 5.83 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type ResourceGroup } from "@azure/arm-resources";
import { LocationListStep, ResourceGroupListStep, parseAzureResourceGroupId } from "@microsoft/vscode-azext-azureutils";
import { callWithTelemetryAndErrorHandling, createSubscriptionContext, nonNullValueAndProp, subscriptionExperience, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { type AzureSubscription } from "@microsoft/vscode-azureresources-api";
import { Uri, type WorkspaceFolder } from "vscode";
import { ext } from "../../extensionVariables";
import { getWorkspaceFolderFromPath } from "../../utils/workspaceUtils";
import { ManagedEnvironmentNameStep } from "../createManagedEnvironment/ManagedEnvironmentNameStep";
import { type DeployWorkspaceProjectContext } from "../deployWorkspaceProject/DeployWorkspaceProjectContext";
import { getDeployWorkspaceProjectResults, type DeployWorkspaceProjectResults } from "../deployWorkspaceProject/getDeployWorkspaceProjectResults";
import { type DeployWorkspaceProjectInternalContext } from "../deployWorkspaceProject/internal/DeployWorkspaceProjectInternalContext";
import { deployWorkspaceProjectInternal } from "../deployWorkspaceProject/internal/deployWorkspaceProjectInternal";
import { RegistryCredentialType } from "../registryCredentials/RegistryCredentialsAddConfigurationListStep";
import type * as api from "./vscode-azurecontainerapps.api";
export async function deployWorkspaceProjectApi(deployWorkspaceProjectOptions: api.DeployWorkspaceProjectOptionsContract): Promise<DeployWorkspaceProjectResults> {
return await callWithTelemetryAndErrorHandling('containerApps.api.deployWorkspaceProject', async (context: IActionContext): Promise<DeployWorkspaceProjectResults> => {
context.errorHandling.rethrow = true;
const {
resourceGroupId,
location,
rootPath,
dockerfilePath,
srcPath,
suppressConfirmation,
suppressContainerAppCreation,
shouldSaveDeploySettings
} = deployWorkspaceProjectOptions;
const subscription: AzureSubscription = await subscriptionExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider, {
selectBySubscriptionId: getSubscriptionIdFromOptions(deployWorkspaceProjectOptions),
showLoadingPrompt: false
});
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription);
const rootFolder: WorkspaceFolder | undefined = rootPath ? getWorkspaceFolderFromPath(rootPath) : undefined;
const resourceGroup: ResourceGroup | undefined = resourceGroupId ? await getResourceGroupFromId({ ...context, ...subscriptionContext }, resourceGroupId) : undefined;
const deployWorkspaceProjectInternalContext: DeployWorkspaceProjectInternalContext = Object.assign(context, {
...subscriptionContext,
subscription,
resourceGroup,
newManagedEnvironmentName: await tryGetNewManagedEnvironmentName({ ...context, ...subscriptionContext }, resourceGroup?.name, resourceGroup?.name),
rootFolder,
srcPath: srcPath ? Uri.file(srcPath).fsPath : undefined,
dockerfilePath: dockerfilePath ? Uri.file(dockerfilePath).fsPath : undefined,
newRegistryCredentialType: RegistryCredentialType.DockerLogin,
shouldSaveDeploySettings: !!shouldSaveDeploySettings,
});
if (location || deployWorkspaceProjectInternalContext.resourceGroup) {
const autoSelectLocation = location ?? nonNullValueAndProp(deployWorkspaceProjectInternalContext.resourceGroup, 'location');
await LocationListStep.setAutoSelectLocation(deployWorkspaceProjectInternalContext, autoSelectLocation);
}
const deployWorkspaceProjectContext: DeployWorkspaceProjectContext = await deployWorkspaceProjectInternal(deployWorkspaceProjectInternalContext, {
advancedCreate: false,
suppressActivity: true,
suppressConfirmation,
suppressContainerAppCreation,
suppressProgress: true,
suppressWizardTitle: true,
});
return await getDeployWorkspaceProjectResults(deployWorkspaceProjectContext);
}) ?? {};
}
async function tryGetNewManagedEnvironmentName(context: ISubscriptionActionContext, resourceGroupName?: string, newEnvironmentName?: string): Promise<string | undefined> {
if (!resourceGroupName || !newEnvironmentName) {
return undefined;
}
if (!ManagedEnvironmentNameStep.validateInput(newEnvironmentName) && await ManagedEnvironmentNameStep.isNameAvailable(context, resourceGroupName, newEnvironmentName)) {
return newEnvironmentName;
}
return undefined;
}
function getSubscriptionIdFromOptions(deployWorkspaceProjectOptions: api.DeployWorkspaceProjectOptionsContract): string | undefined {
if (deployWorkspaceProjectOptions.subscriptionId) {
return deployWorkspaceProjectOptions.subscriptionId;
} else if (deployWorkspaceProjectOptions.resourceGroupId) {
return parseAzureResourceGroupId(deployWorkspaceProjectOptions.resourceGroupId).subscriptionId as string;
} else {
return undefined;
}
}
async function getResourceGroupFromId(context: ISubscriptionActionContext, resourceGroupId: string): Promise<ResourceGroup | undefined> {
const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(context);
return resourceGroups.find(rg => rg.id === resourceGroupId);
}