-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProjectInternal.ts
More file actions
258 lines (214 loc) · 11.5 KB
/
deployWorkspaceProjectInternal.ts
File metadata and controls
258 lines (214 loc) · 11.5 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
import { LocationListStep, ResourceGroupCreateStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, GenericTreeItem, activityInfoIcon, activitySuccessContext, createUniversallyUniqueContextValue, nonNullValueAndProp, type AzureWizardExecuteStep, type AzureWizardPromptStep, type ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
import { ProgressLocation, window } from "vscode";
import { appProvider, managedEnvironmentsId } from "../../../constants";
import { ext } from "../../../extensionVariables";
import { createActivityContext } from "../../../utils/activityUtils";
import { getVerifyProvidersStep } from "../../../utils/getVerifyProvidersStep";
import { localize } from "../../../utils/localize";
import { ContainerAppCreateStep } from "../../createContainerApp/ContainerAppCreateStep";
import { LogAnalyticsCreateStep } from "../../createManagedEnvironment/LogAnalyticsCreateStep";
import { ManagedEnvironmentCreateStep } from "../../createManagedEnvironment/ManagedEnvironmentCreateStep";
import { ContainerAppUpdateStep } from "../../image/imageSource/ContainerAppUpdateStep";
import { ImageSourceListStep } from "../../image/imageSource/ImageSourceListStep";
import { IngressPromptStep } from "../../ingress/IngressPromptStep";
import { formatSectionHeader } from "../formatSectionHeader";
import { AppResourcesNameStep } from "./AppResourcesNameStep";
import { DeployWorkspaceProjectConfirmStep } from "./DeployWorkspaceProjectConfirmStep";
import { type DeployWorkspaceProjectInternalContext } from "./DeployWorkspaceProjectInternalContext";
import { DeployWorkspaceProjectSaveSettingsStep } from "./DeployWorkspaceProjectSaveSettingsStep";
import { SharedResourcesNameStep } from "./SharedResourcesNameStep";
import { ShouldSaveDeploySettingsPromptStep } from "./ShouldSaveDeploySettingsPromptStep";
import { getStartingConfiguration } from "./startingConfiguration/getStartingConfiguration";
export interface DeployWorkspaceProjectInternalOptions {
/**
* Suppress showing the wizard execution through the activity log
*/
suppressActivity?: boolean;
/**
* Suppress registry selection prompt
*/
suppressRegistryPrompt?: boolean;
/**
* Suppress any [resource] confirmation prompts
*/
suppressConfirmation?: boolean;
/**
* Suppress the creation of a container app (last potential resource creation step in the process)
*/
suppressContainerAppCreation?: boolean;
/**
* Suppress loading progress notification
*/
suppressProgress?: boolean;
/**
* Suppress the default wizard [prompting] title
*/
suppressWizardTitle?: boolean;
}
export async function deployWorkspaceProjectInternal(
context: DeployWorkspaceProjectInternalContext,
options: DeployWorkspaceProjectInternalOptions
): Promise<DeployWorkspaceProjectInternalContext> {
ext.outputChannel.appendLog(
formatSectionHeader(localize('initCommandExecution', 'Initialize deploy workspace project'))
);
let activityContext: Partial<ExecuteActivityContext>;
if (options.suppressActivity) {
activityContext = { suppressNotification: true };
} else {
activityContext = await createActivityContext();
activityContext.activityChildren = [];
}
// Show loading indicator while we configure starting values
let startingConfiguration: Partial<DeployWorkspaceProjectInternalContext> | undefined;
await window.withProgress({
location: ProgressLocation.Notification,
cancellable: false,
title: options.suppressProgress ?
undefined :
localize('loadingWorkspaceTitle', 'Loading workspace project starting configurations...')
}, async () => {
startingConfiguration = await getStartingConfiguration({ ...context }, options);
});
if (startingConfiguration?.containerApp?.revisionsMode === KnownActiveRevisionsMode.Multiple) {
throw new Error(localize('multipleRevisionsNotSupported', 'The container app "{0}" cannot be updated using "Deploy Project from Workspace..." while in multiple revisions mode.', startingConfiguration?.containerApp?.name));
}
if ((startingConfiguration?.containerApp?.template?.containers?.length ?? 0) > 1) {
throw new Error(localize('multipleContainersNotSupported', 'The container app "{0}" cannot be updated using "Deploy Project from Workspace..." while having more than one active container.', startingConfiguration?.containerApp?.name));
}
const wizardContext: DeployWorkspaceProjectInternalContext = {
...context,
...activityContext,
...startingConfiguration
};
const promptSteps: AzureWizardPromptStep<DeployWorkspaceProjectInternalContext>[] = [
new DeployWorkspaceProjectConfirmStep(!!options.suppressConfirmation),
new SharedResourcesNameStep(),
new AppResourcesNameStep(!!options.suppressContainerAppCreation)
];
const executeSteps: AzureWizardExecuteStep<DeployWorkspaceProjectInternalContext>[] = [
new DeployWorkspaceProjectSaveSettingsStep()
];
// Resource group
if (wizardContext.resourceGroup) {
wizardContext.telemetry.properties.existingResourceGroup = 'true';
const resourceGroupName: string = nonNullValueAndProp(wizardContext.resourceGroup, 'name');
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['useExistingResourceGroupInfoItem', activitySuccessContext]),
label: localize('useResourceGroup', 'Using resource group "{0}"', resourceGroupName),
iconPath: activityInfoIcon
})
);
await LocationListStep.setLocation(wizardContext, wizardContext.resourceGroup.location);
ext.outputChannel.appendLog(localize('usingResourceGroup', 'Using resource group "{0}".', resourceGroupName));
} else {
wizardContext.telemetry.properties.existingResourceGroup = 'false';
executeSteps.push(new ResourceGroupCreateStep());
}
// Managed environment
if (wizardContext.managedEnvironment) {
wizardContext.telemetry.properties.existingEnvironment = 'true';
const managedEnvironmentName: string = nonNullValueAndProp(wizardContext.managedEnvironment, 'name');
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['useExistingManagedEnvironmentInfoItem', activitySuccessContext]),
label: localize('useManagedEnvironment', 'Using container apps environment "{0}"', managedEnvironmentName),
iconPath: activityInfoIcon
})
);
if (!LocationListStep.hasLocation(wizardContext)) {
await LocationListStep.setLocation(wizardContext, wizardContext.managedEnvironment.location);
}
ext.outputChannel.appendLog(localize('usingManagedEnvironment', 'Using container apps environment "{0}".', managedEnvironmentName));
} else {
wizardContext.telemetry.properties.existingEnvironment = 'false';
executeSteps.push(
new LogAnalyticsCreateStep(),
new ManagedEnvironmentCreateStep()
);
}
// Azure Container Registry
if (wizardContext.registry) {
wizardContext.telemetry.properties.existingRegistry = 'true';
const registryName: string = nonNullValueAndProp(wizardContext.registry, 'name');
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['useExistingAcrInfoItem', activitySuccessContext]),
label: localize('useAcr', 'Using container registry "{0}"', registryName),
iconPath: activityInfoIcon
})
);
ext.outputChannel.appendLog(localize('usingAcr', 'Using Azure Container Registry "{0}".', registryName));
} else {
// ImageSourceListStep can already handle this creation logic
wizardContext.telemetry.properties.existingRegistry = 'false';
}
// Container app
if (wizardContext.containerApp) {
wizardContext.telemetry.properties.existingContainerApp = 'true';
const containerAppName: string = nonNullValueAndProp(wizardContext.containerApp, 'name');
executeSteps.push(new ContainerAppUpdateStep());
wizardContext.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['useExistingContainerAppInfoItem', activitySuccessContext]),
label: localize('useContainerApp', 'Using container app "{0}"', containerAppName),
iconPath: activityInfoIcon
})
);
ext.outputChannel.appendLog(localize('usingContainerApp', 'Using container app "{0}".', containerAppName));
if (!LocationListStep.hasLocation(wizardContext)) {
await LocationListStep.setLocation(wizardContext, wizardContext.containerApp.location);
}
} else {
wizardContext.telemetry.properties.existingContainerApp = 'false';
if (!options.suppressContainerAppCreation) {
executeSteps.push(new ContainerAppCreateStep());
}
}
promptSteps.push(
new ImageSourceListStep(),
new IngressPromptStep(),
);
// Verify providers
executeSteps.push(getVerifyProvidersStep<DeployWorkspaceProjectInternalContext>());
// Location
if (LocationListStep.hasLocation(wizardContext)) {
wizardContext.telemetry.properties.existingLocation = 'true';
ext.outputChannel.appendLog(localize('useLocation', 'Using location "{0}".', (await LocationListStep.getLocation(wizardContext)).name));
} else {
wizardContext.telemetry.properties.existingLocation = 'false';
LocationListStep.addProviderForFiltering(wizardContext, appProvider, managedEnvironmentsId);
LocationListStep.addStep(wizardContext, promptSteps);
}
// Save deploy settings
promptSteps.push(new ShouldSaveDeploySettingsPromptStep());
const wizard: AzureWizard<DeployWorkspaceProjectInternalContext> = new AzureWizard(wizardContext, {
title: options.suppressWizardTitle ?
undefined :
localize('deployWorkspaceProjectTitle', 'Deploy workspace project to a container app'),
promptSteps,
executeSteps,
showLoadingPrompt: true
});
await wizard.prompt();
if (!options.suppressActivity) {
wizardContext.activityTitle = localize('deployWorkspaceProjectActivityTitle', 'Deploy workspace project to container app "{0}"', wizardContext.containerApp?.name || wizardContext.newContainerAppName);
}
ext.outputChannel.appendLog(
formatSectionHeader(localize('beginCommandExecution', 'Deploy workspace project'))
);
await wizard.execute();
wizardContext.telemetry.properties.revisionMode = wizardContext.containerApp?.revisionsMode;
ext.outputChannel.appendLog(
formatSectionHeader(localize('finishCommandExecution', 'Finished deploying workspace project'))
);
ext.branchDataProvider.refresh();
return wizardContext;
}