-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProjectApi.ts
More file actions
81 lines (71 loc) · 5.05 KB
/
deployWorkspaceProjectApi.ts
File metadata and controls
81 lines (71 loc) · 5.05 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { type RegistryPassword } from "@azure/arm-containerregistry";
import { type ResourceGroup } from "@azure/arm-resources";
import { ResourceGroupListStep, parseAzureResourceGroupId } from "@microsoft/vscode-azext-azureutils";
import { createSubscriptionContext, 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 { deployWorkspaceProjectInternal, type DeployWorkspaceProjectInternalContext } from "../deployWorkspaceProject/deployWorkspaceProjectInternal";
import { listCredentialsFromRegistry } from "../image/imageSource/containerRegistry/acr/listCredentialsFromRegistry";
import type * as api from "./vscode-azurecontainerapps.api";
export async function deployWorkspaceProjectApi(context: IActionContext, deployWorkspaceProjectOptions: api.DeployWorkspaceProjectOptionsContract): Promise<api.DeployWorkspaceProjectResults> {
const { resourceGroupId, rootPath, dockerfilePath, srcPath, suppressConfirmation, suppressContainerAppCreation, ignoreExistingDeploySettings, 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,
rootFolder,
srcPath: srcPath ? Uri.file(srcPath).fsPath : undefined,
dockerfilePath: dockerfilePath ? Uri.file(dockerfilePath).fsPath : undefined,
suppressConfirmation,
ignoreExistingDeploySettings,
shouldSaveDeploySettings: !!shouldSaveDeploySettings,
});
const deployWorkspaceProjectResultContext = await deployWorkspaceProjectInternal(deployWorkspaceProjectInternalContext, undefined, {
// Don't show activity log updates in ACA when another client extension calls into this API.
// Let each client decide how it wants to show its own activity log updates.
suppressActivity: true,
suppressConfirmation,
suppressContainerAppCreation,
suppressProgress: true,
suppressWizardTitle: true,
});
const registryCredentials: { username: string, password: RegistryPassword } | undefined = deployWorkspaceProjectResultContext.registry ?
await listCredentialsFromRegistry(deployWorkspaceProjectResultContext, deployWorkspaceProjectResultContext.registry) : undefined;
return {
resourceGroupId: deployWorkspaceProjectResultContext.resourceGroup?.id,
logAnalyticsWorkspaceId: deployWorkspaceProjectResultContext.logAnalyticsWorkspace?.id,
managedEnvironmentId: deployWorkspaceProjectResultContext.managedEnvironment?.id,
containerAppId: deployWorkspaceProjectResultContext.containerApp?.id,
registryId: deployWorkspaceProjectResultContext.registry?.id,
registryLoginServer: deployWorkspaceProjectResultContext.registry?.loginServer,
registryUsername: registryCredentials?.username,
registryPassword: registryCredentials?.password.value,
imageName: deployWorkspaceProjectResultContext.imageName
};
}
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);
}