-
Notifications
You must be signed in to change notification settings - Fork 21
Add changes for re running "Deploy to Container App" command #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
6179474
6369e45
a73ff7e
28ddbb7
3124483
33b1e64
de898ee
27b145f
dc140c4
845f2fd
7dc3606
8d5ec21
63251a8
1827c97
ffae38b
4a2dd26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,19 +4,22 @@ | |
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers"; | ||
| import { AzureWizard, CopilotUserInput, createSubscriptionContext, nonNullProp, type AzureWizardPromptStep, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; | ||
| import { ImageSource } from "../../constants"; | ||
| import { AzExtUserInput, AzureWizard, createSubscriptionContext, isCopilotUserInput, nonNullProp, type AzureWizardPromptStep, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils"; | ||
| import { type AzureSubscription } from "@microsoft/vscode-azureresources-api"; | ||
| import { acrDomain, ImageSource, SupportedRegistries } 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 { OpenLoadingViewStep } from "../../webviews/OpenLoadingViewStep"; | ||
| import { OpenConfirmationViewStep, SharedState } from "../../webviews/OpenConfirmationViewStep"; | ||
| import { openLoadingViewPanel } from "../../webviews/OpenLoadingViewStep"; | ||
| import { CommandAttributes } from "../CommandAttributes"; | ||
| import { ContainerAppOverwriteConfirmStep } from "../ContainerAppOverwriteConfirmStep"; | ||
| import { ContainerAppListStep } from "../createContainerApp/ContainerAppListStep"; | ||
| import { ManagedEnvironmentListStep } from "../createManagedEnvironment/ManagedEnvironmentListStep"; | ||
| import { deployWorkspaceProject } from "../deployWorkspaceProject/deployWorkspaceProject"; | ||
| import { type DeployWorkspaceProjectResults } from "../deployWorkspaceProject/getDeployWorkspaceProjectResults"; | ||
| import { editContainerCommandName } from "../editContainer/editContainer"; | ||
|
|
@@ -39,62 +42,116 @@ export async function deployContainerApp(context: IActionContext, node?: Contain | |
| 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) { | ||
| return await deployWorkspaceProject(context, item); | ||
| } | ||
|
|
||
| const wizardContext: ContainerAppDeployContext = { | ||
| ...subscriptionActionContext, | ||
| ...await createActivityContext({ withChildren: true }), | ||
| subscription: item.subscription, | ||
| containerApp: item.containerApp, | ||
| managedEnvironment: await getManagedEnvironmentFromContainerApp(subscriptionActionContext, item.containerApp), | ||
| imageSource, | ||
| activityAttributes: CommandAttributes.DeployContainerAppContainerRegistry, | ||
| }; | ||
|
|
||
| if (isAzdExtensionInstalled()) { | ||
| wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; | ||
| } | ||
| wizardContext.telemetry.properties.revisionMode = item.containerApp.revisionsMode; | ||
|
|
||
| const confirmationViewTitle: string = localize('summary', 'Summary'); | ||
| let confirmationViewDescription: string = localize('viewDescription', 'Please select an input you would like to change. Note: Any input proceeding the changed input will need to change as well'); | ||
| let confirmationViewTabTitle: string = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App'); | ||
| let title: string = localize('deployContainerAppTitle', 'Deploy image to container app'); | ||
|
|
||
| const promptSteps: AzureWizardPromptStep<ContainerAppDeployContext>[] = []; | ||
| if (wizardContext.ui instanceof CopilotUserInput) { | ||
| promptSteps.push(new OpenLoadingViewStep()); | ||
| confirmationViewDescription = localize('viewDescription', 'Please review AI generated inputs and select any you would like to modify. Note: Any input proceeding the modified input will need to change as well'); | ||
| confirmationViewTabTitle = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App using Copilot'); | ||
| title = localize('deployContainerAppWithCopilotTitle', 'Deploy image to container app using copilot'); | ||
| let imageSource: ImageSource | undefined; | ||
| let registryDomain: SupportedRegistries | undefined; | ||
| if (isCopilotUserInput(context)) { | ||
| // If the input is coming from Copilot we want to default to Container Registry as we don't support 'deployWorkspaceProject' flow with Copilot at the moment | ||
| imageSource = ImageSource.ContainerRegistry; | ||
| registryDomain = acrDomain; | ||
| } else { | ||
| // Prompt for image source before initializing the wizard in case we need to redirect the call to 'deployWorkspaceProject' instead | ||
| imageSource = await promptImageSource(subscriptionActionContext); | ||
| if (imageSource === ImageSource.RemoteAcrBuild) { | ||
| return await deployWorkspaceProject(context, item); | ||
| } | ||
| } | ||
| await deployContainerAppInternal(subscriptionActionContext, item, imageSource, registryDomain); | ||
| } | ||
|
|
||
| promptSteps.push( | ||
| new ContainerAppDeployStartingResourcesLogStep(), | ||
| new ImageSourceListStep(), | ||
| new ContainerAppOverwriteConfirmStep(), | ||
| new OpenConfirmationViewStep(confirmationViewTitle, confirmationViewTabTitle, confirmationViewDescription, title, () => wizard.confirmationViewProperties) | ||
| ); | ||
|
|
||
| const wizard = new AzureWizard<ContainerAppDeployContext>(wizardContext, { | ||
| title: title, | ||
| promptSteps: promptSteps, | ||
| 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; | ||
| export async function deployContainerAppInternal(context: ISubscriptionActionContext, node?: ContainerAppItem, imageSource?: ImageSource, registryDomain?: SupportedRegistries): Promise<void> { | ||
| try { | ||
| if (isCopilotUserInput(context)) { | ||
| await openLoadingViewPanel(context); | ||
| } | ||
|
|
||
| const subscription = (context as { azureSubscription?: AzureSubscription }).azureSubscription; | ||
|
|
||
| if (!subscription && !node) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I'm understanding this correctly, could this check be consolidated to a section dedicated to Copilot flow specific changes? A brief comment noting that Copilot may sometimes fail to provide a subscription would help make the intent clearer. |
||
| // If subscription does not exist revert to regular deploy flow | ||
| context.ui = new AzExtUserInput(context); | ||
| await deployContainerApp(context); | ||
| return; | ||
| } | ||
|
|
||
| const promptSteps: AzureWizardPromptStep<ContainerAppDeployContext>[] = []; | ||
|
|
||
| if (!node) { | ||
| promptSteps.push(new ManagedEnvironmentListStep(), new ContainerAppListStep()); | ||
| } | ||
|
|
||
| let wizardContext: ContainerAppDeployContext = {} as ContainerAppDeployContext; | ||
|
|
||
| if (node && imageSource) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can I get some context about this if else if here? If you have a node and an image source, what does that imply? And if you have a subscription?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. node and image source implies you are coming from the regular flow. Just having a subscription and not those other two implies you are coming from a copilot version since we don't pass in a node in that case. I can add comments or something if that is super confusing.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I think it'd be more readable if you had a flag that says something like: runFromCopilot that's set to true if the subscription is defined or something like that. It just makes it clearer as to why we're checking for it. Maybe add it as a flag up at L68.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 I'd love to see Copilot specific logic consolidated as much as possible to improve maintainability of the normal command flow vs. copilot command flow. |
||
| // If this command gets re run we only want the internal portion of the command to run, so we set the callbackid | ||
| context.callbackId = 'containerApps.deployContainerAppInternal'; | ||
| wizardContext = { | ||
| ...context, | ||
| ...await createActivityContext({ withChildren: true }), | ||
| subscription: node.subscription, | ||
| containerApp: node.containerApp, | ||
| managedEnvironment: await getManagedEnvironmentFromContainerApp(context, node.containerApp), | ||
| imageSource, | ||
| registryDomain, | ||
| activityAttributes: { | ||
| ...CommandAttributes.DeployContainerAppContainerRegistry, | ||
| subscription: node.subscription, | ||
| }, | ||
| }; | ||
|
|
||
| if (isAzdExtensionInstalled()) { | ||
| wizardContext.telemetry.properties.isAzdExtensionInstalled = 'true'; | ||
| } | ||
| wizardContext.telemetry.properties.revisionMode = node.containerApp.revisionsMode; | ||
| } else if (subscription) { | ||
| wizardContext = { | ||
| ...context, | ||
| ...await createActivityContext({ withChildren: true }), | ||
| subscription: subscription, | ||
| // at the moment we are only supporting re run with container registry image source | ||
| imageSource: ImageSource.ContainerRegistry | ||
| }; | ||
| } | ||
|
|
||
| const confirmationViewTitle: string = localize('summary', 'Summary'); | ||
| let confirmationViewDescription: string = localize('viewDescription', 'Please select an input you would like to change. Note: Any input preceding the changed input will need to change as well'); | ||
| let confirmationViewTabTitle: string = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App'); | ||
| let title: string = localize('deployContainerAppTitle', 'Deploy image to container app'); | ||
|
|
||
| if (isCopilotUserInput(wizardContext)) { | ||
| confirmationViewDescription = localize('viewDescription', 'Please review AI generated inputs and select any you would like to modify. Note: Any input preceding the modified input will need to change as well'); | ||
| confirmationViewTabTitle = localize('deployContainerAppTabTitle', 'Summary - Deploy Image to Container App using Copilot'); | ||
| title = localize('deployContainerAppWithCopilotTitle', 'Deploy image to container app using copilot'); | ||
| } | ||
|
|
||
| promptSteps.push( | ||
| new ContainerAppDeployStartingResourcesLogStep(), | ||
| new ImageSourceListStep(), | ||
| new ContainerAppOverwriteConfirmStep(), | ||
| new OpenConfirmationViewStep(confirmationViewTitle, confirmationViewTabTitle, confirmationViewDescription, title, () => wizard.confirmationViewProperties) | ||
| ); | ||
|
|
||
| const wizard = new AzureWizard<ContainerAppDeployContext>(wizardContext, { | ||
| title: title, | ||
| promptSteps: promptSteps, | ||
| 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; | ||
| } catch (_error) { | ||
| if (SharedState.currentPanel?.viewType === 'react-webview-loadingView') { | ||
| SharedState.currentPanel.dispose(); | ||
| SharedState.currentPanel = undefined; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function promptImageSource(context: ISubscriptionActionContext): Promise<ImageSource> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,9 @@ import { type RegistryCredentials } from "@azure/arm-appcontainers"; | |
| import { type SupportedRegistries } from "../../../constants"; | ||
| import { type IContainerAppContext } from "../../IContainerAppContext"; | ||
| import { type CreateAcrContext } from "../../image/imageSource/containerRegistry/acr/createAcr/CreateAcrContext"; | ||
| import { type ManagedEnvironmentRequiredContext } from "../../ManagedEnvironmentContext"; | ||
| import { type ManagedEnvironmentContext } from "../../ManagedEnvironmentContext"; | ||
|
|
||
| export interface ManagedIdentityRegistryCredentialsContext extends CreateAcrContext, ManagedEnvironmentRequiredContext, IContainerAppContext { | ||
| export interface ManagedIdentityRegistryCredentialsContext extends CreateAcrContext, ManagedEnvironmentContext, IContainerAppContext { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Context loosened from ManagedEnvironmentRequiredContext → ManagedEnvironmentContext. |
||
| registryDomain?: SupportedRegistries; | ||
| newRegistryCredential?: RegistryCredentials; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.