diff --git a/src/commands/createContainerApp/ContainerAppCreateStartingResourcesLogStep.ts b/src/commands/createContainerApp/ContainerAppCreateStartingResourcesLogStep.ts deleted file mode 100644 index 1a4bb865..00000000 --- a/src/commands/createContainerApp/ContainerAppCreateStartingResourcesLogStep.ts +++ /dev/null @@ -1,26 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { type ResourceGroup } from "@azure/arm-resources"; -import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils"; -import { nonNullValue, nonNullValueAndProp } from "@microsoft/vscode-azext-utils"; -import { type ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem"; -import { StartingResourcesLogStep } from "../StartingResourcesLogStep"; -import { type ContainerAppCreateContext } from "./ContainerAppCreateContext"; - -export class ContainerAppCreateStartingResourcesLogStep extends StartingResourcesLogStep { - constructor(readonly parentItem: ManagedEnvironmentItem) { - super(); - } - - async configureStartingResources(context: T): Promise { - // Use the same resource group and location as the parent resource (managed environment) - const resourceGroupName: string = nonNullValueAndProp(this.parentItem.resource, 'resourceGroup'); - const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(context); - context.resourceGroup = nonNullValue(resourceGroups.find(rg => rg.name === resourceGroupName)); - - await LocationListStep.setLocation(context, nonNullValueAndProp(this.parentItem.resource, 'location')); - } -} diff --git a/src/commands/createContainerApp/createContainerApp.ts b/src/commands/createContainerApp/createContainerApp.ts index 75cad165..d48fe606 100644 --- a/src/commands/createContainerApp/createContainerApp.ts +++ b/src/commands/createContainerApp/createContainerApp.ts @@ -3,7 +3,9 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { AzureWizard, createSubscriptionContext, nonNullProp, type IActionContext } from "@microsoft/vscode-azext-utils"; +import { type ResourceGroup } from "@azure/arm-resources"; +import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils"; +import { AzureWizard, createSubscriptionContext, nonNullProp, nonNullValue, nonNullValueAndProp, type IActionContext } from "@microsoft/vscode-azext-utils"; import { ImageSource } from "../../constants"; import { ext } from "../../extensionVariables"; import { ContainerAppItem } from "../../tree/ContainerAppItem"; @@ -15,25 +17,24 @@ import { localize } from "../../utils/localize"; import { pickEnvironment } from "../../utils/pickItem/pickEnvironment"; import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep"; import { type ContainerAppCreateContext } from "./ContainerAppCreateContext"; -import { ContainerAppCreateStartingResourcesLogStep } from "./ContainerAppCreateStartingResourcesLogStep"; import { ContainerAppCreateStep } from "./ContainerAppCreateStep"; import { ContainerAppNameStep } from "./ContainerAppNameStep"; import { showContainerAppNotification } from "./showContainerAppNotification"; -export async function createContainerApp(context: IActionContext, item?: ManagedEnvironmentItem): Promise { +export async function createContainerApp(context: IActionContext, node?: ManagedEnvironmentItem): Promise { // If an incompatible tree item is passed, treat it as if no item was passed - if (item && !ManagedEnvironmentItem.isManagedEnvironmentItem(item)) { - item = undefined; + if (node && !ManagedEnvironmentItem.isManagedEnvironmentItem(node)) { + node = undefined; } - item ??= await pickEnvironment(context); + node ??= await pickEnvironment(context); const wizardContext: ContainerAppCreateContext = { ...context, - ...createSubscriptionContext(item.subscription), + ...createSubscriptionContext(node.subscription), ...await createActivityContext(true), - subscription: item.subscription, - managedEnvironment: item.managedEnvironment, + subscription: node.subscription, + managedEnvironment: node.managedEnvironment, imageSource: ImageSource.QuickstartImage, }; @@ -41,10 +42,16 @@ export async function createContainerApp(context: IActionContext, item?: Managed wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; } + // Use the same resource group and location as the parent resource (managed environment) + const resourceGroupName: string = nonNullValueAndProp(node.resource, 'resourceGroup'); + const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(wizardContext); + wizardContext.resourceGroup = nonNullValue(resourceGroups.find(rg => rg.name === resourceGroupName)); + + await LocationListStep.setLocation(wizardContext, nonNullProp(node.resource, 'location')); + const wizard: AzureWizard = new AzureWizard(wizardContext, { title: localize('createContainerApp', 'Create container app'), promptSteps: [ - new ContainerAppCreateStartingResourcesLogStep(item), new ContainerAppNameStep(), new ImageSourceListStep(), ], @@ -58,7 +65,7 @@ export async function createContainerApp(context: IActionContext, item?: Managed const newContainerAppName = nonNullProp(wizardContext, 'newContainerAppName'); await ext.state.showCreatingChild( - item.managedEnvironment.id, + node.managedEnvironment.id, localize('creating', 'Creating "{0}"...', newContainerAppName), async () => { wizardContext.activityTitle = localize('createNamedContainerApp', 'Create container app "{0}"', newContainerAppName); @@ -71,5 +78,5 @@ export async function createContainerApp(context: IActionContext, item?: Managed void showContainerAppNotification(createdContainerApp); } - return new ContainerAppItem(item.subscription, createdContainerApp); + return new ContainerAppItem(node.subscription, createdContainerApp); } diff --git a/src/commands/deployContainerApp/ContainerAppDeployStartingResourcesLogStep.ts b/src/commands/deployContainerApp/ContainerAppDeployStartingResourcesLogStep.ts deleted file mode 100644 index 02f7facf..00000000 --- a/src/commands/deployContainerApp/ContainerAppDeployStartingResourcesLogStep.ts +++ /dev/null @@ -1,22 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import { type ResourceGroup } from "@azure/arm-resources"; -import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils"; -import { nonNullValue, nonNullValueAndProp } from "@microsoft/vscode-azext-utils"; -import { localize } from "../../utils/localize"; -import { StartingResourcesLogStep } from "../StartingResourcesLogStep"; -import { type ContainerAppDeployContext } from "./ContainerAppDeployContext"; - -export class ContainerAppDeployStartingResourcesLogStep extends StartingResourcesLogStep { - async configureStartingResources(context: T): Promise { - const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(context); - context.resourceGroup = nonNullValue( - resourceGroups.find(rg => rg.name === context.containerApp?.resourceGroup), - localize('containerAppResourceGroup', 'Expected to find the container app\'s resource group.'), - ); - await LocationListStep.setLocation(context, nonNullValueAndProp(context.containerApp, 'location')); - } -} diff --git a/src/commands/deployContainerApp/deployContainerApp.ts b/src/commands/deployContainerApp/deployContainerApp.ts index 5a877994..b4afee9a 100644 --- a/src/commands/deployContainerApp/deployContainerApp.ts +++ b/src/commands/deployContainerApp/deployContainerApp.ts @@ -4,8 +4,11 @@ *--------------------------------------------------------------------------------------------*/ import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers"; -import { AzureWizard, createSubscriptionContext, nonNullProp, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; +import { type ResourceGroup } from "@azure/arm-resources"; +import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils"; +import { activityInfoIcon, activitySuccessContext, AzureWizard, createSubscriptionContext, createUniversallyUniqueContextValue, GenericTreeItem, nonNullProp, nonNullValue, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; import { ImageSource } from "../../constants"; +import { ext } from "../../extensionVariables"; import { type ContainerAppItem } from "../../tree/ContainerAppItem"; import { createActivityContext } from "../../utils/activityUtils"; import { isAzdExtensionInstalled } from "../../utils/azdUtils"; @@ -18,7 +21,6 @@ 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...'); @@ -55,10 +57,37 @@ export async function deployContainerApp(context: IActionContext, node?: Contain wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; } + const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(wizardContext); + wizardContext.resourceGroup = nonNullValue( + resourceGroups.find(rg => rg.name === item.containerApp.resourceGroup), + localize('containerAppResourceGroup', 'Expected to find the container app\'s resource group.'), + ); + + // Log resource group + wizardContext.activityChildren?.push( + new GenericTreeItem(undefined, { + contextValue: createUniversallyUniqueContextValue(['useExistingResourceGroupInfoItem', activitySuccessContext]), + label: localize('useResourceGroup', 'Using resource group "{0}"', wizardContext.resourceGroup.name), + iconPath: activityInfoIcon + }) + ); + ext.outputChannel.appendLog(localize('usingResourceGroup', 'Using resource group "{0}".', wizardContext.resourceGroup.name)); + + // Log container app + wizardContext.activityChildren?.push( + new GenericTreeItem(undefined, { + contextValue: createUniversallyUniqueContextValue(['useExistingContainerAppInfoItem', activitySuccessContext]), + label: localize('useContainerApp', 'Using container app "{0}"', wizardContext.containerApp?.name), + iconPath: activityInfoIcon + }) + ); + ext.outputChannel.appendLog(localize('usingContainerApp', 'Using container app "{0}".', wizardContext.containerApp?.name)); + + await LocationListStep.setLocation(wizardContext, item.containerApp.location); + const wizard: AzureWizard = new AzureWizard(wizardContext, { title: localize('deployContainerAppTitle', 'Deploy image to container app'), promptSteps: [ - new ContainerAppDeployStartingResourcesLogStep(), new ImageSourceListStep(), ], executeSteps: [ diff --git a/src/commands/deployImage/deployImage.ts b/src/commands/deployImage/deployImage.ts index 387099a8..dcb5cb9b 100644 --- a/src/commands/deployImage/deployImage.ts +++ b/src/commands/deployImage/deployImage.ts @@ -3,7 +3,10 @@ * Licensed under the MIT License. See License.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { AzureWizard, createSubscriptionContext, nonNullValueAndProp, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; +import { type ResourceGroup } from "@azure/arm-resources"; +import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils"; +import { activityInfoIcon, activitySuccessContext, AzureWizard, createSubscriptionContext, createUniversallyUniqueContextValue, GenericTreeItem, nonNullValue, nonNullValueAndProp, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; +import { ext } from "../../extensionVariables"; import { type ContainerItem } from "../../tree/containers/ContainerItem"; import { createActivityContext } from "../../utils/activityUtils"; import { isAzdExtensionInstalled } from "../../utils/azdUtils"; @@ -13,7 +16,6 @@ import { localize } from "../../utils/localize"; import { getParentResource } from "../../utils/revisionDraftUtils"; import { ContainerAppOverwriteConfirmStep } from "../ContainerAppOverwriteConfirmStep"; import { showContainerAppNotification } from "../createContainerApp/showContainerAppNotification"; -import { ContainerAppDeployStartingResourcesLogStep } from "../deployContainerApp/ContainerAppDeployStartingResourcesLogStep"; import { ContainerAppUpdateStep } from "../image/imageSource/ContainerAppUpdateStep"; import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep"; import { type ContainerRegistryImageSourceContext } from "../image/imageSource/containerRegistry/ContainerRegistryImageSourceContext"; @@ -38,11 +40,38 @@ export async function deployImage(context: IActionContext & Partial rg.name === containerApp.resourceGroup), + localize('containerAppResourceGroup', 'Expected to find the container app\'s resource group.'), + ); + + // Log resource group + wizardContext.activityChildren?.push( + new GenericTreeItem(undefined, { + contextValue: createUniversallyUniqueContextValue(['useExistingResourceGroupInfoItem', activitySuccessContext]), + label: localize('useResourceGroup', 'Using resource group "{0}"', wizardContext.resourceGroup.name), + iconPath: activityInfoIcon + }) + ); + ext.outputChannel.appendLog(localize('usingResourceGroup', 'Using resource group "{0}".', wizardContext.resourceGroup.name)); + + // Log container app + wizardContext.activityChildren?.push( + new GenericTreeItem(undefined, { + contextValue: createUniversallyUniqueContextValue(['useExistingContainerAppInfoItem', activitySuccessContext]), + label: localize('useContainerApp', 'Using container app "{0}"', wizardContext.containerApp?.name), + iconPath: activityInfoIcon + }) + ); + ext.outputChannel.appendLog(localize('usingContainerApp', 'Using container app "{0}".', wizardContext.containerApp?.name)); + + await LocationListStep.setLocation(wizardContext, containerApp.location); + const parentResourceName: string = getParentResource(containerApp, node.revision).name ?? containerApp.name; const wizard: AzureWizard = new AzureWizard(wizardContext, { title: localize('deployImageTitle', 'Deploy image to "{0}"', parentResourceName), promptSteps: [ - new ContainerAppDeployStartingResourcesLogStep(), new ImageSourceListStep(), new ContainerAppOverwriteConfirmStep(), ],