Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
"title": "%containerApps.editRevisionDraft%",
"category": "Azure Container Apps"
},
{
"command": "containerApps.deployRevisionDraft",
"title": "%containerApps.deployRevisionDraft%",
"category": "Azure Container Apps",
"icon": "$(cloud-upload)"
},
{
"command": "containerApps.discardRevisionDraft",
"title": "%containerApps.discardRevisionDraft%",
Expand Down Expand Up @@ -236,6 +242,16 @@
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem/i",
"group": "2@2"
},
{
"command": "containerApps.deployRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem(.*)revisionMode:single(.*)unsavedChanges:true/i",
"group": "inline@1"
},
{
"command": "containerApps.deployRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem(.*)revisionMode:single(.*)unsavedChanges:true/i",
"group": "3@1"
},
{
"command": "containerApps.discardRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /containerAppItem(.*)revisionMode:single(.*)unsavedChanges:true/i",
Expand Down Expand Up @@ -301,6 +317,16 @@
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionItem(.*)revisionState:active/i",
"group": "2@4"
},
{
"command": "containerApps.deployRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionDraftItem/i",
"group": "inline@1"
},
{
"command": "containerApps.deployRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionDraftItem/i",
"group": "1@1"
},
{
"command": "containerApps.discardRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionDraftItem/i",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"containerApps.chooseRevisionMode": "Choose Revision Mode...",
"containerApps.createRevisionDraft": "Create Draft...",
"containerApps.editRevisionDraft": "Edit Draft (Advanced)...",
"containerApps.deployRevisionDraft": "Deploy Changes...",
"containerApps.discardRevisionDraft": "Discard Changes...",
"containerApps.activateRevision": "Activate Revision",
"containerApps.deactivateRevision": "Deactivate Revision",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { chooseRevisionMode } from './revision/chooseRevisionMode';
import { deactivateRevision } from './revision/deactivateRevision';
import { restartRevision } from './revision/restartRevision';
import { createRevisionDraft } from './revisionDraft/createRevisionDraft';
import { deployRevisionDraft } from './revisionDraft/deployRevisionDraft/deployRevisionDraft';
import { discardRevisionDraft } from './revisionDraft/discardRevisionDraft';
import { editRevisionDraft } from './revisionDraft/editRevisionDraft';
import { addScaleRule } from './scaling/addScaleRule/addScaleRule';
Expand Down Expand Up @@ -66,6 +67,7 @@ export function registerCommands(): void {
// revision draft
registerCommandWithTreeNodeUnwrapping('containerApps.createRevisionDraft', createRevisionDraft);
registerCommandWithTreeNodeUnwrapping('containerApps.editRevisionDraft', editRevisionDraft);
registerCommandWithTreeNodeUnwrapping('containerApps.deployRevisionDraft', deployRevisionDraft);
registerCommandWithTreeNodeUnwrapping('containerApps.discardRevisionDraft', discardRevisionDraft);

// scaling
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizardPromptStep } from "@microsoft/vscode-azext-utils";
import { localize } from "../../../utils/localize";
import type { IDeployRevisionDraftContext } from "./IDeployRevisionDraftContext";

export class DeployRevisionDraftConfirmStep extends AzureWizardPromptStep<IDeployRevisionDraftContext> {
public async prompt(context: IDeployRevisionDraftContext): Promise<void> {
await context.ui.showWarningMessage(
localize('deployRevisionWarning', 'This will deploy a new revision to container app "{0}".', context.containerApp?.name),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should steer away from the word "revision" since we don't really expose that anywhere else. We should probably just have something to the effect that we're "Deploying to container app" or "Updating container app" or something.

{ modal: true },
{ title: localize('continue', 'Continue') }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have this title be "Deploy"

);
}

public shouldPrompt(context: IDeployRevisionDraftContext): boolean {
return !!context.template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils";
import type { Progress } from "vscode";
import { ext } from "../../../extensionVariables";
import { ContainerAppItem, ContainerAppModel, getContainerEnvelopeWithSecrets } from "../../../tree/ContainerAppItem";
import { RevisionDraftItem } from "../../../tree/revisionManagement/RevisionDraftItem";
import { localize } from "../../../utils/localize";
import { updateContainerApp } from "../../../utils/updateContainerApp";
import type { IDeployRevisionDraftContext } from "./IDeployRevisionDraftContext";

export class DeployRevisionDraftStep extends AzureWizardExecuteStep<IDeployRevisionDraftContext> {
public priority: number = 260;

public async execute(context: IDeployRevisionDraftContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
const containerApp: ContainerAppModel = nonNullProp(context, 'containerApp');
const containerAppEnvelope = await getContainerEnvelopeWithSecrets(context, context.subscription, containerApp);
containerAppEnvelope.template = context.template;

const creatingRevision: string = localize('creatingRevision', 'Creating revision...');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still says revision here.

progress.report({ message: creatingRevision });

const id: string = containerApp.revisionsMode === KnownActiveRevisionsMode.Single ? containerApp.id : `${containerApp.id}/${RevisionDraftItem.idSuffix}`;

await ext.state.runWithTemporaryDescription(id, creatingRevision, async () => {
await updateContainerApp(context, context.subscription, containerAppEnvelope);
const updatedContainerApp = await ContainerAppItem.Get(context, context.subscription, containerApp.resourceGroup, containerApp.name);

if (containerApp.revisionsMode === KnownActiveRevisionsMode.Multiple) {
// Display the name of the newly created revision when in multiple revisions mode
context.activityTitle = localize('deployRevision', 'Deploy revision "{0}" to container app "{1}"', updatedContainerApp.latestRevisionName, containerApp.name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still says revision here.

}
});
}

public shouldExecute(context: IDeployRevisionDraftContext): boolean {
return !!context.template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import type { Template } from "@azure/arm-appcontainers";
import type { ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
import type { IContainerAppContext } from "../../IContainerAppContext";

export interface IDeployRevisionDraftContext extends IContainerAppContext, ExecuteActivityContext {
template: Template;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { ContainerAppsAPIClient, KnownActiveRevisionsMode, Revision } from "@azure/arm-appcontainers";
import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, AzureWizardExecuteStep, AzureWizardPromptStep, IActionContext, createSubscriptionContext, nonNullProp, nonNullValue, nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import * as deepEqual from "deep-eql";
import { ext } from "../../../extensionVariables";
import type { ContainerAppItem, ContainerAppModel } from "../../../tree/ContainerAppItem";
import { RevisionDraftItem } from "../../../tree/revisionManagement/RevisionDraftItem";
import { createActivityContext } from "../../../utils/activityUtils";
import { createContainerAppsAPIClient } from "../../../utils/azureClients";
import { delay } from "../../../utils/delay";
import { localize } from "../../../utils/localize";
import { pickContainerApp } from "../../../utils/pickContainerApp";
import { DeployRevisionDraftConfirmStep } from "./DeployRevisionDraftConfirmStep";
import { DeployRevisionDraftStep } from "./DeployRevisionDraftStep";
import type { IDeployRevisionDraftContext } from "./IDeployRevisionDraftContext";

export async function deployRevisionDraft(context: IActionContext, node?: ContainerAppItem | RevisionDraftItem): Promise<void> {
const item = node ?? await pickContainerApp(context);

if (!ext.revisionDraftFileSystem.doesContainerAppsItemHaveRevisionDraft(item)) {
throw new Error(localize('noDraftExists', 'No draft changes exist for container app "{0}".', item.containerApp.name));
}

const { subscription, containerApp } = item;

const wizardContext: IDeployRevisionDraftContext = {
...context,
...createSubscriptionContext(subscription),
...(await createActivityContext()),
subscription,
containerApp,
template: nonNullValue(ext.revisionDraftFileSystem.parseRevisionDraft(item)),
};

if (!await hasUnsavedChanges(wizardContext, item)) {
throw new Error(localize('noUnsavedChanges', 'No unsaved changes detected to deploy to container app "{0}".', containerApp.name));
}

const promptSteps: AzureWizardPromptStep<IDeployRevisionDraftContext>[] = [
new DeployRevisionDraftConfirmStep()
];

const executeSteps: AzureWizardExecuteStep<IDeployRevisionDraftContext>[] = [
new DeployRevisionDraftStep()
];

const wizard: AzureWizard<IDeployRevisionDraftContext> = new AzureWizard(wizardContext, {
title: localize('deploy', 'Deploy changes to container app "{0}"', containerApp.name),
promptSteps,
executeSteps,
});

await wizard.prompt();
await wizard.execute();

if (item.containerApp.revisionsMode === KnownActiveRevisionsMode.Single) {
ext.revisionDraftFileSystem.discardRevisionDraft(item);
} else {
await ext.state.showDeleting(
`${item.containerApp.id}/${RevisionDraftItem.idSuffix}`,
async () => {
// Add a short delay to display the deleting message
await delay(5);
ext.revisionDraftFileSystem.discardRevisionDraft(item);
}
);
}

ext.state.notifyChildrenChanged(item.containerApp.managedEnvironmentId);
}

async function hasUnsavedChanges(context: IDeployRevisionDraftContext, item: ContainerAppItem | RevisionDraftItem): Promise<boolean> {
const containerApp: ContainerAppModel = nonNullProp(context, 'containerApp');

if (context.containerApp?.revisionsMode === KnownActiveRevisionsMode.Single) {
return !!containerApp.template && !deepEqual(containerApp.template, context.template);
} else {
const client: ContainerAppsAPIClient = await createContainerAppsAPIClient(context);
const revisions: Revision[] = await uiUtils.listAllIterator(client.containerAppsRevisions.listRevisions(containerApp.resourceGroup, containerApp.name));

const baseRevisionName: string = nonNullValueAndProp(ext.revisionDraftFileSystem.getRevisionDraftFile(item), 'baseRevisionName');
const baseRevision: Revision | undefined = revisions.find(revision => revision.name === baseRevisionName);

return !!baseRevision?.template && !deepEqual(baseRevision.template, context.template);
}
}