-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathContainerAppCreateStep.ts
More file actions
90 lines (80 loc) · 4.64 KB
/
ContainerAppCreateStep.ts
File metadata and controls
90 lines (80 loc) · 4.64 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
81
82
83
84
85
86
87
88
89
90
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ContainerAppsAPIClient, Ingress, KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { GenericTreeItem, nonNullProp, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import type { Progress } from "vscode";
import { activityFailContext, activityFailIcon, activitySuccessContext, activitySuccessIcon, containerAppsWebProvider } from "../../constants";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { ExecuteActivityOutput, ExecuteActivityOutputStepBase } from "../../utils/activity/ExecuteActivityOutputStepBase";
import { createActivityChildContext } from "../../utils/activity/activityUtils";
import { createContainerAppsAPIClient } from "../../utils/azureClients";
import { localize } from "../../utils/localize";
import { getContainerNameForImage } from "../image/imageSource/containerRegistry/getContainerNameForImage";
import type { ICreateContainerAppContext } from "./ICreateContainerAppContext";
export class ContainerAppCreateStep extends ExecuteActivityOutputStepBase<ICreateContainerAppContext> {
public priority: number = 620;
protected async executeCore(context: ICreateContainerAppContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
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 ? {
targetPort: context.targetPort,
external: context.enableExternal,
transport: 'auto',
allowInsecure: false,
traffic: [
{
weight: 100,
latestRevision: true
}
],
} : undefined;
const creating: string = localize('creatingContainerApp', 'Creating container app...');
progress.report({ message: creating });
context.containerApp = ContainerAppItem.CreateContainerAppModel(await appClient.containerApps.beginCreateOrUpdateAndWait(resourceGroupName, containerAppName, {
location: (await LocationListStep.getLocation(context, containerAppsWebProvider)).name,
managedEnvironmentId: context.managedEnvironmentId || context.managedEnvironment?.id,
configuration: {
ingress,
secrets: context.secrets,
registries: context.registries,
activeRevisionsMode: KnownActiveRevisionsMode.Single,
},
template: {
containers: [
{
image: context.image,
name: getContainerNameForImage(nonNullProp(context, 'image')),
env: context.environmentVariables
}
]
}
}));
}
public shouldExecute(context: ICreateContainerAppContext): boolean {
return !context.containerApp;
}
protected createSuccessOutput(context: ICreateContainerAppContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['containerAppCreateStep', activitySuccessContext]),
label: localize('createContainerApp', 'Create container app "{0}"', context.newContainerAppName),
iconPath: activitySuccessIcon
}),
message: localize('createContainerAppSuccess', 'Created container app "{0}".', context.newContainerAppName)
};
}
protected createFailOutput(context: ICreateContainerAppContext): ExecuteActivityOutput {
return {
item: new GenericTreeItem(undefined, {
contextValue: createActivityChildContext(['containerAppCreateStep', activityFailContext]),
label: localize('createContainerApp', 'Create container app "{0}"', context.newContainerAppName),
iconPath: activityFailIcon
}),
message: localize('createContainerAppFail', 'Failed to create container app "{0}".', context.newContainerAppName)
};
}
}