Skip to content

Commit

Permalink
Merge with main
Browse files Browse the repository at this point in the history
  • Loading branch information
MicroFish91 committed Dec 17, 2024
2 parents 0d03759 + 8619562 commit c78ba36
Show file tree
Hide file tree
Showing 22 changed files with 329 additions and 163 deletions.
2 changes: 2 additions & 0 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// At runtime the tests live in dist/tests and will therefore pick up the main webpack bundle at dist/extension.bundle.js.
export * from '@microsoft/vscode-azext-utils';
// Export activate/deactivate for main.js
export * from './src/commands/createManagedEnvironment/createManagedEnvironment';
export * from './src/commands/deployWorkspaceProject/deployWorkspaceProject';
export * from './src/commands/deployWorkspaceProject/getDeployWorkspaceProjectResults';
export * from './src/commands/deployWorkspaceProject/internal/DeployWorkspaceProjectInternalContext';
Expand All @@ -31,6 +32,7 @@ export * from './src/commands/ingress/tryGetDockerfileExposePorts';
export { activate, deactivate } from './src/extension';
export * from './src/extensionVariables';
export * from './src/utils/azureClients';
export * from './src/utils/imageNameUtils';
export * from './src/utils/settingUtils';
export * from './src/utils/validateUtils';

Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@
"devDependencies": {
"@azure/ms-rest-azure-env": "^2.0.0",
"@microsoft/eslint-config-azuretools": "^0.2.2",
"@microsoft/vscode-azext-dev": "^2.0.4",
"@microsoft/vscode-azext-dev": "^2.0.5",
"@types/deep-eql": "^4.0.0",
"@types/fs-extra": "^8.1.1",
"@types/gulp": "^4.0.6",
Expand Down Expand Up @@ -831,7 +831,7 @@
"@azure/storage-blob": "^12.4.1",
"@microsoft/vscode-azext-azureutils": "^3.1.1",
"@microsoft/vscode-azext-github": "^1.0.0",
"@microsoft/vscode-azext-utils": "^2.5.10",
"@microsoft/vscode-azext-utils": "^2.5.11",
"@microsoft/vscode-azureresources-api": "^2.0.2",
"buffer": "^6.0.3",
"dayjs": "^1.11.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type ManagedEnvironment } from "@azure/arm-appcontainers";
import { LocationListStep, ResourceGroupCreateStep } from "@microsoft/vscode-azext-azureutils";
import { AzureWizard, createSubscriptionContext, nonNullProp, subscriptionExperience, type AzureWizardExecuteStep, type AzureWizardPromptStep, type IActionContext } from "@microsoft/vscode-azext-utils";
import { type AzureSubscription } from "@microsoft/vscode-azureresources-api";
Expand All @@ -16,7 +17,7 @@ import { type ManagedEnvironmentCreateContext } from "./ManagedEnvironmentCreate
import { ManagedEnvironmentCreateStep } from "./ManagedEnvironmentCreateStep";
import { ManagedEnvironmentNameStep } from "./ManagedEnvironmentNameStep";

export async function createManagedEnvironment(context: IActionContext, node?: { subscription: AzureSubscription }): Promise<void> {
export async function createManagedEnvironment(context: IActionContext, node?: { subscription: AzureSubscription }): Promise<ManagedEnvironment> {
const subscription = node?.subscription ?? await subscriptionExperience(context, ext.rgApiV2.resources.azureResourceTreeDataProvider);

const wizardContext: ManagedEnvironmentCreateContext = {
Expand Down Expand Up @@ -54,4 +55,5 @@ export async function createManagedEnvironment(context: IActionContext, node?: {
await wizard.execute();

ext.branchDataProvider.refresh();
return nonNullProp(wizardContext, 'managedEnvironment');
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type EnvironmentVar } from "@azure/arm-appcontainers";
import { type SetTelemetryProps } from "../../../telemetry/SetTelemetryProps";
import { type ContainerUpdateTelemetryProps as TelemetryProps } from "../../../telemetry/commandTelemetryProps";
import { type ISecretContext } from "../../secret/ISecretContext";
Expand All @@ -14,6 +15,8 @@ export interface EnvironmentVariableAddBaseContext extends EnvironmentVariablesB
newEnvironmentVariableName?: string;
newEnvironmentVariableManualInput?: string;
// secretName

environmentVariable?: EnvironmentVar;
}

export type EnvironmentVariableAddContext = EnvironmentVariableAddBaseContext & SetTelemetryProps<TelemetryProps>;
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ export class EnvironmentVariableAddDraftStep<T extends EnvironmentVariableAddCon

public async execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void> {
progress.report({ message: localize('addingEnv', 'Adding environment variable (draft)...') });
context.environmentVariable = {
name: context.newEnvironmentVariableName,
value: context.newEnvironmentVariableManualInput ?? '', // The server doesn't allow this value to be undefined
secretRef: context.secretName,
};

this.revisionDraftTemplate.containers ??= [];

const container: Container = this.revisionDraftTemplate.containers[context.containersIdx] ?? {};
container.env ??= [];
container.env.push({
name: context.newEnvironmentVariableName,
value: context.newEnvironmentVariableManualInput ?? '', // The server doesn't allow this value to be undefined
secretRef: context.secretName,
});
container.env.push(context.environmentVariable);

await this.updateRevisionDraftWithTemplate(context);
}

public shouldExecute(context: T): boolean {
return context.containersIdx !== undefined && !!context.newEnvironmentVariableName;
return !context.environmentVariable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@
import { type EnvironmentVar } from "@azure/arm-appcontainers";
import { type SetTelemetryProps } from "../../../telemetry/SetTelemetryProps";
import { type ContainerUpdateTelemetryProps as TelemetryProps } from "../../../telemetry/commandTelemetryProps";
import { type ISecretContext } from "../../secret/ISecretContext";
import { type EnvironmentVariablesBaseContext } from "../EnvironmentVariablesContext";
import { type EnvironmentVariableType } from "../addEnvironmentVariable/EnvironmentVariableTypeListStep";

export interface EnvironmentVariableEditBaseContext extends EnvironmentVariablesBaseContext, Pick<ISecretContext, 'secretName'> {
newEnvironmentVariableType?: EnvironmentVariableType;
newEnvironmentVariableName?: string;
newEnvironmentVariableManualInput?: string;
// secretName
import { type EnvironmentVariableAddContext } from "../addEnvironmentVariable/EnvironmentVariableAddContext";

export interface EnvironmentVariableEditBaseContext extends EnvironmentVariableAddContext {
// Require the environment variable upfront so we can make edits
environmentVariable: EnvironmentVar;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export class EnvironmentVariableEditDraftStep<T extends EnvironmentVariableEditC
}

public shouldExecute(context: T): boolean {
return context.containersIdx !== undefined && !!context.environmentVariable;
return !!context.environmentVariable;
}
}
19 changes: 12 additions & 7 deletions src/commands/image/deployImageApi/deployImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzureWizard, createSubscriptionContext, type AzureWizardExecuteStep, type AzureWizardPromptStep, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { AzureWizard, createSubscriptionContext, type AzureWizardPromptStep, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
import { type ContainerAppItem } from "../../../tree/ContainerAppItem";
import { createActivityContext } from "../../../utils/activityUtils";
import { getManagedEnvironmentFromContainerApp } from "../../../utils/getResourceUtils";
import { getVerifyProvidersStep } from "../../../utils/getVerifyProvidersStep";
import { getImageNameWithoutTag } from "../../../utils/imageNameUtils";
import { localize } from "../../../utils/localize";
import { ContainerAppOverwriteConfirmStep } from "../../ContainerAppOverwriteConfirmStep";
import { showContainerAppNotification } from "../../createContainerApp/showContainerAppNotification";
import { IngressPromptStep } from "../../ingress/IngressPromptStep";
import { ContainerAppUpdateStep } from "../imageSource/ContainerAppUpdateStep";
import { ImageSourceListStep } from "../imageSource/ImageSourceListStep";
import { type ContainerRegistryImageSourceContext } from "../imageSource/containerRegistry/ContainerRegistryImageSourceContext";
Expand All @@ -33,18 +35,21 @@ export async function deployImage(context: IActionContext & Partial<ContainerReg

const promptSteps: AzureWizardPromptStep<DeployImageApiContext>[] = [
new ImageSourceListStep(),
new ContainerAppOverwriteConfirmStep(),
];

const executeSteps: AzureWizardExecuteStep<DeployImageApiContext>[] = [
getVerifyProvidersStep<DeployImageApiContext>(),
new ContainerAppUpdateStep()
];
// If more than the image tag changed, prompt for ingress again
if (getImageNameWithoutTag(wizardContext.containerApp?.template?.containers?.[0].image ?? '') !== getImageNameWithoutTag(wizardContext.image ?? '')) {
promptSteps.push(new IngressPromptStep());
}
promptSteps.push(new ContainerAppOverwriteConfirmStep());

const wizard: AzureWizard<DeployImageApiContext> = new AzureWizard(wizardContext, {
title: localize('deploy', 'Deploy image to container app "{0}"', containerApp.name),
promptSteps,
executeSteps,
executeSteps: [
getVerifyProvidersStep<DeployImageApiContext>(),
new ContainerAppUpdateStep(),
],
showLoadingPrompt: true
});

Expand Down
21 changes: 20 additions & 1 deletion src/commands/image/imageSource/ContainerAppUpdateStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,41 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { type Ingress } from "@azure/arm-appcontainers";
import { AzureWizardExecuteStep, GenericParentTreeItem, GenericTreeItem, activityFailContext, activityFailIcon, activitySuccessContext, activitySuccessIcon, createUniversallyUniqueContextValue, nonNullProp, type ExecuteActivityOutput } from "@microsoft/vscode-azext-utils";
import { type Progress } from "vscode";
import { ext } from "../../../extensionVariables";
import { getContainerEnvelopeWithSecrets, type ContainerAppModel } from "../../../tree/ContainerAppItem";
import { localize } from "../../../utils/localize";
import { type IngressContext } from "../../ingress/IngressContext";
import { enabledIngressDefaults } from "../../ingress/enableIngress/EnableIngressStep";
import { updateContainerApp } from "../../updateContainerApp";
import { type ImageSourceContext } from "./ImageSourceContext";
import { getContainerNameForImage } from "./containerRegistry/getContainerNameForImage";

export class ContainerAppUpdateStep<T extends ImageSourceContext> extends AzureWizardExecuteStep<T> {
export class ContainerAppUpdateStep<T extends ImageSourceContext & IngressContext> extends AzureWizardExecuteStep<T> {
public priority: number = 680;

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

let ingress: Ingress | undefined;
if (context.enableIngress) {
ingress = {
...enabledIngressDefaults,
...containerAppEnvelope.configuration.ingress ?? {}, // Overwrite any default settings if we already have previous configurations set
external: context.enableExternal ?? containerAppEnvelope.configuration.ingress?.external,
targetPort: context.targetPort ?? containerAppEnvelope.configuration.ingress?.targetPort,
};
} else if (context.enableIngress === false) {
ingress = undefined;
} else {
// If enableIngress is not set, just default to the previous settings if they exist
ingress = containerAppEnvelope.configuration.ingress;
}

containerAppEnvelope.configuration.ingress = ingress;
containerAppEnvelope.configuration.secrets = context.secrets;
containerAppEnvelope.configuration.registries = context.registryCredentials;

Expand Down
33 changes: 18 additions & 15 deletions src/commands/ingress/IngressPromptStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,31 @@ export async function tryConfigureIngressUsingDockerfile(context: IngressContext
return;
}

if (!context.dockerfileExposePorts) {
context.enableIngress = false;
context.enableExternal = false;
} else if (context.dockerfileExposePorts) {
if (context.dockerfileExposePorts) {
context.enableIngress = true;
context.enableExternal = true;
context.targetPort = getDefaultPort(context);
} else {
context.enableIngress = false;
context.enableExternal = false;
}

// If a container app already exists, activity children will be added automatically in later execute steps
if (!context.containerApp) {
context.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['ingressPromptStepSuccessItem', activitySuccessContext]),
label: context.enableIngress ?
localize('ingressEnableLabel', 'Enable ingress on port {0} (from Dockerfile configuration)', context.targetPort) :
localize('ingressDisableLabel', 'Disable ingress (from Dockerfile configuration)'),
iconPath: activitySuccessIcon
})
);
const currentExternalEnabled: boolean | undefined = context.containerApp?.configuration?.ingress?.external;
const currentTargetPort: number | undefined = context.containerApp?.configuration?.ingress?.targetPort;
if (currentExternalEnabled === context.enableExternal && currentTargetPort === context.targetPort) {
return;
}

context.activityChildren?.push(
new GenericTreeItem(undefined, {
contextValue: createUniversallyUniqueContextValue(['ingressPromptStepSuccessItem', activitySuccessContext]),
label: context.enableIngress ?
localize('ingressEnableLabel', 'Enable ingress on port {0} (from Dockerfile configuration)', context.targetPort) :
localize('ingressDisableLabel', 'Disable ingress (from Dockerfile configuration)'),
iconPath: activitySuccessIcon
})
);

ext.outputChannel.appendLog(context.enableIngress ?
localize('ingressEnabledLabel', 'Detected ingress on port {0} using Dockerfile configuration.', context.targetPort) :
localize('ingressDisabledLabel', 'Detected no ingress using Dockerfile configuration.')
Expand Down
Loading

0 comments on commit c78ba36

Please sign in to comment.