From 2fc2c6718bcd9bbb255496abb2e4e221cf2be9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilherme=20Deusdar=C3=A1?= Date: Tue, 29 May 2018 20:36:25 -0300 Subject: [PATCH 1/2] Fix #3 #8 criando ambiente de dev e componentizando MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Beatriz Hanae Signed-off-by: Guilherme Deusdará Signed-off-by: Isaque Alves Co-Authored-by: Beatriz Hanae Co-Authored-by: Guilherme Deusdará Co-Authored-by: Isaque Alves --- Client/client_sector.js | 16 ++++++++-------- Docker/Dev/Client/Dockerfile | 11 +++++++++++ Docker/Dev/Server/Dockerfile | 11 +++++++++++ Docker/Dev/build.yml | 14 ++++++++++++++ Docker/Dev/env/mongo.env | 3 +++ Docker/Dev/env/rabbitmq.env | 5 +++++ Docker/Dev/start-deps.yml | 32 +++++++++++++++++++++++++++++++ Docker/Dev/start-sector.yml | 36 +++++++++++++++++++++++++++++++++++ Docker/Prod/.keep | 0 Docker/Test/Client/Dockerfile | 11 +++++++++++ Docker/Test/Server/Dockerfile | 11 +++++++++++ Docker/Test/build.yml | 14 ++++++++++++++ Docker/Test/env/.keep | 0 Docker/Test/start-user.yml | 13 +++++++++++++ Server/_sector.js | 22 +++++++++++++++++++++ Server/sector.js | 34 ++++++++------------------------- utils/script_coveralls.sh | 3 +++ 17 files changed, 202 insertions(+), 34 deletions(-) create mode 100644 Docker/Dev/Client/Dockerfile create mode 100644 Docker/Dev/Server/Dockerfile create mode 100644 Docker/Dev/build.yml create mode 100644 Docker/Dev/env/mongo.env create mode 100644 Docker/Dev/env/rabbitmq.env create mode 100644 Docker/Dev/start-deps.yml create mode 100644 Docker/Dev/start-sector.yml create mode 100644 Docker/Prod/.keep create mode 100644 Docker/Test/Client/Dockerfile create mode 100644 Docker/Test/Server/Dockerfile create mode 100644 Docker/Test/build.yml create mode 100644 Docker/Test/env/.keep create mode 100644 Docker/Test/start-user.yml create mode 100644 Server/_sector.js create mode 100644 utils/script_coveralls.sh diff --git a/Client/client_sector.js b/Client/client_sector.js index 79a937b..c1f7ca1 100644 --- a/Client/client_sector.js +++ b/Client/client_sector.js @@ -45,14 +45,14 @@ var seneca = require('seneca')() .use('seneca-amqp-transport') .use("entity") .use('api') - .client( { - type:'amqp', - pin:'role:sector', - port: 5672, - username: 'guest', - password: 'guest', - url: 'amqp://rabbitmq', - } ) + .client({ + type: 'amqp', + pin: 'role:sector', + port: process.env.RABBITMQ_PORT, + username: process.env.RABBITMQ_DEFAULT_USER, + password: process.env.RABBITMQ_DEFAULT_PASS, + url: 'amqp://' + process.env.RABBITMQ_HOST + }) .ready(() => { app.listen(8080) }) diff --git a/Docker/Dev/Client/Dockerfile b/Docker/Dev/Client/Dockerfile new file mode 100644 index 0000000..af50a18 --- /dev/null +++ b/Docker/Dev/Client/Dockerfile @@ -0,0 +1,11 @@ +FROM dulce/dulce:base-dev + +COPY Client/package.json /usr/src/app/package.json + +RUN npm install --development + +ADD Client/ /usr/src/app + +EXPOSE 8080 + +CMD ["npm", "start"] diff --git a/Docker/Dev/Server/Dockerfile b/Docker/Dev/Server/Dockerfile new file mode 100644 index 0000000..0390fc9 --- /dev/null +++ b/Docker/Dev/Server/Dockerfile @@ -0,0 +1,11 @@ +FROM dulce/dulce:base-dev + +COPY Server/package.json /usr/src/app/package.json + +RUN npm install --development + +ADD Server/ /usr/src/app + +EXPOSE 8080 + +CMD ["npm", "start"] diff --git a/Docker/Dev/build.yml b/Docker/Dev/build.yml new file mode 100644 index 0000000..7b8a0c5 --- /dev/null +++ b/Docker/Dev/build.yml @@ -0,0 +1,14 @@ +version: '3.5' + +services: + sectorserver: + image: dulce/sector-server:dev + build: + context: ../../ + dockerfile: Docker/Dev/Server/Dockerfile + + sectorclient: + image: dulce/sector-client:dev + build: + context: ../../ + dockerfile: Docker/Dev/Client/Dockerfile diff --git a/Docker/Dev/env/mongo.env b/Docker/Dev/env/mongo.env new file mode 100644 index 0000000..edc1724 --- /dev/null +++ b/Docker/Dev/env/mongo.env @@ -0,0 +1,3 @@ +MONGO_DATABASE=dataBaseSectors +MONGO_HOST=sectormongo +MONGO_PORT=27017 diff --git a/Docker/Dev/env/rabbitmq.env b/Docker/Dev/env/rabbitmq.env new file mode 100644 index 0000000..ae35d18 --- /dev/null +++ b/Docker/Dev/env/rabbitmq.env @@ -0,0 +1,5 @@ +RABBITMQ_DEFAULT_USER=dulce +RABBITMQ_DEFAULT_PASS=dulce + +RABBITMQ_HOST=sectorrabbitmq +RABBITMQ_PORT=5672 diff --git a/Docker/Dev/start-deps.yml b/Docker/Dev/start-deps.yml new file mode 100644 index 0000000..e3d3cda --- /dev/null +++ b/Docker/Dev/start-deps.yml @@ -0,0 +1,32 @@ +version: '3.5' + +services: + sectormongo: + image: mongo + env_file: + - ./env/mongo.env + networks: + - dulce-db + ports: + - 27017 + volumes: + - db_data:/data/db + + sectorrabbitmq: + image: rabbitmq:3.6.14-management + env_file: + - ./env/rabbitmq.env + ports: + - 5672:5672 + - 15672:15672 + networks: + - dulce-rabbitmq + +networks: + dulce-db: + name: dulce-db + dulce-rabbitmq: + name: dulce-rabbitmq + +volumes: + db_data: {} diff --git a/Docker/Dev/start-sector.yml b/Docker/Dev/start-sector.yml new file mode 100644 index 0000000..f66a242 --- /dev/null +++ b/Docker/Dev/start-sector.yml @@ -0,0 +1,36 @@ +version: '3.5' + +services: + sectorserver: + image: dulce/sector-server:dev + restart: always + env_file: + - ./env/mongo.env + - ./env/rabbitmq.env + ports: + - 8080:8080 + volumes: + - ../../Server:/usr/src/app + - /usr/src/app/node_modules + networks: + - dulce-db + - dulce-rabbitmq + + sectorclient: + image: dulce/sector-client:dev + restart: always + env_file: + - ./env/rabbitmq.env + ports: + - 8083:8080 + volumes: + - ../../Client:/usr/src/app + - /usr/src/app/node_modules + networks: + - dulce-rabbitmq + +networks: + dulce-db: + name: dulce-db + dulce-rabbitmq: + name: dulce-rabbitmq diff --git a/Docker/Prod/.keep b/Docker/Prod/.keep new file mode 100644 index 0000000..e69de29 diff --git a/Docker/Test/Client/Dockerfile b/Docker/Test/Client/Dockerfile new file mode 100644 index 0000000..6bb32b3 --- /dev/null +++ b/Docker/Test/Client/Dockerfile @@ -0,0 +1,11 @@ +FROM dulce/dulce:base-dev + +COPY Client/package.json /usr/src/app/package.json + +RUN npm i -g npm +RUN npm install --development +ADD Client/ /usr/src/app/ + +EXPOSE 8080 + +CMD ["npm","start"] diff --git a/Docker/Test/Server/Dockerfile b/Docker/Test/Server/Dockerfile new file mode 100644 index 0000000..cd1ae45 --- /dev/null +++ b/Docker/Test/Server/Dockerfile @@ -0,0 +1,11 @@ +FROM dulce/dulce:base-dev + +WORKDIR /usr/src/app + +ADD Server/package.json /usr/src/app/ + +RUN npm install + +ADD Server /usr/src/app + +CMD ["npm", "run", "coverage"] diff --git a/Docker/Test/build.yml b/Docker/Test/build.yml new file mode 100644 index 0000000..f966f08 --- /dev/null +++ b/Docker/Test/build.yml @@ -0,0 +1,14 @@ +version: '3.5' + +services: + userserver: + image: dulce/user-server:test + build: + context: ../../ + dockerfile: Docker/Test/Server/Dockerfile + + userclient: + image: dulce/user-client:test + build: + context: ../../ + dockerfile: Docker/Test/Client/Dockerfile diff --git a/Docker/Test/env/.keep b/Docker/Test/env/.keep new file mode 100644 index 0000000..e69de29 diff --git a/Docker/Test/start-user.yml b/Docker/Test/start-user.yml new file mode 100644 index 0000000..8a0ee36 --- /dev/null +++ b/Docker/Test/start-user.yml @@ -0,0 +1,13 @@ +version: '3.5' + +services: + userserver: + image: dulce/user-server:test + restart: always + env_file: + - ./env/coveralls.env + ports: + - 8080:8080 + volumes: + - ../../Server:/usr/src/app + - /usr/src/app/node_modules diff --git a/Server/_sector.js b/Server/_sector.js new file mode 100644 index 0000000..c318c8c --- /dev/null +++ b/Server/_sector.js @@ -0,0 +1,22 @@ +module.exports = function(options){ + + this.add('role:sector,cmd:create', function create (msg,respond) { + var sector = this.make('sectors') + sector.name = msg.name + sector.save$(function(err,sector){ + respond(null,sector) + }) + }) + + this.add('role:sector, cmd:listSector', function listSector(msg, respond){ + var sector = this.make('sectors'); + sector.list$({all$:true}, function(error,sector){ + respond(null,sector); + }); + }) + + this.add('role:sector, cmd:error', function error(msg, respond){ + respond(null, {success:false, message: 'acesso negado'}); + }) + +} diff --git a/Server/sector.js b/Server/sector.js index 1a0f4a7..4133a2f 100644 --- a/Server/sector.js +++ b/Server/sector.js @@ -1,35 +1,17 @@ require('seneca')() .use("entity") .use('mongo-store',{ - name:'dataBaseHospitals', - host:'mongo', - port:27017 + name: process.env.MONGO_DATABASE, + host:process.env.MONGO_HOST, + port: process.env.MONGO_PORT }) .use('seneca-amqp-transport') + .use('_sector') .listen({ type:'amqp', pin:'role:sector', - port: 5672, - username: 'guest', - password: 'guest', - url: 'amqp://rabbitmq', + port: process.env.RABBITMQ_PORT, + username: process.env.RABBITMQ_DEFAULT_USER, + password: process.env.RABBITMQ_DEFAULT_PASS, + url: 'amqp://'+ process.env.RABBITMQ_HOST }) - - .add('role:sector,cmd:create', function create (msg,respond) { - var sector = this.make('sectors') - sector.name = msg.name - sector.save$(function(err,sector){ - respond(null,sector) - }) - }) - - .add('role:sector, cmd:listSector', function listSector(msg, respond){ - var sector = this.make('sectors'); - sector.list$({all$:true}, function(error,sector){ - respond(null,sector); - }); - }) - - .add('role:sector, cmd:error', function error(msg, respond){ - respond(null, {success:false, message: 'acesso negado'}); - }) diff --git a/utils/script_coveralls.sh b/utils/script_coveralls.sh new file mode 100644 index 0000000..afc0e51 --- /dev/null +++ b/utils/script_coveralls.sh @@ -0,0 +1,3 @@ +#!/bin/bash +repo=$(git rev-parse --show-toplevel) +echo "COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN}" > ${repo}/Docker/Test/env/coveralls.env && exit 0 From a19888994c34839584e3b4bf28a92d7d8949494e Mon Sep 17 00:00:00 2001 From: Beatriz Date: Tue, 29 May 2018 22:59:03 -0300 Subject: [PATCH 2/2] Fix #3 #4 #5 #7 Arrumando docker de testes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Beatriz Hanae Signed-off-by: Guilherme Deusdará Signed-off-by: Isaque Alves Co-Authored-by: Beatriz Hanae Co-Authored-by: Guilherme Deusdará Co-Authored-by: Isaque Alves --- .gitignore | 3 +- .travis.yml | 57 +++++-------------- Client/Dockerfile | 13 ----- Docker/Test/build.yml | 8 +-- .../Test/{start-user.yml => start-sector.yml} | 4 +- Server/Dockerfile | 13 ----- Server/package.json | 11 +++- Server/test/sector.test.js | 30 ++++++++++ docker-compose.yml | 31 ---------- utils/script_coveralls.sh | 0 10 files changed, 61 insertions(+), 109 deletions(-) delete mode 100644 Client/Dockerfile rename Docker/Test/{start-user.yml => start-sector.yml} (79%) delete mode 100644 Server/Dockerfile create mode 100644 Server/test/sector.test.js delete mode 100644 docker-compose.yml mode change 100644 => 100755 utils/script_coveralls.sh diff --git a/.gitignore b/.gitignore index 8431635..8fc0ba9 100644 --- a/.gitignore +++ b/.gitignore @@ -46,7 +46,8 @@ buck-out/ # project package-lock.json coverage/ -.coveralls.yml +**coveralls.env +**.nyc_output/ # fastlane # diff --git a/.travis.yml b/.travis.yml index 1f32f20..57ae2a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,47 +1,20 @@ -sudo: required language: node_js -services: - - docker node_js: - "8" -cache: - directories: - - "node_modules" -script: - - npm install -g - - npm run lint -matrix: - include: - - language: node_js - os: linux - install: - - before_install: - - sudo apt-get remove docker docker-engine docker.io - - sudo apt-get update - - sudo apt-get install apt-transport-https ca-certificates curl software-properties-common - - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - - sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose - - sudo chmod +x /usr/local/bin/docker-compose - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" - - sudo apt-get update - - sudo apt-get install docker-ce - - docker-compose version - - docker version - - before_script: - - cd $TRAVIS_BUILD_DIR/Database - - sudo docker-compose up --build -d& - - cd $TRAVIS_BUILD_DIR/RabbitMQ - - sudo docker-compose up --build -d& - - cd $TRAVIS_BUILD_DIR/User - - sudo docker-compose up --build -d& - - cd $TRAVIS_BUILD_DIR/Login - - sudo docker-compose up --build -d& +env: + - DOCKER_COMPOSE_VERSION=1.21.0 +services: + - docker - env: - - DOCKER_COMPOSE_VERSION=1.21.0 +before_install: + - sudo curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose + - sudo chmod +x /usr/local/bin/docker-compose + - docker-compose version + - docker version +before_script: + - ./utils/script_coveralls.sh + - cd $TRAVIS_BUILD_DIR/Docker/Test + - sudo docker-compose -f build.yml build - script: - - cd $TRAVIS_BUILD_DIR/Login - - sudo docker-compose run loginserver npm run test +script: + - sudo docker-compose -f start-sector.yml run sectorserver npm run coverage diff --git a/Client/Dockerfile b/Client/Dockerfile deleted file mode 100644 index 3369f9b..0000000 --- a/Client/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM node:latest - -RUN mkdir -p /usr/src/app -RUN npm install nodemon -g - -WORKDIR /usr/src/app -COPY package.json /usr/src/app/package.json -RUN npm install -g - -EXPOSE 8080 - - -CMD ["npm", "start"] diff --git a/Docker/Test/build.yml b/Docker/Test/build.yml index f966f08..b54e865 100644 --- a/Docker/Test/build.yml +++ b/Docker/Test/build.yml @@ -1,14 +1,14 @@ version: '3.5' services: - userserver: - image: dulce/user-server:test + sectorserver: + image: dulce/sector-server:test build: context: ../../ dockerfile: Docker/Test/Server/Dockerfile - userclient: - image: dulce/user-client:test + sectorclient: + image: dulce/sector-client:test build: context: ../../ dockerfile: Docker/Test/Client/Dockerfile diff --git a/Docker/Test/start-user.yml b/Docker/Test/start-sector.yml similarity index 79% rename from Docker/Test/start-user.yml rename to Docker/Test/start-sector.yml index 8a0ee36..4b64d40 100644 --- a/Docker/Test/start-user.yml +++ b/Docker/Test/start-sector.yml @@ -1,8 +1,8 @@ version: '3.5' services: - userserver: - image: dulce/user-server:test + sectorserver: + image: dulce/sector-server:test restart: always env_file: - ./env/coveralls.env diff --git a/Server/Dockerfile b/Server/Dockerfile deleted file mode 100644 index 3369f9b..0000000 --- a/Server/Dockerfile +++ /dev/null @@ -1,13 +0,0 @@ -FROM node:latest - -RUN mkdir -p /usr/src/app -RUN npm install nodemon -g - -WORKDIR /usr/src/app -COPY package.json /usr/src/app/package.json -RUN npm install -g - -EXPOSE 8080 - - -CMD ["npm", "start"] diff --git a/Server/package.json b/Server/package.json index 80649e0..02d580f 100644 --- a/Server/package.json +++ b/Server/package.json @@ -5,13 +5,16 @@ "main": "app.js", "scripts": { "start": "nodemon sector.js", - "test": "./node_modules/.bin/mocha --reporter spec" + "test": "nyc --reporter=html --reporter=text mocha", + "coverage": "npm run cover && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", + "cover": "istanbul cover _mocha" }, "author": "", "license": "MIT", "dependencies": { - "bcrypt": "^1.0.3", + "bcrypt": "2.0.1", "body-parser": "1.15.2", + "chai": "^4.1.2", "express": "^4.14.0", "jsonwebtoken": "^8.2.0", "mongoose": "^4.6.1", @@ -25,9 +28,11 @@ "seneca-web-adapter-express": "^1.1.1" }, "devDependencies": { + "coveralls": "^3.0.1", "istanbul": "^0.4.5", - "jest": "^22.4.3", "mocha": "^5.0.5", + "mocha-lcov-reporter": "^1.3.0", + "nyc": "^11.7.3", "should": "^13.2.1", "supertest": "^3.0.0" } diff --git a/Server/test/sector.test.js b/Server/test/sector.test.js new file mode 100644 index 0000000..bff9715 --- /dev/null +++ b/Server/test/sector.test.js @@ -0,0 +1,30 @@ +var Seneca = require('seneca') +var assert = require('assert') +var chai = require('chai') + + +var expect = chai.expect; + +function test_sector_seneca (fin){ + return Seneca({log: 'test'}) + .test(fin) + + .use("entity") + .use(require('../_sector')) +} + +describe('Create sector', function() { + + it('Sector entity creation', function(fin){ + var seneca = test_sector_seneca(fin) + + seneca.act({ + role: 'sector', + cmd: 'create', + name: 'Pediatria' + }, function(err, result){ + expect(result.name).to.equal('Pediatria') + fin() + }) + }) +}); diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index c1dbb3c..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: "3.5" -services: - sectorserver: - build: ./Server - command: bash -c "npm install; nodemon sector.js --color=always" - ports: - - "8087:8080" - volumes: - - ./Server:/usr/src/app - networks: - - mongo_gabriela - - rabbitmq_gama - - sectorclient: - build: ./Client - command: bash -c "npm install; nodemon client_sector.js --color=always" - ports: - - "8084:8080" - volumes: - - ./Client:/usr/src/app - networks: - - mongo_gabriela - - rabbitmq_gama - -networks: - mongo_gabriela: - external: - name: my_network - rabbitmq_gama: - external: - name: my_network_gama diff --git a/utils/script_coveralls.sh b/utils/script_coveralls.sh old mode 100644 new mode 100755