-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathupdateImage.ts
More file actions
80 lines (71 loc) · 4.28 KB
/
updateImage.ts
File metadata and controls
80 lines (71 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownActiveRevisionsMode, type Revision } from "@azure/arm-appcontainers";
import { AzureWizard, createSubscriptionContext, type ExecuteActivityContext, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { ext } from "../../../extensionVariables";
import { type SetTelemetryProps } from "../../../telemetry/SetTelemetryProps";
import { type UpdateImageTelemetryProps as TelemetryProps } from "../../../telemetry/commandTelemetryProps";
import { type ContainerAppItem, type ContainerAppModel } from "../../../tree/ContainerAppItem";
import { type RevisionDraftItem } from "../../../tree/revisionManagement/RevisionDraftItem";
import { type RevisionItem } from "../../../tree/revisionManagement/RevisionItem";
import { createActivityContext } from "../../../utils/activityUtils";
import { getManagedEnvironmentFromContainerApp } from "../../../utils/getResourceUtils";
import { getVerifyProvidersStep } from "../../../utils/getVerifyProvidersStep";
import { localize } from "../../../utils/localize";
import { pickContainerApp } from "../../../utils/pickItem/pickContainerApp";
import { pickRevision, pickRevisionDraft } from "../../../utils/pickItem/pickRevision";
import { getParentResourceFromItem } from "../../../utils/revisionDraftUtils";
import { RevisionDraftDeployPromptStep } from "../../revisionDraft/RevisionDraftDeployPromptStep";
import { type ImageSourceBaseContext } from "../imageSource/ImageSourceContext";
import { ImageSourceListStep } from "../imageSource/ImageSourceListStep";
import { UpdateImageDraftStep } from "./UpdateImageDraftStep";
import { UpdateRegistryAndSecretsStep } from "./UpdateRegistryAndSecretsStep";
export type UpdateImageContext = ImageSourceBaseContext & ExecuteActivityContext & SetTelemetryProps<TelemetryProps>;
/**
* An ACA exclusive command that updates the container app or revision's container image via revision draft.
* The draft must be deployed for the changes to take effect and can be used to bundle together template changes.
*/
export async function updateImage(context: IActionContext, node?: ContainerAppItem | RevisionItem): Promise<void> {
let item: ContainerAppItem | RevisionItem | RevisionDraftItem | undefined = node;
if (!item) {
const containerAppItem: ContainerAppItem = await pickContainerApp(context);
if (containerAppItem.containerApp.revisionsMode === KnownActiveRevisionsMode.Single) {
item = containerAppItem;
} else {
if (ext.revisionDraftFileSystem.doesContainerAppsItemHaveRevisionDraft(containerAppItem)) {
item = await pickRevisionDraft(context, containerAppItem);
} else {
item = await pickRevision(context, containerAppItem);
}
}
}
const { subscription, containerApp } = item;
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(subscription);
const wizardContext: UpdateImageContext = {
...context,
...subscriptionContext,
...await createActivityContext(),
subscription,
managedEnvironment: await getManagedEnvironmentFromContainerApp({ ...context, ...subscriptionContext }, containerApp),
containerApp
};
wizardContext.telemetry.properties.revisionMode = containerApp.revisionsMode;
const parentResource: ContainerAppModel | Revision = getParentResourceFromItem(item);
const wizard: AzureWizard<UpdateImageContext> = new AzureWizard(wizardContext, {
title: localize('updateImage', 'Update container image for "{0}" (draft)', parentResource.name),
promptSteps: [
new ImageSourceListStep(),
new RevisionDraftDeployPromptStep(),
],
executeSteps: [
getVerifyProvidersStep<UpdateImageContext>(),
new UpdateRegistryAndSecretsStep(),
new UpdateImageDraftStep(item),
],
showLoadingPrompt: true
});
await wizard.prompt();
await wizard.execute();
}