Skip to content

Commit

Permalink
Improvements to ACR selection prompting (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 authored Jan 10, 2025
1 parent 0994519 commit a9ea653
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ManagedEnvironmentItem } from "../../../tree/ManagedEnvironmentItem";
import { type IContainerAppContext } from "../../IContainerAppContext";
import { RootFolderStep } from "../../image/imageSource/buildImageInAzure/RootFolderStep";
import { type DeploymentConfiguration } from "./DeploymentConfiguration";
import { TryUseExistingWorkspaceRegistryStep } from "./workspace/azureResources/TryUseExistingWorkspaceRegistryStep";

type TreeItemDeploymentConfigurationContext = IContainerAppContext & DeploymentConfiguration;

Expand All @@ -18,7 +17,6 @@ export async function getTreeItemDeploymentConfiguration(context: IContainerAppC

const wizard: AzureWizard<TreeItemDeploymentConfigurationContext> = new AzureWizard(wizardContext, {
promptSteps: [new RootFolderStep()],
executeSteps: [new TryUseExistingWorkspaceRegistryStep()]
});

await wizard.prompt();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { RootFolderStep } from "../../../image/imageSource/buildImageInAzure/Roo
import { type DeploymentConfiguration } from "../DeploymentConfiguration";
import { DeploymentConfigurationListStep } from "./DeploymentConfigurationListStep";
import { type WorkspaceDeploymentConfigurationContext } from "./WorkspaceDeploymentConfigurationContext";
import { TryUseExistingWorkspaceRegistryStep } from "./azureResources/TryUseExistingWorkspaceRegistryStep";

export async function getWorkspaceDeploymentConfiguration(context: IContainerAppContext & { rootFolder?: WorkspaceFolder }): Promise<DeploymentConfiguration> {
const wizardContext: WorkspaceDeploymentConfigurationContext = Object.assign(context, {
Expand All @@ -25,9 +24,6 @@ export async function getWorkspaceDeploymentConfiguration(context: IContainerApp
new RootFolderStep(),
new DeploymentConfigurationListStep(),
],
executeSteps: [
new TryUseExistingWorkspaceRegistryStep()
]
});

await wizard.prompt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ export class ShouldSaveDeploySettingsPromptStep extends AzureWizardPromptStep<De
const settings: DeploymentConfigurationSettings[] | undefined = await dwpSettingUtilsV2.getWorkspaceDeploymentConfigurations(rootFolder);
const setting: DeploymentConfigurationSettings | undefined = settings?.[context.configurationIdx];

const hasNewResourceGroupSetting: boolean = (!!context.newResourceGroupName && setting?.resourceGroup !== context.newResourceGroupName) ||
(!!context.resourceGroup && setting?.resourceGroup !== context.resourceGroup.name);
const hasNewContainerAppSetting: boolean = (!!context.newContainerAppName && setting?.containerApp !== context.newContainerAppName) ||
(!!context.containerApp && setting?.containerApp !== context.containerApp.name);
const hasNewRegistrySetting: boolean = (!!context.newRegistryName && setting?.containerRegistry !== context.newRegistryName) ||
(!!context.registry && setting?.containerRegistry !== context.registry.name);

const hasNewSettings: boolean =
!setting?.label ||
setting?.type !== 'AcrDockerBuildRequest' ||
(context.dockerfilePath && convertRelativeToAbsolutePath(rootPath, setting?.dockerfilePath) !== context.dockerfilePath) ||
(context.envPath && convertRelativeToAbsolutePath(rootPath, setting?.envPath) !== context.envPath) ||
(context.srcPath && convertRelativeToAbsolutePath(rootPath, setting?.srcPath) !== context.srcPath) ||
(!!context.resourceGroup && setting?.resourceGroup !== context.resourceGroup.name) ||
(!!context.containerApp && setting?.containerApp !== context.containerApp.name) ||
(!!context.registry && setting?.containerRegistry !== context.registry.name);
hasNewResourceGroupSetting ||
hasNewContainerAppSetting ||
hasNewRegistrySetting;

if (!hasNewSettings) {
context.telemetry.properties.hasNewSettings = 'false';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type Registry } from "@azure/arm-containerregistry";
import { AzureWizardPromptStep, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { localize } from "../../../../utils/localize";
import { acrCreatePick, AcrListStep } from "../../../image/imageSource/containerRegistry/acr/AcrListStep";
import { type DeployWorkspaceProjectInternalContext } from "../DeployWorkspaceProjectInternalContext";

export class DwpAcrListStep<T extends DeployWorkspaceProjectInternalContext> extends AzureWizardPromptStep<T> {
public async prompt(context: T): Promise<void> {
const picks: IAzureQuickPickItem<Registry | undefined>[] = await this.getPicks(context);
if (picks.length < 2) {
// No container registries to choose from
return;
}

const placeHolder: string = localize('selectContainerRegistry', 'Select an Azure Container Registry to store your image');
const pick: IAzureQuickPickItem<Registry | undefined> = await context.ui.showQuickPick(picks, { placeHolder, enableGrouping: true, suppressPersistence: true });

context.registry = pick.data;
}

public shouldPrompt(context: T): boolean {
return !context.registry;
}

public async getPicks(context: T): Promise<IAzureQuickPickItem<Registry | undefined>[]> {
return [
acrCreatePick,
...await AcrListStep.getSortedAndRecommendedPicks(context),
];
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { ResourceGroupListStep, getResourceGroupFromId, uiUtils } from "@microso
import { AzureWizardPromptStep, nonNullProp, nonNullValueAndProp, type IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { createContainerAppsAPIClient } from "../../../../utils/azureClients";
import { localize } from "../../../../utils/localize";
import { hasMatchingPickDescription, recommendedPickDescription } from "../../../../utils/pickUtils";
import { type DeploymentConfigurationSettings } from "../../settings/DeployWorkspaceProjectSettingsV2";
import { dwpSettingUtilsV2 } from "../../settings/dwpSettingUtilsV2";
import { type DeployWorkspaceProjectInternalContext } from "../DeployWorkspaceProjectInternalContext";

const recommendedPickDescription: string = localize('recommended', '(Recommended)');
export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployWorkspaceProjectInternalContext> {
public async prompt(context: DeployWorkspaceProjectInternalContext): Promise<void> {
const placeHolder: string = localize('selectManagedEnvironment', 'Select a container apps environment');
Expand All @@ -26,9 +26,9 @@ export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployW

await this.setRecommendedPicks(context, picks);
const pick = await context.ui.showQuickPick(picks, { placeHolder, suppressPersistence: true });
context.telemetry.properties.usedRecommendedEnv = isRecommendedPick(pick) ? 'true' : 'false';
context.telemetry.properties.usedRecommendedEnv = hasMatchingPickDescription(pick, recommendedPickDescription) ? 'true' : 'false';
context.telemetry.properties.recommendedEnvCount =
String(picks.reduce((count, pick) => count + (isRecommendedPick(pick) ? 1 : 0), 0));
String(picks.reduce((count, pick) => count + (hasMatchingPickDescription(pick, recommendedPickDescription) ? 1 : 0), 0));

const managedEnvironment: ManagedEnvironment | undefined = pick.data;
if (!managedEnvironment) {
Expand Down Expand Up @@ -99,15 +99,13 @@ export class DwpManagedEnvironmentListStep extends AzureWizardPromptStep<DeployW

// sort the picks by recommendation
picks.sort((a, b) => {
if (isRecommendedPick(a)) {
if (hasMatchingPickDescription(a, recommendedPickDescription)) {
return -1;
} else if (isRecommendedPick(b)) {
} else if (hasMatchingPickDescription(b, recommendedPickDescription)) {
return 1;
} else {
return 0;
}
});
}
}

const isRecommendedPick = (pick: IAzureQuickPickItem<ManagedEnvironment | undefined>): boolean => pick.description === recommendedPickDescription;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { DockerfileItemStep } from "../../../image/imageSource/buildImageInAzure
import { AcrBuildSupportedOS } from "../../../image/imageSource/buildImageInAzure/OSPickStep";
import { RootFolderStep } from "../../../image/imageSource/buildImageInAzure/RootFolderStep";
import { type DeployWorkspaceProjectInternalContext } from "../DeployWorkspaceProjectInternalContext";
import { DwpAcrListStep } from "./DwpAcrListStep";
import { DwpManagedEnvironmentListStep } from "./DwpManagedEnvironmentListStep";
import { TryUseExistingResourceGroupRegistryStep } from "./TryUseExistingRegistryStep";
import { getResourcesFromContainerAppHelper, getResourcesFromManagedEnvironmentHelper } from "./containerAppsResourceHelpers";

export async function getStartingConfiguration(context: DeployWorkspaceProjectInternalContext): Promise<Partial<DeployWorkspaceProjectInternalContext>> {
Expand All @@ -22,11 +22,9 @@ export async function getStartingConfiguration(context: DeployWorkspaceProjectIn
promptSteps: [
new RootFolderStep(),
new DockerfileItemStep(),
new DwpManagedEnvironmentListStep()
new DwpManagedEnvironmentListStep(),
new DwpAcrListStep(),
],
executeSteps: [
new TryUseExistingResourceGroupRegistryStep()
]
});

await wizard.prompt();
Expand Down
Loading

0 comments on commit a9ea653

Please sign in to comment.