From 9a343316b21522e34a94a66f2391e63a96516114 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Wed, 3 Apr 2019 13:08:22 +0100 Subject: [PATCH] Fix service comparison when starting a stopped service When comparing a stopped container after a start request, the container ID will be present in the target state (where usually it is not). We were already filtering this value out of the current state, but neglected to do so for the target state. This change now ensures we remove it from both alias lists if it exists. Change-type: patch Signed-off-by: Cameron Diver --- src/compose/service.ts | 44 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/compose/service.ts b/src/compose/service.ts index c4b6af25..0fe330d6 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -650,22 +650,15 @@ export class Service { const differentArrayFields: string[] = []; sameConfig = sameConfig && - _.every(Service.configArrayFields, (field: ServiceConfigArrayField) => { - return _.isEmpty( - _.xorWith( - // TODO: The typings here aren't accepted, even though we - // know it's fine - (this.config as any)[field], - (service.config as any)[field], - (a, b) => { - const eq = _.isEqual(a, b); - if (!eq) { - differentArrayFields.push(field); - } - return eq; - }, - ), + _.every(Service.configArrayFields, (field: keyof ServiceConfig) => { + const eq = _.isEqual( + _.sortBy(this.config[field] as Array), + _.sortBy(service.config[field] as Array), ); + if (!eq) { + differentArrayFields.push(field); + } + return eq; }); if (!(sameConfig && sameNetworks)) { @@ -844,15 +837,20 @@ export class Service { if (current.aliases == null) { sameNetwork = false; } else { - // Remove the auto-added docker container id - const currentAliases = _.filter(current.aliases, (alias: string) => { - return !_.startsWith(this.containerId!, alias); - }); - const targetAliases = target.aliases || []; - - sameNetwork = _.isEmpty( - _.xorWith(currentAliases, targetAliases, _.isEqual), + // Take out the container id from both aliases, as it *will* be present + // in a currently running container, and can also be present in the target + // for example when doing a start-service + // Also sort the aliases, so we can do a simple comparison + const [currentAliases, targetAliases] = [ + current.aliases, + target.aliases, + ].map(aliases => + _.sortBy( + aliases.filter(a => !_.startsWith(this.containerId || '', a)), + ), ); + + sameNetwork = _.isEqual(currentAliases, targetAliases); } } if (target.ipv4Address != null) {