-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathContainerAppCreateStep.ts
More file actions
93 lines (84 loc) · 4.18 KB
/
ContainerAppCreateStep.ts
File metadata and controls
93 lines (84 loc) · 4.18 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
91
92
93
/*---------------------------------------------------------------------------------------------
* 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, RegistryCredentials, Secret } from "@azure/arm-appcontainers";
import { LocationListStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizardExecuteStep } from "@microsoft/vscode-azext-utils";
import { Progress } from "vscode";
import { containerAppsWebProvider } from "../../constants";
import { ext } from "../../extensionVariables";
import { ContainerAppItem } from "../../tree/ContainerAppItem";
import { createContainerAppsAPIClient } from "../../utils/azureClients";
import { localize } from "../../utils/localize";
import { nonNullProp } from "../../utils/nonNull";
import { listCredentialsFromRegistry } from "../deployImage/acr/listCredentialsFromRegistry";
import { getContainerNameForImage } from "../deployImage/getContainerNameForImage";
import { getLoginServer } from "./getLoginServer";
import { IContainerAppContext } from "./IContainerAppContext";
export class ContainerAppCreateStep extends AzureWizardExecuteStep<IContainerAppContext> {
public priority: number = 250;
public async execute(context: IContainerAppContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const appClient: ContainerAppsAPIClient = await createContainerAppsAPIClient(context);
let secrets: Secret[], registries: RegistryCredentials[];
if (context.registry) {
// for ACR usage
const { username, password } = await listCredentialsFromRegistry(context, context.registry);
const passwordName = `${context.registry.name?.toLowerCase()}-${password?.name}`;
secrets = [
{
name: passwordName,
value: password?.value
}
]
registries = [
{
server: context.registry.loginServer,
username,
passwordSecretRef: passwordName
}
]
} else {
// currently only supporting public Docker Hub registries so no secrets required
secrets = [];
registries = [];
}
const ingress: Ingress | undefined = context.enableIngress ? {
targetPort: context.targetPort,
external: context.enableExternal,
transport: 'auto',
allowInsecure: false,
traffic: [
{
"weight": 100,
"latestRevision": true
}
],
} : undefined;
const creatingSwa: string = localize('creatingContainerApp', 'Creating new container app "{0}"...', context.newContainerAppName);
progress.report({ message: creatingSwa });
ext.outputChannel.appendLog(creatingSwa);
context.image ||= `${getLoginServer(context)}/${context.repositoryName}:${context.tag}`;
const name = getContainerNameForImage(context.image);
context.containerApp = ContainerAppItem.CreateContainerAppModel(await appClient.containerApps.beginCreateOrUpdateAndWait(nonNullProp(context, 'newResourceGroupName'), nonNullProp(context, 'newContainerAppName'), {
location: (await LocationListStep.getLocation(context, containerAppsWebProvider)).name,
managedEnvironmentId: context.managedEnvironmentId,
configuration: {
ingress,
secrets,
registries,
activeRevisionsMode: KnownActiveRevisionsMode.Multiple,
},
template: {
containers: [
{
image: context.image, name, env: context.environmentVariables
}
]
}
}));
}
public shouldExecute(_wizardContext: IContainerAppContext): boolean {
return true;
}
}