From 68084a257d7928989bad4da2aa0c02abea0e9fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Sat, 15 Jul 2017 04:38:27 +0100 Subject: [PATCH] feat(portal-api): add support for env_file's --- packages/portal-api/lib/data/index.js | 21 ++++++++++++++----- packages/portal-api/lib/data/transform.js | 11 ++++++++-- .../portal-api/lib/watch/container-pilot.js | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/portal-api/lib/data/index.js b/packages/portal-api/lib/data/index.js index 27fb2e9d..dd41c9c2 100644 --- a/packages/portal-api/lib/data/index.js +++ b/packages/portal-api/lib/data/index.js @@ -113,6 +113,14 @@ class Data extends EventEmitter { }); } + fromKeyValueToDict(kv) { + return kv.reduce((acc, { name, value }) => { + return Object.assign(acc, { + [name]: value + }); + }, {}); + } + // triton @@ -571,7 +579,7 @@ class Data extends EventEmitter { this._listMachines(deploymentGroupName, handleMachinesList); } - scale ({ serviceId, environment, replicas }, cb) { + scale ({ serviceId, replicas }, cb) { Hoek.assert(serviceId, 'service id is required'); Hoek.assert(typeof replicas === 'number' && replicas >= 0, 'replicas must be a number no less than 0'); @@ -642,11 +650,12 @@ class Data extends EventEmitter { this._dockerCompose.scale({ projectName: ctx.deploymentGroup.name, - environment, + environment: ctx.manifest.environment, + files: this.fromKeyValueToDict(ctx.manifest.files), + manifest: ctx.manifest.raw, services: { [ctx.service.name]: replicas - }, - manifest: ctx.manifest.raw + } }, handleTriggeredScale); }); }; @@ -1154,6 +1163,7 @@ class Data extends EventEmitter { this._dockerCompose.provision({ projectName: ctx.currentDeploymentGroup.name, environment: clientManifest.environment, + files: this.fromKeyValueToDict(clientManifest.files), manifest: ctx.newManifest.raw }, handleProvisionResponse); }); @@ -2007,7 +2017,7 @@ class Data extends EventEmitter { }); } - getConfig ({deploymentGroupName = '', type = '', format = '', environment = '', raw = '' }, cb) { + getConfig ({deploymentGroupName = '', type = '', format = '', environment = '', files = [], raw = '' }, cb) { if (type.toUpperCase() !== 'COMPOSE') { return cb(new Error('"COMPOSE" is the only `type` supported')); } @@ -2021,6 +2031,7 @@ class Data extends EventEmitter { this._dockerCompose.config({ projectName: deploymentGroupName, environment, + files: this.fromKeyValueToDict(files), manifest: raw }, (err, config = {}) => { if (err) { diff --git a/packages/portal-api/lib/data/transform.js b/packages/portal-api/lib/data/transform.js index b87d83f8..0ab98409 100644 --- a/packages/portal-api/lib/data/transform.js +++ b/packages/portal-api/lib/data/transform.js @@ -2,6 +2,7 @@ const Yamljs = require('yamljs'); const ParamCase = require('param-case'); +const Uuid = require('uuid/v4'); const clean = (v) => { return JSON.parse(JSON.stringify(v)); @@ -124,16 +125,21 @@ exports.fromVersion = function (version) { exports.toManifest = function (clientManifest) { - return { + return clean({ id: clientManifest.id, deployment_group_id: clientManifest.deploymentGroupId, created: clientManifest.created || Date.now(), type: clientManifest.type, format: clientManifest.format, environment: clientManifest.environment, + files: clientManifest.files ? clientManifest.files.map((m) => { + return Object.assign({}, m, { + id: m.id || Uuid() + }); + }) : undefined, raw: clientManifest.raw, json: clientManifest.json || Yamljs.parse(clientManifest.raw) - }; + }); }; exports.fromManifest = function (manifest) { @@ -144,6 +150,7 @@ exports.fromManifest = function (manifest) { type: manifest.type, format: manifest.format, environment: manifest.environment, + files: manifest.files, raw: manifest.raw, json: manifest.json }; diff --git a/packages/portal-api/lib/watch/container-pilot.js b/packages/portal-api/lib/watch/container-pilot.js index 1ce69fa9..37e25aee 100644 --- a/packages/portal-api/lib/watch/container-pilot.js +++ b/packages/portal-api/lib/watch/container-pilot.js @@ -383,7 +383,7 @@ module.exports = class ContainerPilotWatcher extends Events { })); }))); - if (!deviantJobNames) { + if (!deviantJobNames || !deviantJobNames.length) { return []; }