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 <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-02-08 15:05:02 +00:00
parent 04a9790e11
commit f3264862ca
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 10 additions and 4 deletions

View File

@ -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 {

View File

@ -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', ->