diff --git a/src/app.coffee b/src/app.coffee index d079d164..ce502741 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -9,8 +9,6 @@ do -> return lookup(name, { verbatim: true }, opts) return lookup(name, Object.assign({ verbatim: true }, opts), cb) -require('log-timestamp') - Supervisor = require './supervisor' supervisor = new Supervisor() diff --git a/src/compose/service-manager.ts b/src/compose/service-manager.ts index cf710606..24f76732 100644 --- a/src/compose/service-manager.ts +++ b/src/compose/service-manager.ts @@ -20,6 +20,7 @@ import { import * as LogTypes from '../lib/log-types'; import { checkInt, isValidDeviceName } from '../lib/validation'; import { Service } from './service'; +import { serviceNetworksToDockerNetworks } from './utils'; interface ServiceConstructOpts { docker: Docker; @@ -266,7 +267,9 @@ export class ServiceManager extends (EventEmitter as { } const conf = service.toDockerContainer({ deviceName }); - const nets = service.extraNetworksToJoin(); + const nets = serviceNetworksToDockerNetworks( + service.extraNetworksToJoin(), + ); this.logger.logSystemEvent(LogTypes.installService, { service }); this.reportNewStatus(mockContainerId, service, 'Installing'); @@ -275,7 +278,7 @@ export class ServiceManager extends (EventEmitter as { service.containerId = container.id; await Promise.all( - _.map(nets, (endpointConfig, name) => + _.map((nets || {}).EndpointsConfig, (endpointConfig, name) => this.docker.getNetwork(name).connect({ Container: container.id, EndpointConfig: endpointConfig, diff --git a/src/compose/service.ts b/src/compose/service.ts index 823f0b75..c4b6af25 100644 --- a/src/compose/service.ts +++ b/src/compose/service.ts @@ -122,6 +122,17 @@ export class Service { } // Prefix the network entries with the app id networks = _.mapKeys(networks, (_v, k) => `${service.appId}_${k}`); + // Ensure that we add an alias of the service name + networks = _.mapValues(networks, v => { + if (v.aliases == null) { + v.aliases = []; + } + const serviceName: string = service.serviceName || ''; + if (!_.includes(v.aliases, serviceName)) { + v.aliases.push(serviceName); + } + return v; + }); delete config.networks; // Check for unsupported networkMode entries @@ -791,8 +802,8 @@ export class Service { appId: number, serviceName: string, ): { [envVarName: string]: string } { - let defaultEnv: { [envVarName: string]: string } = {}; - for (let namespace of ['BALENA', 'RESIN']) { + const defaultEnv: { [envVarName: string]: string } = {}; + for (const namespace of ['BALENA', 'RESIN']) { _.assign( defaultEnv, _.mapKeys( @@ -837,24 +848,11 @@ export class Service { const currentAliases = _.filter(current.aliases, (alias: string) => { return !_.startsWith(this.containerId!, alias); }); - const targetAliases = _.filter(current.aliases, (alias: string) => { - return !_.startsWith(this.containerId!, alias); - }); + const targetAliases = target.aliases || []; - // Docker adds container ids to the alias list, directly after - // the service name, to detect this, check for both target having - // exactly half of the amount of entries as the current, and check - // that every second entry (starting from 0) is equal - if (currentAliases.length === targetAliases.length * 2) { - sameNetwork = _(currentAliases) - .filter((_v, k) => k % 2 === 0) - .isEqual(targetAliases); - } else { - // Otherwise compare them literally - sameNetwork = _.isEmpty( - _.xorWith(currentAliases, targetAliases, _.isEqual), - ); - } + sameNetwork = _.isEmpty( + _.xorWith(currentAliases, targetAliases, _.isEqual), + ); } } if (target.ipv4Address != null) { diff --git a/src/compose/utils.ts b/src/compose/utils.ts index 33f56c26..ec2c7866 100644 --- a/src/compose/utils.ts +++ b/src/compose/utils.ts @@ -348,7 +348,7 @@ export function addFeaturesFromLabels( }`; } // We keep balena.sock for backwards compatibility - if (constants.dockerSocket != '/var/run/balena.sock') { + if (constants.dockerSocket !== '/var/run/balena.sock') { service.config.volumes.push( `${constants.dockerSocket}:/var/run/balena.sock`, ); diff --git a/test/04-service.spec.coffee b/test/04-service.spec.coffee index 98b40190..4797a251 100644 --- a/test/04-service.spec.coffee +++ b/test/04-service.spec.coffee @@ -311,7 +311,9 @@ describe 'compose/service', -> IPAMConfig: { IPv4Address: '1.2.3.4' }, - Aliases: [] + Aliases: [ + 'test' + ] } } })