|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import { AzureWizardExecuteStep, AzureWizardPromptStep, IWizardOptions } from "@microsoft/vscode-azext-utils"; |
| 7 | +import { ext } from "../../extensionVariables"; |
7 | 8 | import { localize } from "../../utils/localize"; |
8 | 9 | import type { IngressContext } from "./IngressContext"; |
9 | 10 | import { DisableIngressStep } from "./disableIngress/DisableIngressStep"; |
10 | 11 | import { TargetPortInputStep } from "./editTargetPort/TargetPortInputStep"; |
| 12 | +import { getDefaultPort } from "./editTargetPort/getDefaultPort"; |
11 | 13 | import { EnableIngressStep } from "./enableIngress/EnableIngressStep"; |
12 | 14 | import { IngressVisibilityStep } from "./enableIngress/IngressVisibilityStep"; |
13 | | -import { tryConfigureIngressUsingDockerfile } from "./tryConfigureIngressUsingDockerfile"; |
| 15 | +import { tryGetDockerfileExposePorts } from "./tryGetDockerfileExposePorts"; |
14 | 16 |
|
15 | 17 | export class IngressPromptStep extends AzureWizardPromptStep<IngressContext> { |
16 | 18 | public async prompt(context: IngressContext): Promise<void> { |
@@ -42,3 +44,42 @@ export class IngressPromptStep extends AzureWizardPromptStep<IngressContext> { |
42 | 44 | return { promptSteps, executeSteps }; |
43 | 45 | } |
44 | 46 | } |
| 47 | + |
| 48 | +export async function tryConfigureIngressUsingDockerfile(context: IngressContext): Promise<void> { |
| 49 | + if (!context.dockerfilePath) { |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + context.dockerfileExposePorts = await tryGetDockerfileExposePorts(context.dockerfilePath); |
| 54 | + |
| 55 | + if (context.alwaysPromptIngress) { |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + if (!context.dockerfileExposePorts) { |
| 60 | + context.enableIngress = false; |
| 61 | + context.enableExternal = false; |
| 62 | + } else if (context.dockerfileExposePorts) { |
| 63 | + context.enableIngress = true; |
| 64 | + context.enableExternal = true; |
| 65 | + context.targetPort = getDefaultPort(context); |
| 66 | + } |
| 67 | + |
| 68 | + // If a container app already exists, activity children will be added automatically in later execute steps |
| 69 | + // if (!context.containerApp) { |
| 70 | + // context.activityChildren?.push( |
| 71 | + // new GenericTreeItem(undefined, { |
| 72 | + // contextValue: createActivityChildContext(['ingressPromptStep', activitySuccessContext]), |
| 73 | + // label: context.enableIngress ? |
| 74 | + // localize('ingressEnableLabel', 'Enable ingress on port {0} (found Dockerfile configuration)', context.targetPort) : |
| 75 | + // localize('ingressDisableLabel', 'Disable ingress (found Dockerfile configuration)'), |
| 76 | + // iconPath: activitySuccessIcon |
| 77 | + // }) |
| 78 | + // ); |
| 79 | + // } |
| 80 | + |
| 81 | + ext.outputChannel.appendLog(context.enableIngress ? |
| 82 | + localize('ingressEnabledLabel', 'Detected ingress on port {0} using Dockerfile configuration.', context.targetPort) : |
| 83 | + localize('ingressDisabledLabel', 'Detected no ingress using Dockerfile configuration.') |
| 84 | + ); |
| 85 | +} |
0 commit comments