Skip to content

Commit b112787

Browse files
authored
Add extra guard clauses to deployment commands (#815)
1 parent 3781ae6 commit b112787

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@
378378
},
379379
{
380380
"command": "containerApps.deployContainerApp",
381-
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem/i",
381+
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem(.*)revisionMode:single/i",
382382
"group": "2@1"
383383
},
384384
{

src/commands/deployContainerApp/deployContainerApp.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
67
import { type ResourceGroup } from "@azure/arm-resources";
78
import { LocationListStep, ResourceGroupListStep } from "@microsoft/vscode-azext-azureutils";
89
import { activityInfoIcon, activitySuccessContext, AzureWizard, createSubscriptionContext, createUniversallyUniqueContextValue, GenericTreeItem, nonNullProp, nonNullValue, type IActionContext, type ISubscriptionActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
@@ -16,15 +17,25 @@ import { getVerifyProvidersStep } from "../../utils/getVerifyProvidersStep";
1617
import { localize } from "../../utils/localize";
1718
import { pickContainerApp } from "../../utils/pickItem/pickContainerApp";
1819
import { deployWorkspaceProject } from "../deployWorkspaceProject/deployWorkspaceProject";
20+
import { editContainerCommandName } from "../editContainer/editContainer";
1921
import { ContainerAppUpdateStep } from "../image/imageSource/ContainerAppUpdateStep";
2022
import { ImageSourceListStep } from "../image/imageSource/ImageSourceListStep";
2123
import { type ContainerAppDeployContext } from "./ContainerAppDeployContext";
2224

25+
const deployContainerAppCommandName: string = localize('deployContainerApp', 'Deploy to Container App...');
26+
2327
export async function deployContainerApp(context: IActionContext, node?: ContainerAppItem): Promise<void> {
2428
const item: ContainerAppItem = node ?? await pickContainerApp(context);
2529
const subscriptionContext: ISubscriptionContext = createSubscriptionContext(item.subscription);
2630
const subscriptionActionContext: ISubscriptionActionContext = { ...context, ...subscriptionContext };
2731

32+
if (item.containerApp.revisionsMode === KnownActiveRevisionsMode.Multiple) {
33+
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.', deployContainerAppCommandName, editContainerCommandName));
34+
}
35+
if ((item.containerApp.template?.containers?.length ?? 0) > 1) {
36+
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.', deployContainerAppCommandName, editContainerCommandName));
37+
}
38+
2839
// Prompt for image source before initializing the wizard in case we need to redirect the call to 'deployWorkspaceProject' instead
2940
const imageSource: ImageSource = await promptImageSource(subscriptionActionContext);
3041
if (imageSource === ImageSource.RemoteAcrBuild) {

src/commands/deployWorkspaceProject/deployWorkspaceProject.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { type DeployWorkspaceProjectInternalContext } from "./internal/DeployWor
2626
import { deployWorkspaceProjectInternal } from "./internal/deployWorkspaceProjectInternal";
2727
import { convertV1ToV2SettingsSchema } from "./settings/convertSettings/convertV1ToV2SettingsSchema";
2828

29+
export const deployWorkspaceProjectCommandName: string = localize('deployWorkspaceProject', 'Deploy Project from Workspace...');
30+
2931
export async function deployWorkspaceProject(context: IActionContext & Partial<DeployWorkspaceProjectContext>, item?: ContainerAppItem | ManagedEnvironmentItem): Promise<DeployWorkspaceProjectResults> {
3032
// If an incompatible tree item is passed, treat it as if no item was passed
3133
if (item && !ContainerAppItem.isContainerAppItem(item) && !ManagedEnvironmentItem.isManagedEnvironmentItem(item)) {

src/commands/deployWorkspaceProject/internal/deployWorkspaceProjectInternal.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.md in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
67
import { LocationListStep, ResourceGroupCreateStep } from "@microsoft/vscode-azext-azureutils";
78
import { AzureWizard, GenericTreeItem, activityInfoIcon, activitySuccessContext, createUniversallyUniqueContextValue, nonNullValueAndProp, type AzureWizardExecuteStep, type AzureWizardPromptStep, type ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
89
import { ProgressLocation, window } from "vscode";
@@ -14,9 +15,11 @@ import { localize } from "../../../utils/localize";
1415
import { ContainerAppCreateStep } from "../../createContainerApp/ContainerAppCreateStep";
1516
import { LogAnalyticsCreateStep } from "../../createManagedEnvironment/LogAnalyticsCreateStep";
1617
import { ManagedEnvironmentCreateStep } from "../../createManagedEnvironment/ManagedEnvironmentCreateStep";
18+
import { editContainerCommandName } from "../../editContainer/editContainer";
1719
import { ContainerAppUpdateStep } from "../../image/imageSource/ContainerAppUpdateStep";
1820
import { ImageSourceListStep } from "../../image/imageSource/ImageSourceListStep";
1921
import { IngressPromptStep } from "../../ingress/IngressPromptStep";
22+
import { deployWorkspaceProjectCommandName } from "../deployWorkspaceProject";
2023
import { formatSectionHeader } from "../formatSectionHeader";
2124
import { AppResourcesNameStep } from "./AppResourcesNameStep";
2225
import { DeployWorkspaceProjectConfirmStep } from "./DeployWorkspaceProjectConfirmStep";
@@ -78,6 +81,13 @@ export async function deployWorkspaceProjectInternal(
7881
startingConfiguration = await getStartingConfiguration({ ...context });
7982
});
8083

84+
if (startingConfiguration?.containerApp?.revisionsMode === KnownActiveRevisionsMode.Multiple) {
85+
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));
86+
}
87+
if ((startingConfiguration?.containerApp?.template?.containers?.length ?? 0) > 1) {
88+
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));
89+
}
90+
8191
const wizardContext: DeployWorkspaceProjectInternalContext = {
8292
...context,
8393
...activityContext,

src/commands/editContainer/editContainer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import { ContainerEditDraftStep } from "./ContainerEditDraftStep";
2222
import { ContainerEditStartingResourcesLogStep } from "./ContainerEditStartingResourcesLogStep";
2323
import { RegistryAndSecretsUpdateStep } from "./RegistryAndSecretsUpdateStep";
2424

25+
export const editContainerCommandName: string = localize('editContainer', 'Edit Container...');
26+
2527
// Edits both the 'image' and 'environmentVariables' portion of the container profile (draft)
2628
export async function editContainer(context: IActionContext, node?: ContainersItem | ContainerItem): Promise<void> {
2729
const item: ContainerItem | ContainersItem = node ?? await pickContainer(context, { autoSelectDraft: true });

0 commit comments

Comments
 (0)