Skip to content

Commit

Permalink
This PR has morphed a bit from its original form:
Browse files Browse the repository at this point in the history
- Update Node to Node 5.x
- Add docker compose for easier provisioning
- Add userName and realName for the bot
- Wait until the bot is connected to log the channel it is on
- Address a security vulnerability in moment.js
- Add david-dm.org badge to track up to date packages and whether or not
- they are vulnerable
  • Loading branch information
robbyoconnor committed Feb 29, 2016
1 parent 4ca141e commit cd318be
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
irc:channel=#openmrstest
elasticsearch:host=http://elasticsearch:9200
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
config.json
node_modules
logs
npm-debug.log
npm-debug.log
esdata
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM node:4-onbuild
FROM node:5-onbuild

EXPOSE 3000
EXPOSE 3000
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Record Scrum notes from the #openmrs IRC channel
[![Dependency Status](https://david-dm.org/djazayeri/openmrs-contrib-scrumbot.svg)](https://david-dm.org/djazayeri/openmrs-contrib-scrumbot)

You may set settings such as the channel and the elasticsearch host in `.env`, which is in this working directory, or optionally in `config.json`. A sample `.env` file is provided. `config.js` has defaults.

## Before building

npm install -g mocha

## Development

### ES (for a dev environment on OSX)
This requires [docker-compose][] for provisioning. For development, simply do:

$ docker run --name es -d -p 9200:9200 -p 9300:9300 elasticsearch -Des.network.bindHost=0.0.0.0
## Run just the listener (without the webapp)

$ node index --elasticsearch.host http://192.168.99.100:9200
Expand All @@ -30,28 +31,41 @@ If you do not have elasticsearch running on localhost:9200, then create a "confi
Then

$ npm start

And see the webapp running on http://localhost:3000

### Testing the docker build locally

$ docker run --name web -d -p 3000:3000 --link es:es -e "elasticsearch:host=http://es:9200" -e "irc:channel=#openmrstest" djazayeri/openmrs-scrumbot:1.0
``` shell
$ docker-compose run elasticsearch web
```

## Prod
## Production

Note: this approach uses LINK networking, which will eventually be deprecated in Docker.

### ES for prod on a Digital Ocean one-click app Docker box (don't expose ElasticSearch to the outside world, since it isn't secured)
### ES for production on a Digital Ocean one-click app Docker box (don't expose ElasticSearch to the outside world, since it isn't secured)

``` shell
$ docker-compose -f docker-compose.yml -f docker-compose-prod.yml up -d elasticsearch web
```

$ docker run -d --restart="unless-stopped" --name es -v "$PWD/esdata":/usr/share/elasticsearch/data -p 127.0.0.1:9200:9200 elasticsearch

### dockerhub does builds automatically

Whenever you commit code to this repository it is automatically built as djazayeri/openmrs-contrib-scrumbot:latest
Whenever you commit code to this repository it is automatically built as djazayeri/openmrs-contrib-scrumbot:latest

### run webapp+bot on docker on Digital Ocean

// this is automated as ./update-web
``` shell
$ docker pull djazayeri/openmrs-contrib-scrumbot:latest
$ docker rm web
$ docker run -d -p 80:3000 --name web --link es:es -e "elasticsearch:host=http://es:9200" djazayeri/openmrs-contrib-scrumbot:latest
```

You may also use [docker-compose][] to handle this:

``` shell
$ docker-compose -f docker-compose.yml -f docker-compose-prod.yml up -d elasticsearch web
```

[docker-compose]: https://docs.docker.com/compose/
3 changes: 2 additions & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
var app = require('../server');
var debug = require('debug')('scrumbot:server');
var http = require('http');
var log = require('../log');

/**
* Get port from environment and store in Express.
Expand Down Expand Up @@ -86,5 +87,5 @@ function onListening() {
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
log.info('Listening on ' + bind);
}
4 changes: 3 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ nconf
server: "chat.freenode.net",
channel: "#openmrs",
nick: "omrs-scrum-bot",
userName: "scrumbot",
realName: "OpenMRS Scrum Bot",
startListening: "!scrumon",
stopListening: "!scrumoff",
sayBuildFailures: "!scrumon"
Expand All @@ -22,4 +24,4 @@ nconf
}
});

module.exports = nconf;
module.exports = nconf;
4 changes: 4 additions & 0 deletions docker-compose-overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
elasticsearch:
ports:
– "9200:9200"
- "9300:9300"
12 changes: 12 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
elasticsearch:
ports:
- "127.0.0.1:9200:9200"
- "127.0.0.1:9300:9300"
restart: unless-stopped

web:
ports:
- "80:3000"
restart: unless-stopped
environment:
- NODE_ENV=production
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
web:
build: .
ports:
- "3000:3000"
links:
- elasticsearch
env_file: ./.env
restart: unless-stopped

elasticsearch:
image: elasticsearch:latest
command: elasticsearch -Des.network.bindHost=0.0.0.0
restart: unless-stopped
volumes:
- "./esdata:/usr/share/elasticsearch/data"
13 changes: 9 additions & 4 deletions ircbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var bamboo = require("./bamboo");
var SERVER = config.get("irc").server;
var CHANNEL = config.get("irc").channel;
var NICK = config.get("irc").nick;
var USERNAME = config.get("irc").userName;
var REALNAME = config.get("irc").realName;
var START_LISTENING = config.get("irc").startListening;
var STOP_LISTENING = config.get("irc").stopListening;
var SAY_BUILD_FAILURES = config.get("irc").sayBuildFailures;
Expand All @@ -22,8 +24,11 @@ var postMessage = function (text) {
client.say(CHANNEL, text);
};

var client = new irc.Client(SERVER, NICK, {channels: [CHANNEL]});
log.info("Connected to " + CHANNEL);
var client = new irc.Client(SERVER, NICK, {userName: USERNAME, realName: REALNAME, channels: [CHANNEL]});

client.addListener('names', function(channel, nicks) {
log.info("Connected to " + CHANNEL);
});

client.addListener('error', function (message) {
log.error(message);
Expand Down Expand Up @@ -74,12 +79,12 @@ client.addListener('message', function (from, to, message) {
bamboo.summarizeBrokenBuilds().then(function (summary) {
_.each(summary, function (line) {
postMessage(line);
})
});
});
}
});

module.exports.shouldStartListening = shouldStartListening;
module.exports.shouldStopListening = shouldStopListening;
module.exports.shouldListBuildFailures = shouldListBuildFailures;
module.exports.postMessage = postMessage;
module.exports.postMessage = postMessage;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
"fs": "0.0.2",
"irc": "^0.4.0",
"jade": "^1.11.0",
"lodash": "^3.10.1",
"lodash": "^4.5.1",
"log4js": "^0.6.29",
"moment": "^2.11.1",
"moment": "^2.11.2",
"morgan": "^1.6.1",
"nconf": "^0.8.2",
"request": "^2.67.0",
Expand Down

0 comments on commit cd318be

Please sign in to comment.