From 568c854435f50fa877b14e52c2048462ce70d888 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 16:23:28 +0100 Subject: [PATCH 01/13] Docker --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index c7a491d49..1784e11b1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -87,6 +87,8 @@ services: - "80" ports: - "80:80" + depends_on: + - route links: - "auth:${BRANCH_NAME}-auth" - "salix:${BRANCH_NAME}-salix" From 254615331a8b88483541ef955b0f4af85bf78fda Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 17:04:08 +0100 Subject: [PATCH 02/13] Docker: Faster --- Jenkinsfile | 5 +++++ services/auth/Dockerfile | 2 -- services/client/Dockerfile | 2 -- services/production/Dockerfile | 2 -- services/route/Dockerfile | 2 -- services/salix/Dockerfile | 2 -- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 82748e93d..88de5a6b8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,6 +34,11 @@ node stage ("docker") { + stage ("install modules loopback service") + { + sh "npm install /services/loopback" + } + stage ("Stopping/Removing Docker") { sh "docker-compose down --rmi all" diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile index f0390d9e9..582de9eae 100644 --- a/services/auth/Dockerfile +++ b/services/auth/Dockerfile @@ -4,8 +4,6 @@ COPY auth /app COPY loopback /loopback -RUN npm install loopback - WORKDIR /app RUN npm install diff --git a/services/client/Dockerfile b/services/client/Dockerfile index 01cc147f1..2ff9fa445 100644 --- a/services/client/Dockerfile +++ b/services/client/Dockerfile @@ -4,8 +4,6 @@ COPY client /app COPY loopback /loopback -RUN npm install loopback - WORKDIR /app RUN npm install diff --git a/services/production/Dockerfile b/services/production/Dockerfile index 41e52e736..7c0658d7c 100644 --- a/services/production/Dockerfile +++ b/services/production/Dockerfile @@ -4,8 +4,6 @@ COPY production /app COPY loopback /loopback -RUN npm install loopback - WORKDIR /app RUN npm install diff --git a/services/route/Dockerfile b/services/route/Dockerfile index 6491d6e4f..ded1fa1db 100644 --- a/services/route/Dockerfile +++ b/services/route/Dockerfile @@ -4,8 +4,6 @@ COPY route /app COPY loopback /loopback -RUN npm install loopback - WORKDIR /app RUN npm install diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile index 8af14e460..db7b8720f 100644 --- a/services/salix/Dockerfile +++ b/services/salix/Dockerfile @@ -4,8 +4,6 @@ COPY salix /app COPY loopback /loopback -RUN npm install loopback - WORKDIR /app RUN npm install From 32a6117d228650079baaf887029b4a440df0af4f Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 17:08:09 +0100 Subject: [PATCH 03/13] Error JenkinsFile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 88de5a6b8..998b955f7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -36,7 +36,7 @@ node { stage ("install modules loopback service") { - sh "npm install /services/loopback" + sh "npm install ./services/loopback" } stage ("Stopping/Removing Docker") From c03e5297a2442ca2040e215f193bd64e085a6038 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 17:24:23 +0100 Subject: [PATCH 04/13] Docker loopback --- services/auth/Dockerfile | 2 +- services/client/Dockerfile | 2 +- services/production/Dockerfile | 2 +- services/route/Dockerfile | 2 +- services/salix/Dockerfile | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile index 582de9eae..d65f358e0 100644 --- a/services/auth/Dockerfile +++ b/services/auth/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY auth /app -COPY loopback /loopback +COPY ../loopback /loopback WORKDIR /app diff --git a/services/client/Dockerfile b/services/client/Dockerfile index 2ff9fa445..6bef8bf0a 100644 --- a/services/client/Dockerfile +++ b/services/client/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY client /app -COPY loopback /loopback +COPY ../loopback /loopback WORKDIR /app diff --git a/services/production/Dockerfile b/services/production/Dockerfile index 7c0658d7c..f770425c6 100644 --- a/services/production/Dockerfile +++ b/services/production/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY production /app -COPY loopback /loopback +COPY ../loopback /loopback WORKDIR /app diff --git a/services/route/Dockerfile b/services/route/Dockerfile index ded1fa1db..26265cc84 100644 --- a/services/route/Dockerfile +++ b/services/route/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY route /app -COPY loopback /loopback +COPY ../loopback /loopback WORKDIR /app diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile index db7b8720f..0f5638fb6 100644 --- a/services/salix/Dockerfile +++ b/services/salix/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY salix /app -COPY loopback /loopback +COPY ../loopback /loopback WORKDIR /app From 2de3ccff8e413c6535aaae72de48bab86da37fee Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 17:40:15 +0100 Subject: [PATCH 05/13] Docker auth --- services/auth/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/auth/Dockerfile b/services/auth/Dockerfile index d65f358e0..582de9eae 100644 --- a/services/auth/Dockerfile +++ b/services/auth/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY auth /app -COPY ../loopback /loopback +COPY loopback /loopback WORKDIR /app From 18121e1d9de4454377e0222c02999efca361eac0 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 17:44:10 +0100 Subject: [PATCH 06/13] docker context --- services/client/Dockerfile | 2 +- services/production/Dockerfile | 2 +- services/route/Dockerfile | 2 +- services/salix/Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/client/Dockerfile b/services/client/Dockerfile index 6bef8bf0a..2ff9fa445 100644 --- a/services/client/Dockerfile +++ b/services/client/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY client /app -COPY ../loopback /loopback +COPY loopback /loopback WORKDIR /app diff --git a/services/production/Dockerfile b/services/production/Dockerfile index f770425c6..7c0658d7c 100644 --- a/services/production/Dockerfile +++ b/services/production/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY production /app -COPY ../loopback /loopback +COPY loopback /loopback WORKDIR /app diff --git a/services/route/Dockerfile b/services/route/Dockerfile index 26265cc84..ded1fa1db 100644 --- a/services/route/Dockerfile +++ b/services/route/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY route /app -COPY ../loopback /loopback +COPY loopback /loopback WORKDIR /app diff --git a/services/salix/Dockerfile b/services/salix/Dockerfile index 0f5638fb6..db7b8720f 100644 --- a/services/salix/Dockerfile +++ b/services/salix/Dockerfile @@ -2,7 +2,7 @@ FROM node:6.9.1 COPY salix /app -COPY ../loopback /loopback +COPY loopback /loopback WORKDIR /app From 560f41307fe96fce3c5989b1cc26bda33cd390fd Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 18:01:15 +0100 Subject: [PATCH 07/13] Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 998b955f7..e61547070 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -36,7 +36,7 @@ node { stage ("install modules loopback service") { - sh "npm install ./services/loopback" + sh "cd ./services/loopback && npm install" } stage ("Stopping/Removing Docker") From 9cddb00a1999ebaa008cdc688d6bbd775ec082a5 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 18:27:31 +0100 Subject: [PATCH 08/13] Client: Request Package --- services/client/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/client/package.json b/services/client/package.json index 7189c15cc..e37c7ab5a 100644 --- a/services/client/package.json +++ b/services/client/package.json @@ -13,6 +13,7 @@ "url": "https://git.verdnatura.es/salix" }, "dependencies": { - "loopback-context": "^3.3.0" + "loopback-context": "^3.3.0", + "request": "^2.83.0" } } From a9cab91acc6b41e8f48335a9128589ba68526495 Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Wed, 8 Nov 2017 20:06:00 +0100 Subject: [PATCH 09/13] Production Package --- services/production/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/production/package.json b/services/production/package.json index 8001114a5..91f9e27d2 100644 --- a/services/production/package.json +++ b/services/production/package.json @@ -12,5 +12,8 @@ "url": "https://git.verdnatura.es/salix" }, "license": "GPL-3.0", - "description": "vn-production" + "description": "vn-production", + "dependencies": { + "uuid": "^3.1.0" + } } From 20a6728ed67f83254fc60905d0095494b43385ee Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Thu, 9 Nov 2017 07:34:02 +0100 Subject: [PATCH 10/13] microservices: boot --- docker-compose.yml | 12 ++++++------ services/loopback/server/server.js | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index c7a491d49..59573b1b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -88,9 +88,9 @@ services: ports: - "80:80" links: - - "auth:${BRANCH_NAME}-auth" - - "salix:${BRANCH_NAME}-salix" - - "client:${BRANCH_NAME}-client" - - "mailer:${BRANCH_NAME}-mailer" - - "production:${BRANCH_NAME}-production" - - "route:${BRANCH_NAME}-route" + - "${BRANCH_NAME}-auth:auth" + - "${BRANCH_NAME}-salix:salix" + - "${BRANCH_NAME}-client:client" + - "${BRANCH_NAME}-mailer:mailer" + - "${BRANCH_NAME}-production:production" + - "${BRANCH_NAME}-route:route" diff --git a/services/loopback/server/server.js b/services/loopback/server/server.js index b11c17c58..55ff51e36 100644 --- a/services/loopback/server/server.js +++ b/services/loopback/server/server.js @@ -84,10 +84,11 @@ function vnBoot(app, rootDir, cb) { boot(app, bootOptions, function(err) { if (err) throw err; - if (require.main === module) - app.start(); - if (cb) cb(app); }); + + if (require.main === module) { + app.start(); + } } From 10c52a75b9c04f4dce5111437b570f6739de633b Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Thu, 9 Nov 2017 07:45:46 +0100 Subject: [PATCH 11/13] microservices: configuration --- services/auth/server/server.js | 3 +++ services/client/server/server.js | 3 +++ services/loopback/server/server.js | 7 +++---- services/production/server/server.js | 3 +++ services/route/server/server.js | 3 +++ services/salix/server/server.js | 4 ++++ 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/services/auth/server/server.js b/services/auth/server/server.js index 71e359136..c87c400dc 100644 --- a/services/auth/server/server.js +++ b/services/auth/server/server.js @@ -4,3 +4,6 @@ var vnLoopback = require('../../loopback/server/server.js'); var app = module.exports = vnLoopback.loopback(); app.set('applications', require('./application.json')); vnLoopback.boot(app, __dirname); +if (require.main === module) { + app.start(); +} diff --git a/services/client/server/server.js b/services/client/server/server.js index 1f10f7f51..eda31589d 100644 --- a/services/client/server/server.js +++ b/services/client/server/server.js @@ -3,3 +3,6 @@ var vnLoopback = require('../../loopback/server/server.js'); var app = module.exports = vnLoopback.loopback(); vnLoopback.boot(app, __dirname); +if (require.main === module) { + app.start(); +} diff --git a/services/loopback/server/server.js b/services/loopback/server/server.js index 55ff51e36..431ca8775 100644 --- a/services/loopback/server/server.js +++ b/services/loopback/server/server.js @@ -84,11 +84,10 @@ function vnBoot(app, rootDir, cb) { boot(app, bootOptions, function(err) { if (err) throw err; + if (require.main === module) { + app.start(); + } if (cb) cb(app); }); - - if (require.main === module) { - app.start(); - } } diff --git a/services/production/server/server.js b/services/production/server/server.js index f59b8971e..bc4b454c4 100644 --- a/services/production/server/server.js +++ b/services/production/server/server.js @@ -2,3 +2,6 @@ var vnLoopback = require('../../loopback/server/server.js'); var app = module.exports = vnLoopback.loopback(); vnLoopback.boot(app, __dirname); +if (require.main === module) { + app.start(); +} diff --git a/services/route/server/server.js b/services/route/server/server.js index 1f10f7f51..eda31589d 100644 --- a/services/route/server/server.js +++ b/services/route/server/server.js @@ -3,3 +3,6 @@ var vnLoopback = require('../../loopback/server/server.js'); var app = module.exports = vnLoopback.loopback(); vnLoopback.boot(app, __dirname); +if (require.main === module) { + app.start(); +} diff --git a/services/salix/server/server.js b/services/salix/server/server.js index e67d6aa42..4c7743f0d 100644 --- a/services/salix/server/server.js +++ b/services/salix/server/server.js @@ -11,3 +11,7 @@ app.set('url auth', '/auth'); app.use(cookieParser()); vnLoopback.boot(app, __dirname); + +if (require.main === module) { + app.start(); +} From d2491bfbf4aa2e43d0969ac2fbb84babb575d440 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Thu, 9 Nov 2017 08:54:41 +0100 Subject: [PATCH 12/13] refact production list --- services/production/common/methods/fake-production/list.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/services/production/common/methods/fake-production/list.js b/services/production/common/methods/fake-production/list.js index fddb9c310..0ad582160 100644 --- a/services/production/common/methods/fake-production/list.js +++ b/services/production/common/methods/fake-production/list.js @@ -2,9 +2,6 @@ module.exports = function(Self) { Self.defineScope(); Self.list = function(ctx, filter, callback) { - var page = filter.page - 1; - var limit = filter.limit * page; - var offset = (page + 1) * filter.limit; let daysTickets = 0; let warehouseFk = filter.where.warehouseFk; delete filter.limit; @@ -80,7 +77,7 @@ module.exports = function(Self) { }, this); obj.m3 = obj.m3.toFixed(2); obj.total = tickets.length; - obj.tickets = tickets.slice(limit, offset); + obj.tickets = tickets; return obj; } }; From 3d33c21cc81754ef820a74bbd3eaf34cca78fb2e Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Thu, 9 Nov 2017 08:59:40 +0100 Subject: [PATCH 13/13] removed eslint errors --- services/loopback/common/models/vn-model.js | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/services/loopback/common/models/vn-model.js b/services/loopback/common/models/vn-model.js index 72605a808..3305cb67d 100644 --- a/services/loopback/common/models/vn-model.js +++ b/services/loopback/common/models/vn-model.js @@ -45,18 +45,20 @@ module.exports = function(Self) { }); this.list = function(ctx, clientFilter, cb) { - var clientFields = (clientFilter && clientFilter.fields) ? clientFilter.fields : []; - var serverFields = (serverFilter && serverFilter.fields) ? serverFilter.fields : []; - var fields = clientFields.filter(itemC => { + let clientFields = (clientFilter && clientFilter.fields) ? clientFilter.fields : []; + let serverFields = (serverFilter && serverFilter.fields) ? serverFilter.fields : []; + let fields = clientFields.filter(itemC => { return serverFields.some(itemS => itemS === itemC); }); + let and = []; + let order; + let limit; + let filter = {order: order, limit: limit}; - var and = []; - (clientFilter && clientFilter.where) && and.push(clientFilter.where); - (serverFilter && serverFilter.where) && and.push(serverFilter.where); - - var order; - var limit; + if (clientFilter && clientFilter.where) + and.push(clientFilter.where); + if (serverFilter && serverFilter.where) + and.push(serverFilter.where); if (clientFilter && clientFilter.order) order = clientFilter.order; @@ -68,12 +70,14 @@ module.exports = function(Self) { else if (clientFilter && clientFilter.limit) limit = clientFilter.limit; - var filter = {order: order, limit: limit}; filter.where = (and.length > 0) && {and: and}; filter.fields = fields; this.find(filter, function(err, states) { - (err) ? cb(err, null) : cb(null, states); + if (err) + cb(err, null); + else + cb(null, states); }); }; }; @@ -198,8 +202,8 @@ function removeEmpty(o) { let array = []; for (let item of o) { let i = removeEmpty(item); - if (!isEmpty(item)) - array.push(item); + if (!isEmpty(i)) + array.push(i); } if (array.length > 0) return array;