From 557c32b80e09051e9fe3633a94fe38cd5a49fcdb Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Wed, 2 Jan 2019 11:24:56 +0000 Subject: [PATCH] compose: Normalise target ports for comparison with docker's output Docker always returns ports in ascending order, so if they aren't specified like that in the compose, a restart loop would occur. This patch changes the port maps to be stored in ascending order, based on an alphabetical sort of the internalStart port (not taking into account the protocol). This is the same as how Docker returns them, so they will match, regardless of input form. Change-type: patch Closes: #824 Signed-off-by: Cameron Diver --- src/compose/ports.ts | 6 ++++++ src/compose/service.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/compose/ports.ts b/src/compose/ports.ts index 8ed9c318..bf4cb396 100644 --- a/src/compose/ports.ts +++ b/src/compose/ports.ts @@ -139,6 +139,12 @@ export class PortMap { }, []); } + public static normaliseComposePorts(portMaps: PortMap[]): PortMap[] { + return _.sortBy(portMaps, p => { + return p.ports.internalStart; + }); + } + private parsePortString(portStr: string): void { const match = portStr.match(PORTS_REGEX); if (match == null) { diff --git a/src/compose/service.ts b/src/compose/service.ts index 44c856bb..c2613957 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -253,7 +253,9 @@ export class Service { let portMaps: PortMap[] = []; if (config.ports != null) { - portMaps = _.map(config.ports, p => new PortMap(p)); + portMaps = PortMap.normaliseComposePorts( + _.map(config.ports, p => new PortMap(p)), + ); } delete config.ports;