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 <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-01-02 11:24:56 +00:00
parent 68aa34927b
commit 557c32b80e
No known key found for this signature in database
GPG Key ID: 49690ED87032539F
2 changed files with 9 additions and 1 deletions

View File

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

View File

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