-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathgetDefaultPort.ts
More file actions
22 lines (18 loc) · 1.24 KB
/
getDefaultPort.ts
File metadata and controls
22 lines (18 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { IngressContext } from "../IngressContext";
export function getDefaultPort(context: IngressContext, fallbackPort: number = 80): number {
const currentDeploymentPort: number | undefined = context.containerApp?.configuration?.ingress?.targetPort;
let dockerfilePortSuggestion: number | undefined;
if (
// If there's already a deployment port, don't suggest a new port if it's already a port within range of the current Dockerfile expose ports
(currentDeploymentPort && context.dockerfileExposePorts && !context.dockerfileExposePorts.some(p => p.includes(currentDeploymentPort))) ||
// If no deployment port but we found expose ports
(!currentDeploymentPort && context.dockerfileExposePorts)
) {
dockerfilePortSuggestion = context.dockerfileExposePorts[0].start;
}
return dockerfilePortSuggestion || currentDeploymentPort || fallbackPort;
}