-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployContainerApp.ts
More file actions
105 lines (91 loc) · 6.62 KB
/
deployContainerApp.ts
File metadata and controls
105 lines (91 loc) · 6.62 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
import { AzureWizard, createSubscriptionContext, nonNullProp, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { ImageSource } from "../../constants";
import { type ContainerAppItem } from "../../tree/ContainerAppItem";
import { createActivityContext } from "../../utils/activityUtils";
import { isAzdExtensionInstalled } from "../../utils/azdUtils";
import { getManagedEnvironmentFromContainerApp } from "../../utils/getResourceUtils";
import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep";
import { localize } from "../../utils/localize";
import { pickContainerApp } from "../../utils/pickItem/pickContainerApp";
import { OpenConfirmationViewStep } from "../../webviews/OpenConfirmationViewStep";
import { ContainerAppOverwriteConfirmStep } from "../ContainerAppOverwriteConfirmStep";
import { deployWorkspaceProject } from "../deployWorkspaceProject/deployWorkspaceProject";
import { editContainerCommandName } from "../editContainer/editContainer";
import { ContainerAppUpdateStep } from "../image/imageSource/ContainerAppUpdateStep";
import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep";
import { type ContainerAppDeployContext } from "./ContainerAppDeployContext";
import { ContainerAppDeployStartingResourcesLogStep } from "./ContainerAppDeployStartingResourcesLogStep";
const deployContainerAppCommandName: string = localize('deployContainerApp', 'Deploy to Container App...');
export async function deployContainerApp(context: IActionContext, node?: ContainerAppItem): Promise<void> {
const item: ContainerAppItem = node ?? await pickContainerApp(context);
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(item.subscription);
const subscriptionActionContext: ISubscriptionActionContext = { ...context, ...subscriptionContext };
if (item.containerApp.revisionsMode === KnownActiveRevisionsMode.Multiple) {
throw new Error(localize('multipleRevisionsNotSupported', 'The container app cannot be updated using "{0}" while in multiple revisions mode. Navigate to the revision\'s container and execute "{1}" instead.', deployContainerAppCommandName, editContainerCommandName));
}
if ((item.containerApp.template?.containers?.length ?? 0) > 1) {
throw new Error(localize('multipleContainersNotSupported', 'The container app cannot be updated using "{0}" while having more than one active container. Navigate to the specific container instance and execute "{1}" instead.', deployContainerAppCommandName, editContainerCommandName));
}
// Prompt for image source before initializing the wizard in case we need to redirect the call to 'deployWorkspaceProject' instead
const imageSource: ImageSource = await promptImageSource(subscriptionActionContext);
if (imageSource === ImageSource.RemoteAcrBuild) {
await deployWorkspaceProject(context, item);
return;
}
const wizardContext: ContainerAppDeployContext = {
...subscriptionActionContext,
...await createActivityContext({ withChildren: true }),
subscription: item.subscription,
containerApp: item.containerApp,
managedEnvironment: await getManagedEnvironmentFromContainerApp(subscriptionActionContext, item.containerApp),
imageSource,
activityAttributes: {
description: `Deploys an existing image from a container registry to a target Azure Container App.
The container registry and image must already be available for pulling.
Supports public images from any registry, and both public and private images from Azure Container Registry (ACR).
For private image deployment from other third party registries, we support deployment through the 'vscode-containers' extension
via the command titled "Container Registries: Deploy Image to Azure Container Apps...".`,
troubleshooting: [
`If a container app resource envelope is provided in attributes, do not confuse null secrets as missing container app secrets. This is because secrets are not typically
copied over with the core resource metadata. Any issues with secrets will require inspecting the remote resource directly.`,
]
},
};
if (isAzdExtensionInstalled()) {
wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true';
}
wizardContext.telemetry.properties.revisionMode = item.containerApp.revisionsMode;
const confirmationViewTitle: string = localize('summary', 'Summary');
const confirmationViewDescription: string = localize('viewDescription', 'Please select an input you would like to change. Otherwise click "Confirm" to deploy.');
const confirmationViewTabTitle: string = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App');
const title: string = localize('deployContainerAppTitle', 'Deploy image to container app');
const wizard: AzureWizard<ContainerAppDeployContext> = new AzureWizard(wizardContext, {
title: title,
promptSteps: [
new ContainerAppDeployStartingResourcesLogStep(),
new ImageSourceListStep(),
new ContainerAppOverwriteConfirmStep(),
new OpenConfirmationViewStep(confirmationViewTitle, confirmationViewTabTitle, confirmationViewDescription, title, () => wizard.confirmationViewProperties)
],
executeSteps: [
getVerifyProvidersStep<ContainerAppDeployContext>(),
new ContainerAppUpdateStep(),
],
});
await wizard.prompt();
wizardContext.activityTitle = localize('deployContainerAppActivityTitle', 'Deploy image to container app "{0}"', wizardContext.containerApp?.name);
await wizard.execute();
wizardContext.activityAttributes ??= {};
wizardContext.activityAttributes.azureResource = wizardContext.containerApp;
}
async function promptImageSource(context: ISubscriptionActionContext): Promise<ImageSource> {
const promptContext: ISubscriptionActionContext & { imageSource?: ImageSource } = context;
const imageSourceStep: ImageSourceListStep = new ImageSourceListStep();
await imageSourceStep.prompt(promptContext);
return nonNullProp(promptContext, 'imageSource');
}