-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdeployWorkspaceProjectInternal.ts
More file actions
279 lines (234 loc) · 13 KB
/
deployWorkspaceProjectInternal.ts
File metadata and controls
279 lines (234 loc) · 13 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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*---------------------------------------------------------------------------------------------
* 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 { ActivityChildItem, ActivityChildType, AzureWizard, activityInfoContext, activityInfoIcon, 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, prependOrInsertAfterLastInfoChild } 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 { editContainerCommandName } from "../../editContainer/editContainer";
import { ContainerAppUpdateStep } from "../../image/imageSource/ContainerAppUpdateStep";
import { ImageSourceListStep } from "../../image/imageSource/ImageSourceListStep";
import { IngressPromptStep } from "../../ingress/IngressPromptStep";
import { deployWorkspaceProjectCommandName } from "../deployWorkspaceProject";
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({ withChildren: true });
}
// 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 cannot be updated using "{0}" while in multiple revisions mode. Navigate to the revision\'s container and execute "{1}" instead.', deployWorkspaceProjectCommandName, editContainerCommandName));
}
if ((startingConfiguration?.containerApp?.template?.containers?.length ?? 0) > 1) {
throw new Error(localize('multipleContainersNotSupported', 'The container app cannot be updated using "{0}" while having more than one active container. Navigate to the specific container instance and execute "{1}" instead.', deployWorkspaceProjectCommandName, editContainerCommandName));
}
const wizardContext: DeployWorkspaceProjectInternalContext = {
...context,
...activityContext,
...startingConfiguration,
activityAttributes: {
description: `Takes a workspace project with a Dockerfile and deploys it to an Azure Container App.
Automatically creates any required resources (resource group, managed environment, container registry, container app, log analytics workspace).
Supports single repo and monorepo, with deployment settings saved and reused via local VS Code settings (.vscode/settings.json).
Deployment settings are saved under "containerApps.deploymentConfigurations".
Deployment is agnostic to project runtime and language.`,
troubleshooting: [
`When ACR build errors are present, try to inspect the Dockerfile and ACR build logs.
When an error is related to the Dockerfile, offer to make direct fixes for the user.`,
`If a container app resource envelope is provided in attributes, do not confuse empty secrets as missing container app secrets. This is because secrets are not typically
copied over with the core resource metadata. Any issues with secrets will require inspecting the remote resource directly.`,
],
},
};
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');
prependOrInsertAfterLastInfoChild(wizardContext,
new ActivityChildItem({
label: localize('useResourceGroup', 'Use resource group "{0}"', resourceGroupName),
activityType: ActivityChildType.Info,
contextValue: activityInfoContext,
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');
prependOrInsertAfterLastInfoChild(wizardContext,
new ActivityChildItem({
label: localize('useManagedEnvironment', 'Use container apps environment "{0}"', managedEnvironmentName),
activityType: ActivityChildType.Info,
contextValue: activityInfoContext,
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');
prependOrInsertAfterLastInfoChild(wizardContext,
new ActivityChildItem({
label: localize('useAcr', 'Use container registry "{0}"', registryName),
activityType: ActivityChildType.Info,
contextValue: activityInfoContext,
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());
prependOrInsertAfterLastInfoChild(wizardContext,
new ActivityChildItem({
label: localize('useContainerApp', 'Use container app "{0}"', containerAppName),
activityType: ActivityChildType.Info,
contextValue: activityInfoContext,
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();
wizardContext.activityAttributes ??= {};
wizardContext.activityAttributes.azureResource = wizardContext.containerApp;
return wizardContext;
}