Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -127,6 +127,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 @@ -241,6 +247,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 @@ -306,6 +322,16 @@
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionItem(.*)revisionState:active/i",
"group": "2@4"
},
{
"command": "containerApps.deployRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionDraftItem(.*)unsavedChanges:true/i",
"group": "inline@1"
},
{
"command": "containerApps.deployRevisionDraft",
"when": "view =~ /(azureResourceGroups|azureFocusView)/ && viewItem =~ /revisionDraftItem(.*)unsavedChanges:true/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 @@ -18,6 +18,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 @@ -70,6 +71,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 any unsaved changes to container app "{0}".', context.containerApp?.name),
Copy link
Copy Markdown
Member

@nturinski nturinski Jul 28, 2023

Choose a reason for hiding this comment

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

I think we should probably say something more similar to deploy.

Are you sure you want to deploy changes to "{0}"? This will overwrite your previous deployment.

{ 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 = nonNullProp(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 | undefined;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*---------------------------------------------------------------------------------------------
* 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 } 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);

const { subscription, containerApp } = item;

const wizardContext: IDeployRevisionDraftContext = {
...context,
...createSubscriptionContext(subscription),
...(await createActivityContext()),
subscription,
containerApp,
template: 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 && !!context.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 | undefined = ext.revisionDraftFileSystem.getRevisionDraftFile(item)?.baseRevisionName;
const baseRevision: Revision | undefined = revisions.find(revision => baseRevisionName && revision.name === baseRevisionName);

return !!baseRevision?.template && !!context.template && !deepEqual(baseRevision.template, context.template);
}
}
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,6 @@ export const DOCKERFILE_GLOB_PATTERN = '**/{*.[dD][oO][cC][kK][eE][rR][fF][iI][l

export const revisionModeSingleContextValue: string = 'revisionMode:single';
export const revisionModeMultipleContextValue: string = 'revisionMode:multiple';

export const unsavedChangesTrueContextValue: string = 'unsavedChanges:true';
export const unsavedChangesFalseContextValue: string = 'unsavedChanges:false';
10 changes: 4 additions & 6 deletions src/tree/ContainerAppItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as deepEqual from "deep-eql";
import { TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
import { DeleteAllContainerAppsStep } from "../commands/deleteContainerApp/DeleteAllContainerAppsStep";
import { IDeleteContainerAppWizardContext } from "../commands/deleteContainerApp/IDeleteContainerAppWizardContext";
import { revisionModeMultipleContextValue, revisionModeSingleContextValue } from "../constants";
import { revisionModeMultipleContextValue, revisionModeSingleContextValue, unsavedChangesFalseContextValue, unsavedChangesTrueContextValue } from "../constants";
import { ext } from "../extensionVariables";
import { createActivityContext } from "../utils/activityUtils";
import { createContainerAppsAPIClient, createContainerAppsClient } from "../utils/azureClients";
Expand All @@ -21,12 +21,10 @@ import { treeUtils } from "../utils/treeUtils";
import type { ContainerAppsItem, TreeElementBase } from "./ContainerAppsBranchDataProvider";
import { LogsGroupItem } from "./LogsGroupItem";
import { ConfigurationItem } from "./configurations/ConfigurationItem";
import { RevisionsDraftModel } from "./revisionManagement/RevisionDraftItem";
import { RevisionItem } from "./revisionManagement/RevisionItem";
import { RevisionsItem } from "./revisionManagement/RevisionsItem";

const unsavedChangesTrueContextValue: string = 'unsavedChanges:true';
const unsavedChangesFalseContextValue: string = 'unsavedChanges:false';

export interface ContainerAppModel extends ContainerApp {
id: string;
name: string;
Expand All @@ -35,7 +33,7 @@ export interface ContainerAppModel extends ContainerApp {
revisionsMode: KnownActiveRevisionsMode;
}

export class ContainerAppItem implements ContainerAppsItem {
export class ContainerAppItem implements ContainerAppsItem, RevisionsDraftModel {
static readonly contextValue: string = 'containerAppItem';
static readonly contextValueRegExp: RegExp = new RegExp(ContainerAppItem.contextValue);

Expand Down Expand Up @@ -164,7 +162,7 @@ export class ContainerAppItem implements ContainerAppsItem {
ext.state.notifyChildrenChanged(this.containerApp.managedEnvironmentId);
}

private hasUnsavedChanges(): boolean {
hasUnsavedChanges(): boolean {
const draftTemplate = ext.revisionDraftFileSystem.parseRevisionDraft(this);
if (!this.containerApp.template || !draftTemplate) {
return false;
Expand Down
Loading