Skip to content

Commit 8145ee0

Browse files
authored
Consolidate code into separate "deployContainerApp" and "imageSource" directories (#294)
1 parent 74d8c7e commit 8145ee0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+129
-130
lines changed

src/commands/chooseRevisionMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ContainerAppModel } from "../tree/ContainerAppItem";
1111
import { ContainerAppsItem } from "../tree/ContainerAppsBranchDataProvider";
1212
import { localize } from "../utils/localize";
1313
import { pickContainerApp } from "../utils/pickContainerApp";
14-
import { updateContainerApp } from "./updateContainerApp";
14+
import { updateContainerApp } from "./deployContainerApp/updateContainerApp";
1515

1616
export async function chooseRevisionMode(context: IActionContext, node?: ContainerAppsItem): Promise<void> {
1717
const { subscription, containerApp } = node ?? await pickContainerApp(context);

src/commands/createContainerApp/ContainerAppCreateStep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ext } from "../../extensionVariables";
1212
import { ContainerAppItem } from "../../tree/ContainerAppItem";
1313
import { createContainerAppsAPIClient } from "../../utils/azureClients";
1414
import { localize } from "../../utils/localize";
15-
import { getContainerNameForImage } from "../deploy/deployFromRegistry/getContainerNameForImage";
15+
import { getContainerNameForImage } from "../imageSource/containerRegistry/getContainerNameForImage";
1616
import { IContainerAppContext } from "./IContainerAppContext";
1717

1818
export class ContainerAppCreateStep extends AzureWizardExecuteStep<IContainerAppContext> {

src/commands/createContainerApp/IContainerAppContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import { IResourceGroupWizardContext } from '@microsoft/vscode-azext-azureutils';
77
import { ExecuteActivityContext } from "@microsoft/vscode-azext-utils";
88
import { ContainerAppModel } from "../../tree/ContainerAppItem";
9-
import { IDeployBaseContext } from '../deploy/IDeployBaseContext';
9+
import { IImageSourceBaseContext } from '../imageSource/IImageSourceBaseContext';
1010

11-
export interface IContainerAppContext extends IResourceGroupWizardContext, IDeployBaseContext {
11+
export interface IContainerAppContext extends IResourceGroupWizardContext, IImageSourceBaseContext {
1212
managedEnvironmentId: string;
1313
newContainerAppName?: string;
1414

src/commands/createContainerApp/createContainerApp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ManagedEnvironmentItem } from "../../tree/ManagedEnvironmentItem";
1212
import { createActivityContext } from "../../utils/activityUtils";
1313
import { localize } from "../../utils/localize";
1414
import { containerAppEnvironmentExperience } from "../../utils/pickContainerApp";
15-
import { ImageSourceListStep } from "../deploy/ImageSourceListStep";
15+
import { ImageSourceListStep } from "../imageSource/ImageSourceListStep";
1616
import { ContainerAppCreateStep } from "./ContainerAppCreateStep";
1717
import { ContainerAppNameStep } from "./ContainerAppNameStep";
1818
import { EnableIngressStep } from "./EnableIngressStep";

src/commands/deploy/ContainerAppOverwriteConfirmStep.ts renamed to src/commands/deployContainerApp/ContainerAppOverwriteConfirmStep.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { AzureWizardPromptStep, nonNullProp } from "@microsoft/vscode-azext-util
88
import { MessageItem } from "vscode";
99
import { ContainerAppModel } from "../../tree/ContainerAppItem";
1010
import { localize } from "../../utils/localize";
11-
import { IDeployBaseContext } from "./IDeployBaseContext";
11+
import { IDeployContainerAppContext } from "./deployContainerApp";
1212

13-
export class ContainerAppOverwriteConfirmStep extends AzureWizardPromptStep<IDeployBaseContext> {
13+
export class ContainerAppOverwriteConfirmStep extends AzureWizardPromptStep<IDeployContainerAppContext> {
1414
public hideStepCount: boolean = true;
1515

16-
public async prompt(context: IDeployBaseContext): Promise<void> {
16+
public async prompt(context: IDeployContainerAppContext): Promise<void> {
1717
const containerApp: ContainerAppModel = nonNullProp(context, 'targetContainer');
1818
const warning: string = containerApp.revisionsMode === KnownActiveRevisionsMode.Single ?
1919
localize('confirmDeploySingle', 'Are you sure you want to deploy to "{0}"? This will overwrite the active revision and unsupported features in VS Code will be lost.', containerApp.name) :
@@ -23,12 +23,12 @@ export class ContainerAppOverwriteConfirmStep extends AzureWizardPromptStep<IDep
2323
await context.ui.showWarningMessage(warning, { modal: true, stepName: 'confirmDestructiveDeployment' }, ...items);
2424
}
2525

26-
public shouldPrompt(context: IDeployBaseContext): boolean {
26+
public shouldPrompt(context: IDeployContainerAppContext): boolean {
2727
return !!context.targetContainer && this.hasUnsupportedFeatures(context);
2828
}
2929

3030
// Check for any portal features that VS Code doesn't currently support
31-
private hasUnsupportedFeatures(context: IDeployBaseContext): boolean {
31+
private hasUnsupportedFeatures(context: IDeployContainerAppContext): boolean {
3232
const containerApp: ContainerAppModel = nonNullProp(context, 'targetContainer');
3333
if (containerApp.template?.volumes) {
3434
return true;

src/commands/deploy/ContainerAppUpdateStep.ts renamed to src/commands/deployContainerApp/ContainerAppUpdateStep.ts

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

6-
import type { ContainerAppsAPIClient } from "@azure/arm-appcontainers";
7-
import { AzureWizardExecuteStep, createSubscriptionContext, nonNullProp } from "@microsoft/vscode-azext-utils";
6+
import { AzureWizardExecuteStep, nonNullProp } from "@microsoft/vscode-azext-utils";
87
import { Progress } from "vscode";
98
import { ext } from "../../extensionVariables";
109
import { ContainerAppItem, ContainerAppModel, getContainerEnvelopeWithSecrets } from "../../tree/ContainerAppItem";
11-
import { createContainerAppsAPIClient } from "../../utils/azureClients";
1210
import { localize } from "../../utils/localize";
1311
import { showContainerAppCreated } from "../createContainerApp/showContainerAppCreated";
14-
import { IDeployBaseContext } from "./IDeployBaseContext";
15-
import { getContainerNameForImage } from "./deployFromRegistry/getContainerNameForImage";
12+
import { getContainerNameForImage } from "../imageSource/containerRegistry/getContainerNameForImage";
13+
import { IDeployContainerAppContext } from "./deployContainerApp";
14+
import { updateContainerApp } from "./updateContainerApp";
1615

17-
export class ContainerAppUpdateStep extends AzureWizardExecuteStep<IDeployBaseContext> {
16+
export class ContainerAppUpdateStep extends AzureWizardExecuteStep<IDeployContainerAppContext> {
1817
public priority: number = 260;
1918

20-
public async execute(context: IDeployBaseContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
19+
public async execute(context: IDeployContainerAppContext, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
2120
const containerApp: ContainerAppModel = nonNullProp(context, 'targetContainer');
2221
const containerAppEnvelope = await getContainerEnvelopeWithSecrets(context, context.subscription, containerApp);
2322

@@ -39,8 +38,7 @@ export class ContainerAppUpdateStep extends AzureWizardExecuteStep<IDeployBaseCo
3938
ext.outputChannel.appendLog(creatingRevision);
4039

4140
await ext.state.runWithTemporaryDescription(containerApp.id, localize('creatingRevisionShort', 'Creating revision...'), async () => {
42-
const appClient: ContainerAppsAPIClient = await createContainerAppsAPIClient([context, createSubscriptionContext(context.subscription)]);
43-
await appClient.containerApps.beginCreateOrUpdateAndWait(containerApp.resourceGroup, containerApp.name, containerAppEnvelope);
41+
await updateContainerApp(context, context.subscription, containerAppEnvelope);
4442
const updatedContainerApp = await ContainerAppItem.Get(context, context.subscription, containerApp.resourceGroup, containerApp.name);
4543
void showContainerAppCreated(updatedContainerApp, true);
4644
ext.state.notifyChildrenChanged(containerApp.managedEnvironmentId);

src/commands/deploy/deploy.ts renamed to src/commands/deployContainerApp/deployContainerApp.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,39 @@ import { webProvider } from "../../constants";
88
import { ContainerAppItem } from "../../tree/ContainerAppItem";
99
import { localize } from "../../utils/localize";
1010
import { pickContainerApp } from "../../utils/pickContainerApp";
11+
import { IImageSourceBaseContext } from "../imageSource/IImageSourceBaseContext";
12+
import { ImageSourceListStep } from "../imageSource/ImageSourceListStep";
1113
import { ContainerAppOverwriteConfirmStep } from "./ContainerAppOverwriteConfirmStep";
1214
import { ContainerAppUpdateStep } from "./ContainerAppUpdateStep";
13-
import { IDeployBaseContext } from "./IDeployBaseContext";
14-
import { ImageSourceListStep } from "./ImageSourceListStep";
1515

16-
export async function deploy(context: ITreeItemPickerContext & Partial<IDeployBaseContext>, node?: ContainerAppItem): Promise<void> {
16+
export type IDeployContainerAppContext = IImageSourceBaseContext;
17+
18+
export async function deployContainerApp(context: ITreeItemPickerContext & Partial<IDeployContainerAppContext>, node?: ContainerAppItem): Promise<void> {
1719
if (!node) {
1820
context.suppressCreatePick = true;
1921
node = await pickContainerApp(context);
2022
}
2123

2224
const { subscription, containerApp } = node;
2325

24-
const wizardContext: IDeployBaseContext = {
26+
const wizardContext: IDeployContainerAppContext = {
2527
...context,
2628
...createSubscriptionContext(subscription),
2729
subscription,
2830
targetContainer: containerApp
2931
};
3032

31-
const promptSteps: AzureWizardPromptStep<IDeployBaseContext>[] = [
33+
const promptSteps: AzureWizardPromptStep<IDeployContainerAppContext>[] = [
3234
new ContainerAppOverwriteConfirmStep(),
3335
new ImageSourceListStep()
3436
];
3537

36-
const executeSteps: AzureWizardExecuteStep<IDeployBaseContext>[] = [
38+
const executeSteps: AzureWizardExecuteStep<IDeployContainerAppContext>[] = [
3739
new VerifyProvidersStep([webProvider]),
3840
new ContainerAppUpdateStep()
3941
];
4042

41-
const wizard: AzureWizard<IDeployBaseContext> = new AzureWizard(wizardContext, {
43+
const wizard: AzureWizard<IDeployContainerAppContext> = new AzureWizard(wizardContext, {
4244
title: localize('deploy', 'Deploying to "{0}"', containerApp.name),
4345
promptSteps,
4446
executeSteps,

src/commands/deploy/deployImageApi.ts renamed to src/commands/deployContainerApp/deployImageApi.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { callWithMaskHandling, createSubscriptionContext, ISubscriptionActionCon
77
import { acrDomain, ImageSource } from "../../constants";
88
import { detectRegistryDomain, getRegistryFromAcrName } from "../../utils/imageNameUtils";
99
import { pickContainerApp } from "../../utils/pickContainerApp";
10-
import { deploy } from "./deploy";
11-
import { IDeployFromRegistryContext } from "./deployFromRegistry/IDeployFromRegistryContext";
10+
import { IContainerRegistryImageContext } from "../imageSource/containerRegistry/IContainerRegistryImageContext";
11+
import { deployContainerApp } from "./deployContainerApp";
1212

1313
// The interface of the command options passed to the Azure Container Apps extension's deployImageToAca command
1414
// This interface is shared with the Docker extension (https://github.com/microsoft/vscode-docker)
@@ -19,12 +19,12 @@ interface DeployImageToAcaOptionsContract {
1919
secret?: string;
2020
}
2121

22-
export async function deployImageApi(context: ITreeItemPickerContext & Partial<IDeployFromRegistryContext>, deployImageOptions: DeployImageToAcaOptionsContract): Promise<void> {
22+
export async function deployImageApi(context: ITreeItemPickerContext & Partial<IContainerRegistryImageContext>, deployImageOptions: DeployImageToAcaOptionsContract): Promise<void> {
2323
context.suppressCreatePick = true;
2424
const node = await pickContainerApp(context);
2525
const { subscription } = node;
2626

27-
Object.assign(context, {...createSubscriptionContext(subscription), imageSource: ImageSource.ExternalRegistry }, deployImageOptions);
27+
Object.assign(context, {...createSubscriptionContext(subscription), imageSource: ImageSource.ContainerRegistry }, deployImageOptions);
2828

2929
context.registryDomain = detectRegistryDomain(deployImageOptions.registryName);
3030
if (context.registryDomain === acrDomain) {
@@ -41,8 +41,8 @@ export async function deployImageApi(context: ITreeItemPickerContext & Partial<I
4141
context.valuesToMask.push(deployImageOptions.image);
4242

4343
if (deployImageOptions.secret) {
44-
return callWithMaskHandling<void>(() => deploy(context, node), deployImageOptions.secret);
44+
return callWithMaskHandling<void>(() => deployContainerApp(context, node), deployImageOptions.secret);
4545
} else {
46-
return deploy(context, node);
46+
return deployContainerApp(context, node);
4747
}
4848
}

src/commands/updateContainerApp.ts renamed to src/commands/deployContainerApp/updateContainerApp.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { ContainerApp, ContainerAppsAPIClient } from "@azure/arm-appcontainers";
77
import { getResourceGroupFromId } from "@microsoft/vscode-azext-azureutils";
8-
import { createSubscriptionContext, IActionContext, nonNullProp } from "@microsoft/vscode-azext-utils";
8+
import { IActionContext, createSubscriptionContext, nonNullProp } from "@microsoft/vscode-azext-utils";
99
import { AzureSubscription } from "@microsoft/vscode-azureresources-api";
10-
import { createContainerAppsAPIClient } from "../utils/azureClients";
10+
import { createContainerAppsAPIClient } from "../../utils/azureClients";
1111

12-
export async function updateContainerApp(context: IActionContext, subscription: AzureSubscription, containerApp: ContainerApp, updatedSetting: Omit<ContainerApp, 'location'>): Promise<void> {
12+
export async function updateContainerApp(context: IActionContext, subscription: AzureSubscription, containerApp: ContainerApp, updatedSetting?: Omit<ContainerApp, 'location'>): Promise<void> {
1313
const client: ContainerAppsAPIClient = await createContainerAppsAPIClient([context, createSubscriptionContext(subscription)]);
1414
const resourceGroupName = getResourceGroupFromId(nonNullProp(containerApp, 'id'));
1515
const name = nonNullProp(containerApp, 'name');
16-
const updatedApp: ContainerApp = { ...updatedSetting, location: containerApp.location };
17-
16+
// If no update setting is provided, just use the original containerApp; otherwise, merge the update settings with the original containerApp
17+
const updatedApp: ContainerApp = !updatedSetting ? containerApp : { ...updatedSetting, location: containerApp.location };
1818
await client.containerApps.beginUpdateAndWait(resourceGroupName, name, updatedApp);
1919
}

src/commands/deploy/EnvironmentVariablesListStep.ts renamed to src/commands/imageSource/EnvironmentVariablesListStep.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { parse } from "dotenv";
88
import { ImageSource } from "../../constants";
99
import { localize } from "../../utils/localize";
1010
import { selectWorkspaceFile } from "../../utils/workspaceUtils";
11-
import { IDeployBaseContext } from "./IDeployBaseContext";
11+
import { IImageSourceBaseContext } from "./IImageSourceBaseContext";
1212

1313
const skipForNowLabel: string = localize('skipForNow', '$(clock) Skip for now');
1414

15-
export class EnvironmentVariablesListStep extends AzureWizardPromptStep<IDeployBaseContext> {
16-
public async prompt(context: IDeployBaseContext): Promise<void> {
15+
export class EnvironmentVariablesListStep extends AzureWizardPromptStep<IImageSourceBaseContext> {
16+
public async prompt(context: IImageSourceBaseContext): Promise<void> {
1717
const input = await context.ui.showQuickPick([{ label: localize('set', 'Set with environment variable file') }, { label: skipForNowLabel }],
1818
{ placeHolder: localize('setEnvVar', 'Set environment variables in container instance') });
1919

@@ -23,11 +23,11 @@ export class EnvironmentVariablesListStep extends AzureWizardPromptStep<IDeployB
2323
}
2424
}
2525

26-
public shouldPrompt(context: IDeployBaseContext): boolean {
26+
public shouldPrompt(context: IImageSourceBaseContext): boolean {
2727
return context.imageSource !== ImageSource.QuickStartImage && context.environmentVariables === undefined;
2828
}
2929

30-
private async selectEnvironmentSettings(context: IDeployBaseContext) {
30+
private async selectEnvironmentSettings(context: IImageSourceBaseContext) {
3131
const envFileFsPath: string = await selectWorkspaceFile(context, 'Select a .env file', { filters: { 'env file': ['env', 'env.*'] } }, '**/*.{env,env.*}');
3232
const data = await AzExtFsExtra.readFile(envFileFsPath);
3333
return parse(data);

0 commit comments

Comments
 (0)