Skip to content

Commit 337f8b6

Browse files
authored
Add the new deployContainerApp command (#804)
1 parent 3cd1f5c commit 337f8b6

File tree

7 files changed

+100
-12
lines changed

7 files changed

+100
-12
lines changed

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
"category": "Azure Container Apps"
9797
},
9898
{
99-
"command": "containerApps.deployWorkspaceProjectToContainerApp",
100-
"title": "%containerApps.deployWorkspaceProjectToContainerApp%",
99+
"command": "containerApps.deployContainerApp",
100+
"title": "%containerApps.deployContainerApp%",
101101
"category": "Azure Container Apps"
102102
},
103103
{
@@ -377,7 +377,7 @@
377377
"group": "1@2"
378378
},
379379
{
380-
"command": "containerApps.deployWorkspaceProjectToContainerApp",
380+
"command": "containerApps.deployContainerApp",
381381
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem/i",
382382
"group": "2@1"
383383
},
@@ -587,10 +587,6 @@
587587
"command": "containerApps.createContainerAppFromWorkspace",
588588
"when": "never"
589589
},
590-
{
591-
"command": "containerApps.deployWorkspaceProjectToContainerApp",
592-
"when": "never"
593-
},
594590
{
595591
"command": "containerApps.deployWorkspaceProjectApi",
596592
"when": "never"

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"containerApps.deployImageApi": "Deploy Image to Container App (API)...",
2222
"containerApps.deployWorkspaceProject": "Deploy Project from Workspace...",
2323
"containerApps.deployWorkspaceProjectApi": "Deploy Project from Workspace (API)...",
24-
"containerApps.deployWorkspaceProjectToContainerApp": "Deploy Workspace to Container App...",
24+
"containerApps.deployContainerApp": "Deploy to Container App...",
2525
"containerApps.deleteContainerApp": "Delete Container App...",
2626
"containerApps.disableIngress": "Disable Ingress for Container App",
2727
"containerApps.enableIngress": "Enable Ingress for Container App...",

src/commands/createContainerApp/createContainerApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function createContainerApp(context: IActionContext, node?: Managed
3939
};
4040

4141
if (isAzdExtensionInstalled()) {
42-
wizardContext.telemetry.properties.isAzdWorkspaceProject = 'true';
42+
wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true';
4343
}
4444

4545
// Use the same resource group and location as the parent resource (managed environment)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { type IResourceGroupWizardContext } from '@microsoft/vscode-azext-azureutils';
7+
import { type ExecuteActivityContext } from '@microsoft/vscode-azext-utils';
8+
import { type IContainerAppContext } from '../IContainerAppContext';
9+
import { type ImageSourceBaseContext } from '../image/imageSource/ImageSourceContext';
10+
import { type IngressBaseContext } from '../ingress/IngressContext';
11+
12+
export type ContainerAppDeployContext = IResourceGroupWizardContext & ImageSourceBaseContext & IngressBaseContext & IContainerAppContext & ExecuteActivityContext;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { type ResourceGroup } from "@azure/arm-resources";
7+
import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils";
8+
import { AzureWizard, createSubscriptionContext, nonNullProp, nonNullValue, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
9+
import { ImageSource } from "../../constants";
10+
import { type ContainerAppItem } from "../../tree/ContainerAppItem";
11+
import { createActivityContext } from "../../utils/activityUtils";
12+
import { isAzdExtensionInstalled } from "../../utils/azdUtils";
13+
import { getManagedEnvironmentFromContainerApp } from "../../utils/getResourceUtils";
14+
import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep";
15+
import { localize } from "../../utils/localize";
16+
import { pickContainerApp } from "../../utils/pickItem/pickContainerApp";
17+
import { deployWorkspaceProject } from "../deployWorkspaceProject/deployWorkspaceProject";
18+
import { ContainerAppUpdateStep } from "../image/imageSource/ContainerAppUpdateStep";
19+
import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep";
20+
import { type ContainerAppDeployContext } from "./ContainerAppDeployContext";
21+
22+
export async function deployContainerApp(context: IActionContext, node?: ContainerAppItem): Promise<void> {
23+
const item: ContainerAppItem = node ?? await pickContainerApp(context);
24+
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(item.subscription);
25+
const subscriptionActionContext: ISubscriptionActionContext = { ...context, ...subscriptionContext };
26+
27+
// Prompt for image source before initializing the wizard in case we need to redirect the call to 'deployWorkspaceProject' instead
28+
const imageSource: ImageSource = await promptImageSource(subscriptionActionContext);
29+
if (imageSource === ImageSource.RemoteAcrBuild) {
30+
await deployWorkspaceProject(context, item);
31+
return;
32+
}
33+
34+
const wizardContext: ContainerAppDeployContext = {
35+
...subscriptionActionContext,
36+
...await createActivityContext(true),
37+
subscription: item.subscription,
38+
containerApp: item.containerApp,
39+
managedEnvironment: await getManagedEnvironmentFromContainerApp(subscriptionActionContext, item.containerApp),
40+
imageSource,
41+
};
42+
43+
if (isAzdExtensionInstalled()) {
44+
wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true';
45+
}
46+
47+
const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(wizardContext);
48+
wizardContext.resourceGroup = nonNullValue(
49+
resourceGroups.find(rg => rg.name === item.containerApp.resourceGroup),
50+
localize('containerAppResourceGroup', 'Expected to find the container app\'s resource group.'),
51+
);
52+
53+
await LocationListStep.setLocation(wizardContext, item.containerApp.location);
54+
55+
const wizard: AzureWizard<ContainerAppDeployContext> = new AzureWizard(wizardContext, {
56+
title: localize('deployContainerAppTitle', 'Deploy image to container app'),
57+
promptSteps: [
58+
new ImageSourceListStep(),
59+
],
60+
executeSteps: [
61+
getVerifyProvidersStep<ContainerAppDeployContext>(),
62+
new ContainerAppUpdateStep(),
63+
],
64+
showLoadingPrompt: true
65+
});
66+
67+
await wizard.prompt();
68+
wizardContext.activityTitle = localize('deployContainerAppActivityTitle', 'Deploy image to container app "{0}"', wizardContext.containerApp?.name);
69+
await wizard.execute();
70+
}
71+
72+
async function promptImageSource(context: ISubscriptionActionContext): Promise<ImageSource> {
73+
const promptContext: ISubscriptionActionContext & { imageSource?: ImageSource } = context;
74+
75+
const imageSourceStep: ImageSourceListStep = new ImageSourceListStep();
76+
await imageSourceStep.prompt(promptContext);
77+
78+
return nonNullProp(promptContext, 'imageSource');
79+
}

src/commands/image/imageSource/ImageSourceListStep.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { AzureWizardPromptStep, type AzureWizardExecuteStep, type IAzureQuickPickItem, type IWizardOptions } from "@microsoft/vscode-azext-utils";
6+
import { AzureWizardPromptStep, type AzureWizardExecuteStep, type IAzureQuickPickItem, type ISubscriptionActionContext, type IWizardOptions } from "@microsoft/vscode-azext-utils";
77
import { UIKind, env, workspace } from "vscode";
88
import { ImageSource } from "../../../constants";
99
import { localize } from "../../../utils/localize";
@@ -33,7 +33,7 @@ export class ImageSourceListStep extends AzureWizardPromptStep<ImageSourceContex
3333
super();
3434
}
3535

36-
public async prompt(context: ImageSourceContext): Promise<void> {
36+
public async prompt(context: ISubscriptionActionContext & { imageSource?: ImageSource, showQuickStartImage?: boolean }): Promise<void> {
3737
const imageSourceLabels: string[] = [
3838
localize('containerRegistryLabel', 'Container Registry'),
3939
localize('quickstartImageLabel', 'Quickstart'),

src/commands/registerCommands.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { createContainerApp } from './createContainerApp/createContainerApp';
1010
import { createManagedEnvironment } from './createManagedEnvironment/createManagedEnvironment';
1111
import { deleteContainerApp } from './deleteContainerApp/deleteContainerApp';
1212
import { deleteManagedEnvironment } from './deleteManagedEnvironment/deleteManagedEnvironment';
13+
import { deployContainerApp } from './deployContainerApp/deployContainerApp';
1314
import { deployWorkspaceProject } from './deployWorkspaceProject/deployWorkspaceProject';
1415
import { editContainer } from './editContainer/editContainer';
1516
import { editContainerImage } from './editContainer/editContainerImage/editContainerImage';
@@ -82,7 +83,7 @@ export function registerCommands(): void {
8283
registerCommandWithTreeNodeUnwrapping('containerApps.deployImageApi', deployImageApi);
8384
registerCommandWithTreeNodeUnwrapping('containerApps.deployRevisionDraft', deployRevisionDraft);
8485
registerCommandWithTreeNodeUnwrapping('containerApps.deployWorkspaceProject', deployWorkspaceProject);
85-
registerCommandWithTreeNodeUnwrapping('containerApps.deployWorkspaceProjectToContainerApp', deployWorkspaceProject);
86+
registerCommandWithTreeNodeUnwrapping('containerApps.deployContainerApp', deployContainerApp);
8687

8788
// github
8889
registerCommandWithTreeNodeUnwrapping('containerApps.connectToGitHub', connectToGitHub);

0 commit comments

Comments
 (0)