-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathContainerAppCreateStep.ts
More file actions
71 lines (62 loc) · 3.93 KB
/
ContainerAppCreateStep.ts
File metadata and controls
71 lines (62 loc) · 3.93 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownActiveRevisionsMode, type ContainerAppsAPIClient, type Ingress } from "@azure/arm-appcontainers";
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizardExecuteStepWithActivityOutput, nonNullProp, nonNullValueAndProp, type AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
import { type Progress } from "vscode";
import { containerAppsWebProvider, ImageSource } from "../../constants";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { createContainerAppsAPIClient } from "../../utils/azureClients";
import { localize } from "../../utils/localize";
import { ContainerAppStartVerificationStep } from "../image/imageSource/ContainerAppStartVerificationStep";
import { getContainerNameForImage } from "../image/imageSource/containerRegistry/getContainerNameForImage";
import { enabledIngressDefaults } from "../ingress/enableIngress/EnableIngressStep";
import { type ContainerAppCreateContext } from "./ContainerAppCreateContext";
export class ContainerAppCreateStep<T extends ContainerAppCreateContext> extends AzureWizardExecuteStepWithActivityOutput<T> {
public priority: number = 620;
public stepName: string = 'containerAppCreateStep';
protected getOutputLogSuccess = (context: T) => localize('createContainerAppSuccess', 'Created container app "{0}".', context.newContainerAppName);
protected getOutputLogFail = (context: T) => localize('createContainerAppFail', 'Failed to create container app "{0}"', context.newContainerAppName);
protected getTreeItemLabel = (context: T) => localize('createContainerAppLabel', 'Create container app "{0}"', context.newContainerAppName);
public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
progress.report({ message: localize('creatingContainerApp', 'Creating container app...') });
const appClient: ContainerAppsAPIClient = await createContainerAppsAPIClient(context);
const resourceGroupName: string = nonNullValueAndProp(context.resourceGroup, 'name');
const containerAppName: string = nonNullProp(context, 'newContainerAppName');
const ingress: Ingress | undefined = context.enableIngress ? {
...enabledIngressDefaults,
external: context.enableExternal,
targetPort: context.targetPort,
} : undefined;
context.containerApp = ContainerAppItem.CreateContainerAppModel(await appClient.containerApps.beginCreateOrUpdateAndWait(resourceGroupName, containerAppName, {
location: (await LocationListStep.getLocation(context, containerAppsWebProvider)).name,
managedEnvironmentId: context.managedEnvironment?.id,
configuration: {
ingress,
secrets: context.secrets,
registries: context.registryCredentials,
activeRevisionsMode: KnownActiveRevisionsMode.Single,
},
template: {
containers: [
{
image: context.image,
name: getContainerNameForImage(nonNullProp(context, 'image')),
env: context.environmentVariables
}
]
},
}));
}
public shouldExecute(context: T): boolean {
return !context.containerApp;
}
public addExecuteSteps(context: T): AzureWizardExecuteStep<T>[] {
if (context.imageSource === ImageSource.QuickstartImage) {
return [];
}
return [new ContainerAppStartVerificationStep()];
}
}