-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgetStartingConfiguration.ts
More file actions
69 lines (61 loc) · 3.49 KB
/
getStartingConfiguration.ts
File metadata and controls
69 lines (61 loc) · 3.49 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownSkuName } from "@azure/arm-containerregistry";
import { AzureWizard } from "@microsoft/vscode-azext-utils";
import { ImageSource } from "../../../../constants";
import { EnvFileListStep } from "../../../image/imageSource/EnvFileListStep";
import { DockerfileItemStep } from "../../../image/imageSource/buildImageInAzure/DockerfileItemStep";
import { AcrBuildSupportedOS } from "../../../image/imageSource/buildImageInAzure/OSPickStep";
import { RootFolderStep } from "../../../image/imageSource/buildImageInAzure/RootFolderStep";
import { type DeployWorkspaceProjectInternalContext } from "../DeployWorkspaceProjectInternalContext";
import { type DeployWorkspaceProjectInternalOptions } from "../deployWorkspaceProjectInternal";
import { DwpAcrListStep } from "./DwpAcrListStep";
import { DwpManagedEnvironmentListStep } from "./DwpManagedEnvironmentListStep";
import { getResourcesFromContainerAppHelper, getResourcesFromManagedEnvironmentHelper } from "./containerAppsResourceHelpers";
export async function getStartingConfiguration(context: DeployWorkspaceProjectInternalContext, options: DeployWorkspaceProjectInternalOptions): Promise<Partial<DeployWorkspaceProjectInternalContext>> {
await tryAddMissingAzureResourcesToContext(context);
const promptSteps = [
new RootFolderStep(),
new DockerfileItemStep(),
new DwpManagedEnvironmentListStep(),
];
if (!options.suppressRegistryPrompt) {
promptSteps.push(new DwpAcrListStep());
}
const wizard: AzureWizard<DeployWorkspaceProjectInternalContext> = new AzureWizard(context, {
promptSteps,
});
await wizard.prompt();
await wizard.execute();
return {
rootFolder: context.rootFolder,
dockerfilePath: context.dockerfilePath,
resourceGroup: context.resourceGroup,
managedEnvironment: context.managedEnvironment,
containerApp: context.containerApp,
registry: context.registry,
newRegistrySku: KnownSkuName.Basic,
suppressEnableAdminUserPrompt: options.suppressConfirmation,
imageSource: ImageSource.RemoteAcrBuild,
os: AcrBuildSupportedOS.Linux,
envPath: context.envPath,
environmentVariables:
context.envPath ?
undefined /** No need to set anything if there's an envPath, the step will handle parsing the data for us */ :
await EnvFileListStep.workspaceHasEnvFile(context.rootFolder) ? undefined : [] /** The equivalent of "skipForNow" */,
};
}
async function tryAddMissingAzureResourcesToContext(context: DeployWorkspaceProjectInternalContext): Promise<void> {
if (!context.containerApp && !context.managedEnvironment) {
return;
} else if (context.containerApp) {
const resources = await getResourcesFromContainerAppHelper(context, context.containerApp);
context.resourceGroup ??= resources.resourceGroup;
context.managedEnvironment ??= resources.managedEnvironment;
} else if (context.managedEnvironment) {
const resources = await getResourcesFromManagedEnvironmentHelper(context, context.managedEnvironment);
context.resourceGroup ??= resources.resourceGroup;
}
}