Skip to content

Commit

Permalink
Reverts commit a8c57c3 (#833)
Browse files Browse the repository at this point in the history
This reverts commit a8c57c3.
  • Loading branch information
MicroFish91 authored Jan 10, 2025
1 parent a8c57c3 commit e0fe14a
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 66 deletions.

This file was deleted.

31 changes: 19 additions & 12 deletions src/commands/createContainerApp/createContainerApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,36 +17,41 @@ 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<ContainerAppItem> {
export async function createContainerApp(context: IActionContext, node?: ManagedEnvironmentItem): Promise<ContainerAppItem> {
// 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,
};

if (isAzdExtensionInstalled()) {
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<ContainerAppCreateContext> = new AzureWizard(wizardContext, {
title: localize('createContainerApp', 'Create container app'),
promptSteps: [
new ContainerAppCreateStartingResourcesLogStep(item),
new ContainerAppNameStep(),
new ImageSourceListStep(),
],
Expand All @@ -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);
Expand All @@ -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);
}

This file was deleted.

35 changes: 32 additions & 3 deletions src/commands/deployContainerApp/deployContainerApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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...');

Expand Down Expand Up @@ -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<ContainerAppDeployContext> = new AzureWizard(wizardContext, {
title: localize('deployContainerAppTitle', 'Deploy image to container app'),
promptSteps: [
new ContainerAppDeployStartingResourcesLogStep(),
new ImageSourceListStep(),
],
executeSteps: [
Expand Down
35 changes: 32 additions & 3 deletions src/commands/deployImage/deployImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -38,11 +40,38 @@ export async function deployImage(context: IActionContext & Partial<ContainerReg
wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true';
}

const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(wizardContext);
wizardContext.resourceGroup = nonNullValue(
resourceGroups.find(rg => 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<DeployImageContext> = new AzureWizard(wizardContext, {
title: localize('deployImageTitle', 'Deploy image to "{0}"', parentResourceName),
promptSteps: [
new ContainerAppDeployStartingResourcesLogStep(),
new ImageSourceListStep(),
new ContainerAppOverwriteConfirmStep(),
],
Expand Down

0 comments on commit e0fe14a

Please sign in to comment.