From f3264862ca73e9b059da7fa7ce19aa67bfb9c296 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Fri, 8 Feb 2019 15:05:02 +0000 Subject: [PATCH] fix: Normalize ports from compose file on instantiation Adjacent ports are always grouped together by docker when reporting the container state (from an inspect), so adjacent ports defined in the compose file would not match as they would not have been normalized. We make sure to always normalize the input port configuration, so that it will match the docker output (if it should). We also don't sort in the fromComposePorts function anymore as that is handled by the normalize function. Closes: #897 Change-type: patch Signed-off-by: Cameron Diver --- src/compose/ports.ts | 5 +---- test/16-ports.spec.coffee | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/compose/ports.ts b/src/compose/ports.ts index 1d80cb29..5fdd0e20 100644 --- a/src/compose/ports.ts +++ b/src/compose/ports.ts @@ -140,10 +140,7 @@ export class PortMap { } public static fromComposePorts(ports: string[]): PortMap[] { - return _(ports) - .map(p => new PortMap(p)) - .sortBy(p => p.ports.internalStart) - .value(); + return PortMap.normalisePortMaps(ports.map(p => new PortMap(p))); } private parsePortString(portStr: string): void { diff --git a/test/16-ports.spec.coffee b/test/16-ports.spec.coffee index 80e83740..f84ea56c 100644 --- a/test/16-ports.spec.coffee +++ b/test/16-ports.spec.coffee @@ -252,6 +252,15 @@ describe 'Ports', -> expect(portMapsTarget).to.deep.equal(portMapsCurrent) + describe 'fromComposePorts', -> + it 'should normalise compose ports', -> + expect(PortMap.fromComposePorts([ + '80:80', + '81:81', + '82:82', + ])).to.deep.equal([ + new PortMap('80-82') + ]) describe 'normalisePortMaps', ->