|
| 1 | +/*--------------------------------------------------------------------------------------------- |
| 2 | +* Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +* Licensed under the MIT License. See License.md 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 { activityInfoIcon, activitySuccessContext, AzureWizard, createSubscriptionContext, createUniversallyUniqueContextValue, GenericTreeItem, nonNullValue, nonNullValueAndProp, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; |
| 9 | +import { ext } from "../../extensionVariables"; |
| 10 | +import { type ContainerItem } from "../../tree/containers/ContainerItem"; |
| 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 { getParentResource } from "../../utils/revisionDraftUtils"; |
| 17 | +import { ContainerAppOverwriteConfirmStep } from "../ContainerAppOverwriteConfirmStep"; |
| 18 | +import { showContainerAppNotification } from "../createContainerApp/showContainerAppNotification"; |
| 19 | +import { ContainerAppUpdateStep } from "../image/imageSource/ContainerAppUpdateStep"; |
| 20 | +import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep"; |
| 21 | +import { type ContainerRegistryImageSourceContext } from "../image/imageSource/containerRegistry/ContainerRegistryImageSourceContext"; |
| 22 | +import { type DeployImageContext } from "./DeployImageContext"; |
| 23 | + |
| 24 | +export async function deployImage(context: IActionContext & Partial<ContainerRegistryImageSourceContext>, node: ContainerItem): Promise<void> { |
| 25 | + const { subscription, containerApp } = node; |
| 26 | + const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription); |
| 27 | + |
| 28 | + const wizardContext: DeployImageContext = { |
| 29 | + ...context, |
| 30 | + ...subscriptionContext, |
| 31 | + ...await createActivityContext(true), |
| 32 | + subscription, |
| 33 | + managedEnvironment: await getManagedEnvironmentFromContainerApp({ ...context, ...subscriptionContext }, containerApp), |
| 34 | + containerApp, |
| 35 | + containersIdx: node.containersIdx, |
| 36 | + template: nonNullValueAndProp(getParentResource(containerApp, node.revision), 'template'), |
| 37 | + }; |
| 38 | + |
| 39 | + if (isAzdExtensionInstalled()) { |
| 40 | + wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; |
| 41 | + } |
| 42 | + |
| 43 | + const resourceGroups: ResourceGroup[] = await ResourceGroupListStep.getResourceGroups(wizardContext); |
| 44 | + wizardContext.resourceGroup = nonNullValue( |
| 45 | + resourceGroups.find(rg => rg.name === containerApp.resourceGroup), |
| 46 | + localize('containerAppResourceGroup', 'Expected to find the container app\'s resource group.'), |
| 47 | + ); |
| 48 | + |
| 49 | + // Log resource group |
| 50 | + wizardContext.activityChildren?.push( |
| 51 | + new GenericTreeItem(undefined, { |
| 52 | + contextValue: createUniversallyUniqueContextValue(['useExistingResourceGroupInfoItem', activitySuccessContext]), |
| 53 | + label: localize('useResourceGroup', 'Using resource group "{0}"', wizardContext.resourceGroup.name), |
| 54 | + iconPath: activityInfoIcon |
| 55 | + }) |
| 56 | + ); |
| 57 | + ext.outputChannel.appendLog(localize('usingResourceGroup', 'Using resource group "{0}".', wizardContext.resourceGroup.name)); |
| 58 | + |
| 59 | + // Log container app |
| 60 | + wizardContext.activityChildren?.push( |
| 61 | + new GenericTreeItem(undefined, { |
| 62 | + contextValue: createUniversallyUniqueContextValue(['useExistingContainerAppInfoItem', activitySuccessContext]), |
| 63 | + label: localize('useContainerApp', 'Using container app "{0}"', wizardContext.containerApp?.name), |
| 64 | + iconPath: activityInfoIcon |
| 65 | + }) |
| 66 | + ); |
| 67 | + ext.outputChannel.appendLog(localize('usingContainerApp', 'Using container app "{0}".', wizardContext.containerApp?.name)); |
| 68 | + |
| 69 | + await LocationListStep.setLocation(wizardContext, containerApp.location); |
| 70 | + |
| 71 | + const parentResourceName: string = getParentResource(containerApp, node.revision).name ?? containerApp.name; |
| 72 | + const wizard: AzureWizard<DeployImageContext> = new AzureWizard(wizardContext, { |
| 73 | + title: localize('deployImageTitle', 'Deploy image to "{0}"', parentResourceName), |
| 74 | + promptSteps: [ |
| 75 | + new ImageSourceListStep(), |
| 76 | + new ContainerAppOverwriteConfirmStep(), |
| 77 | + ], |
| 78 | + executeSteps: [ |
| 79 | + getVerifyProvidersStep<DeployImageContext>(), |
| 80 | + new ContainerAppUpdateStep(), |
| 81 | + ], |
| 82 | + showLoadingPrompt: true |
| 83 | + }); |
| 84 | + |
| 85 | + await wizard.prompt(); |
| 86 | + await wizard.execute(); |
| 87 | + |
| 88 | + if (!wizardContext.suppressNotification) { |
| 89 | + void showContainerAppNotification(containerApp, true /** isUpdate */); |
| 90 | + } |
| 91 | +} |
0 commit comments