|
| 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 { KnownActiveRevisionsMode, Revision } from "@azure/arm-appcontainers"; |
| 7 | +import { VerifyProvidersStep } from "@microsoft/vscode-azext-azureutils"; |
| 8 | +import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, ExecuteActivityContext, IActionContext, createSubscriptionContext } from "@microsoft/vscode-azext-utils"; |
| 9 | +import { webProvider } from "../../../constants"; |
| 10 | +import { ext } from "../../../extensionVariables"; |
| 11 | +import type { ContainerAppItem, ContainerAppModel } from "../../../tree/ContainerAppItem"; |
| 12 | +import type { RevisionDraftItem } from "../../../tree/revisionManagement/RevisionDraftItem"; |
| 13 | +import type { RevisionItem } from "../../../tree/revisionManagement/RevisionItem"; |
| 14 | +import { createActivityContext } from "../../../utils/activity/activityUtils"; |
| 15 | +import { localize } from "../../../utils/localize"; |
| 16 | +import { pickContainerApp } from "../../../utils/pickItem/pickContainerApp"; |
| 17 | +import { pickRevision, pickRevisionDraft } from "../../../utils/pickItem/pickRevision"; |
| 18 | +import { getParentResourceFromItem } from "../../../utils/revisionDraftUtils"; |
| 19 | +import type { ImageSourceBaseContext } from "../imageSource/ImageSourceBaseContext"; |
| 20 | +import { ImageSourceListStep } from "../imageSource/ImageSourceListStep"; |
| 21 | +import { UpdateImageDraftStep } from "./UpdateImageDraftStep"; |
| 22 | +import { UpdateRegistryAndSecretsStep } from "./UpdateRegistryAndSecretsStep"; |
| 23 | + |
| 24 | +export type UpdateImageContext = ImageSourceBaseContext & ExecuteActivityContext; |
| 25 | + |
| 26 | +/** |
| 27 | + * An ACA exclusive command that updates the container app or revision's container image via revision draft. |
| 28 | + * The draft must be deployed for the changes to take effect and can be used to bundle together template changes. |
| 29 | + */ |
| 30 | +export async function updateImage(context: IActionContext, node?: ContainerAppItem | RevisionItem): Promise<void> { |
| 31 | + let item: ContainerAppItem | RevisionItem | RevisionDraftItem | undefined = node; |
| 32 | + if (!item) { |
| 33 | + const containerAppItem: ContainerAppItem = await pickContainerApp(context); |
| 34 | + |
| 35 | + if (containerAppItem.containerApp.revisionsMode === KnownActiveRevisionsMode.Single) { |
| 36 | + item = containerAppItem; |
| 37 | + } else { |
| 38 | + if (ext.revisionDraftFileSystem.doesContainerAppsItemHaveRevisionDraft(containerAppItem)) { |
| 39 | + item = await pickRevisionDraft(context, containerAppItem); |
| 40 | + } else { |
| 41 | + item = await pickRevision(context, containerAppItem); |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + const { subscription, containerApp } = item; |
| 47 | + |
| 48 | + const wizardContext: UpdateImageContext = { |
| 49 | + ...context, |
| 50 | + ...createSubscriptionContext(subscription), |
| 51 | + ...await createActivityContext(), |
| 52 | + subscription, |
| 53 | + containerApp |
| 54 | + }; |
| 55 | + |
| 56 | + const promptSteps: AzureWizardPromptStep<UpdateImageContext>[] = [ |
| 57 | + new ImageSourceListStep(), |
| 58 | + ]; |
| 59 | + |
| 60 | + const executeSteps: AzureWizardExecuteStep<UpdateImageContext>[] = [ |
| 61 | + new VerifyProvidersStep([webProvider]), |
| 62 | + new UpdateRegistryAndSecretsStep(), |
| 63 | + new UpdateImageDraftStep(item) |
| 64 | + ]; |
| 65 | + |
| 66 | + const parentResource: ContainerAppModel | Revision = getParentResourceFromItem(item); |
| 67 | + |
| 68 | + const wizard: AzureWizard<UpdateImageContext> = new AzureWizard(wizardContext, { |
| 69 | + title: localize('updateImage', 'Update container image for "{0}" (draft)', parentResource.name), |
| 70 | + promptSteps, |
| 71 | + executeSteps, |
| 72 | + showLoadingPrompt: true |
| 73 | + }); |
| 74 | + |
| 75 | + await wizard.prompt(); |
| 76 | + await wizard.execute(); |
| 77 | +} |
0 commit comments