diff --git a/Dockerfile b/Dockerfile index 51cffe30..1fe65834 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,8 @@ ### # Set the base image to Node, onbuild variant: https://registry.hub.docker.com/_/node/ -FROM node:0.10.38 +FROM node:4.2.3 +MAINTAINER Mainflux RUN apt-get update -qq && apt-get install -y build-essential diff --git a/app/database.js b/app/database.js index 70328a65..2f9ea709 100644 --- a/app/database.js +++ b/app/database.js @@ -5,13 +5,20 @@ var config = require('../config/config'); */ var mongojs = require('mongojs'); -/** Docker MongoDB url */ -var docker_mongo_url = process.env.MAINFLUX_MONGODB_1_PORT_27017_TCP_ADDR - /** Connect to DB */ -console.log("Connecting to DB"); var collections = ['devices']; -var db = mongojs(docker_mongo_url || config.db.path + ':' + config.db.port + '/' + config.db.name); + +/** Check if we run with Docker compose */ +var dockerMongo = process.env.MONGODB_NAME; +var dbUrl = ''; +if (dockerMongo && dockerMongo == '/mainflux-api-docker/mongodb') { + dbUrl = 'mongodb://' + process.env.MONGODB_PORT_27017_TCP_ADDR + ':' + process.env.MONGODB_PORT_27017_TCP_PORT + '/' + config.db.name; +} else { + dbUrl = 'mongodb://' + config.db.addr + ':' + config.db.port + '/' + config.db.name; +} + +var db = mongojs(dbUrl); + /** * EXPORTS diff --git a/config/development.json b/config/development.json index ba598a5e..8da0a6f7 100644 --- a/config/development.json +++ b/config/development.json @@ -1,7 +1,7 @@ { "message" : "We are in development", "db" : { - "path" : "mongodb://localhost", + "addr" : "localhost", "port" : "27017", "name" : "test" }, diff --git a/docker-compose.yml b/docker-compose.yml index fb336f54..10834fa0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,8 +7,10 @@ api: # set up links so that api knows about db, redis, etc... links: - mongodb + container_name: mainflux-api-docker mongodb: image: mongo ports: - "27017:27017" + container_name: mainflux-mongo-docker