diff --git a/Dockerfile b/Dockerfile index 6f10c562..51e422ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,34 +2,21 @@ # Mainflux Dockerfile ### # Set the base image to Node, onbuild variant: https://registry.hub.docker.com/_/node/ -FROM node:0.10-onbuild -# Maintained by Mainflux team -MAINTAINER Mainflux +FROM node:0.10.38 -# Log info -RUN echo "Starting Mainflux server..." +RUN apt-get update -qq && apt-get install -y build-essential + +RUN mkdir /src -### -# Installations -### -# Add Gulp globally RUN npm install -g gulp +RUN npm install -g nodemon -# Gulp also demands to be saved locally -RUN npm install --save-dev gulp - -# Finally, install all project Node modules +WORKDIR /src +ADD package.json /src/package.json RUN npm install -### -# Setup the port -### -# Run Mainflux on port 80 -ENV PORT 80 - -# Expose port on which we run Mainflux -EXPOSE $PORT +EXPOSE 8080 ### # Run main command from entrypoint and parameters in CMD[] @@ -39,4 +26,3 @@ CMD [""] # Set default container command ENTRYPOINT gulp - diff --git a/config/config.js b/config/config.js index 72d20ebe..dedc05b4 100644 --- a/config/config.js +++ b/config/config.js @@ -1,4 +1,4 @@ /* * Following recipe here: http://dailyjs.com/2014/01/02/recipe-for-express-configuration/ */ -module.exports = require('./' + (process.env.NODE_ENV || 'development') + '.json'); +module.exports = require('./' + (process.env.NODE_ENV || 'development') + '.json'); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..fb336f54 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +api: + build: . + volumes: + - ".:/src" + ports: + - "8080:8080" + # set up links so that api knows about db, redis, etc... + links: + - mongodb + +mongodb: + image: mongo + ports: + - "27017:27017" diff --git a/gulpfile.js b/gulpfile.js index 2ed9be8c..30cc8d5f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -18,7 +18,7 @@ gulp.task('jshint', function() { // configure which files to watch and what tasks to use on file changes gulp.task('watch', function() { gulp.watch('app/**/*.js', ['jshint']); - + // Start up the server and have it reload when anything in the // ./build/ directory changes nodemon({script: 'server.js', watch: 'app/**'}); diff --git a/package.json b/package.json index 3967214c..563469e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,12 @@ { "name": "node-api", + "description": "Mainflux is an open source MIT licensed IoT cloud written in NodeJS", "main": "server.js", + "repository": { + "type": "git", + "url": "https://github.com/Mainflux/mainflux" + }, + "dependencies": { "express": "~4.0.0", "mongoose": "~3.6.13", diff --git a/server.js b/server.js index 0e84be8e..29155d6b 100644 --- a/server.js +++ b/server.js @@ -17,8 +17,10 @@ var bodyParser = require('body-parser'); // MongoDB var mongoose = require('mongoose'); +// Docker MongoDB url +var docker_mongo_url = process.env.MAINFLUX_MONGODB_1_PORT_27017_TCP_ADDR -mongoose.connect(config.db.path + ':' + config.db.port + '/' + config.db.name); // connect to our database +mongoose.connect(docker_mongo_url || config.db.path + ':' + config.db.port + '/' + config.db.name); // connect to our database // configure app to use bodyParser()