Skip to content

Commit d8a7196

Browse files
authored
Add an ingress prompt when more than the image name tag changes (#800)
1 parent b64b3b6 commit d8a7196

File tree

4 files changed

+78
-7
lines changed

4 files changed

+78
-7
lines changed

extension.bundle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export * from './src/commands/ingress/tryGetDockerfileExposePorts';
3131
export { activate, deactivate } from './src/extension';
3232
export * from './src/extensionVariables';
3333
export * from './src/utils/azureClients';
34+
export * from './src/utils/imageNameUtils';
3435
export * from './src/utils/settingUtils';
3536
export * from './src/utils/validateUtils';
3637

src/commands/image/deployImageApi/deployImage.ts

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

6-
import { AzureWizard, createSubscriptionContext, type AzureWizardExecuteStep, type AzureWizardPromptStep, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
6+
import { AzureWizard, createSubscriptionContext, type AzureWizardPromptStep, type IActionContext, type ISubscriptionContext } from "@microsoft/vscode-azext-utils";
77
import { type ContainerAppItem } from "../../../tree/ContainerAppItem";
88
import { createActivityContext } from "../../../utils/activityUtils";
99
import { getManagedEnvironmentFromContainerApp } from "../../../utils/getResourceUtils";
1010
import { getVerifyProvidersStep } from "../../../utils/getVerifyProvidersStep";
11+
import { getImageNameWithoutTag } from "../../../utils/imageNameUtils";
1112
import { localize } from "../../../utils/localize";
1213
import { ContainerAppOverwriteConfirmStep } from "../../ContainerAppOverwriteConfirmStep";
1314
import { showContainerAppNotification } from "../../createContainerApp/showContainerAppNotification";
15+
import { IngressPromptStep } from "../../ingress/IngressPromptStep";
1416
import { ContainerAppUpdateStep } from "../imageSource/ContainerAppUpdateStep";
1517
import { ImageSourceListStep } from "../imageSource/ImageSourceListStep";
1618
import { type ContainerRegistryImageSourceContext } from "../imageSource/containerRegistry/ContainerRegistryImageSourceContext";
@@ -33,18 +35,21 @@ export async function deployImage(context: IActionContext & Partial<ContainerReg
3335

3436
const promptSteps: AzureWizardPromptStep<DeployImageApiContext>[] = [
3537
new ImageSourceListStep(),
36-
new ContainerAppOverwriteConfirmStep(),
3738
];
3839

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

4446
const wizard: AzureWizard<DeployImageApiContext> = new AzureWizard(wizardContext, {
4547
title: localize('deploy', 'Deploy image to container app "{0}"', containerApp.name),
4648
promptSteps,
47-
executeSteps,
49+
executeSteps: [
50+
getVerifyProvidersStep<DeployImageApiContext>(),
51+
new ContainerAppUpdateStep(),
52+
],
4853
showLoadingPrompt: true
4954
});
5055

src/utils/imageNameUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export function parseImageName(imageName?: string): ParsedImageName {
5151
};
5252
}
5353

54+
export function getImageNameWithoutTag(imageName: string): string {
55+
return imageName.replace(/:[^:]*$/, '');
56+
}
57+
5458
/**
5559
* @param registryName When parsed from a full image name, everything before the first slash
5660
*/

test/imageNameUtils.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as assert from "assert";
7+
import { getImageNameWithoutTag } from "../extension.bundle";
8+
9+
suite('imageNameUtils', () => {
10+
test('getImageNameWithoutTag', () => {
11+
const testValues: string[] = [
12+
'',
13+
'myimage:latest',
14+
'repository/name:1.0.0',
15+
'custom-registry.com/myimage:v2',
16+
'library/ubuntu:20.04',
17+
'project/service-name:dev-build',
18+
'docker.io/library/nginx:stable',
19+
'my-repo/my-service:release-candidate',
20+
'anotherrepo/anotherimage:test',
21+
'image_without_tag',
22+
'my-image:with:multiple:colons',
23+
'some-registry.io/nested/repo/image:12345',
24+
'edgecase-without-tag:',
25+
'dockerhub.com/image-name:alpha-beta',
26+
'registry.example.com:5000/repo/image:tagname',
27+
'private-repo/myimage:',
28+
'test-image-with-special-characters:beta@123',
29+
'path/to/image:no-colon-in-name',
30+
'simple-image:another:tag',
31+
'example.com:8080/repo/image:v3'
32+
];
33+
34+
const expectedValues: string[] = [
35+
'',
36+
'myimage',
37+
'repository/name',
38+
'custom-registry.com/myimage',
39+
'library/ubuntu',
40+
'project/service-name',
41+
'docker.io/library/nginx',
42+
'my-repo/my-service',
43+
'anotherrepo/anotherimage',
44+
'image_without_tag',
45+
'my-image:with:multiple',
46+
'some-registry.io/nested/repo/image',
47+
'edgecase-without-tag',
48+
'dockerhub.com/image-name',
49+
'registry.example.com:5000/repo/image',
50+
'private-repo/myimage',
51+
'test-image-with-special-characters',
52+
'path/to/image',
53+
'simple-image:another',
54+
'example.com:8080/repo/image'
55+
];
56+
57+
for (let i = 0; i < testValues.length; i++) {
58+
assert.equal(getImageNameWithoutTag(testValues[i]), expectedValues[i]);
59+
}
60+
});
61+
});

0 commit comments

Comments
 (0)