mirror of
https://github.com/portainer/portainer.git
synced 2025-07-31 11:19:40 +02:00
feat(docker/services): show port ranges [EE-4012] (#10657)
Some checks failed
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
Some checks failed
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
ci / build_images (map[arch:arm platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:s390x platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:linux version:]) (push) Has been cancelled
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
/ triage (push) Has been cancelled
Lint / Run linters (push) Has been cancelled
Test / test-client (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:linux]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Has been cancelled
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Has been cancelled
Test / test-server (map[arch:arm64 platform:linux]) (push) Has been cancelled
ci / build_manifests (push) Has been cancelled
This commit is contained in:
parent
4ca6292805
commit
d336a14e50
37 changed files with 1406 additions and 148 deletions
|
@ -0,0 +1,62 @@
|
|||
import { EndpointPortConfig } from 'docker-types/generated/1.41';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { Values } from './PortsMappingField';
|
||||
import { isRange } from './types';
|
||||
|
||||
export function toRequest(portBindings: Values): Array<EndpointPortConfig> {
|
||||
return _.compact(
|
||||
portBindings.flatMap((portBinding) => {
|
||||
const { hostPort, protocol, containerPort, publishMode } = portBinding;
|
||||
if (!hostPort && !containerPort) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isRange(hostPort) && isRange(containerPort)) {
|
||||
if (
|
||||
hostPort.end - hostPort.start !==
|
||||
containerPort.end - containerPort.start
|
||||
) {
|
||||
throw new Error(
|
||||
`Invalid port specification: host port range must be equal to container port range`
|
||||
);
|
||||
}
|
||||
|
||||
return Array.from(
|
||||
{ length: hostPort.end - hostPort.start + 1 },
|
||||
(_, i) => ({
|
||||
PublishedPort: hostPort.start + i,
|
||||
Protocol: protocol,
|
||||
TargetPort: containerPort.start + i,
|
||||
PublishMode: publishMode,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (isRange(hostPort) && !isRange(containerPort)) {
|
||||
return Array.from(
|
||||
{ length: hostPort.end - hostPort.start + 1 },
|
||||
(_, i) => ({
|
||||
PublishedPort: hostPort.start + i,
|
||||
Protocol: protocol,
|
||||
TargetPort: containerPort,
|
||||
PublishMode: publishMode,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (!isRange(hostPort) && !isRange(containerPort)) {
|
||||
return {
|
||||
PublishedPort: hostPort,
|
||||
Protocol: protocol,
|
||||
TargetPort: containerPort,
|
||||
PublishMode: publishMode,
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(
|
||||
`Invalid port specification: host port must be a range when container port is a range`
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue