From d2dbbcd67f8fd188c73cfa0304e9e7d354dcd6b5 Mon Sep 17 00:00:00 2001 From: Robert O'Connor Date: Sat, 27 Feb 2016 08:15:11 -0500 Subject: [PATCH] This PR has morphed a bit from its original form: - 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 --- .env | 2 ++ .gitignore | 3 ++- README.md | 35 +++++++++++++++++++++++------------ config.js | 5 ++++- docker-compose-overrides.yml | 4 ++++ docker-compose-prod.yml | 9 +++++++++ docker-compose.yml | 14 ++++++++++++++ ircbot.js | 13 +++++++++---- 8 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 .env create mode 100644 docker-compose-overrides.yml create mode 100644 docker-compose-prod.yml create mode 100644 docker-compose.yml diff --git a/.env b/.env new file mode 100644 index 0000000..0332ac9 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +irc:channel=#openmrstest +elasticsearch:host=http://elasticsearch:9200 diff --git a/.gitignore b/.gitignore index 6cd1760..9a34b0c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ config.json node_modules logs -npm-debug.log \ No newline at end of file +npm-debug.log +esdata \ No newline at end of file diff --git a/README.md b/README.md index c26754b..c3919c7 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,13 @@ # Record Scrum notes from the #openmrs IRC channel - +You may set settings such as the channel and the elasticsearch host [.env](.env) in this working directory, or optionally in `config.json`. A sample `.env` file is provided. ## 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 @@ -30,28 +28,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/ diff --git a/config.js b/config.js index 664c37d..c646e0e 100644 --- a/config.js +++ b/config.js @@ -8,8 +8,11 @@ nconf .defaults({ irc: { server: "chat.freenode.net", + port: "7000", channel: "#openmrs", nick: "omrs-scrum-bot", + userName: "scrumbot", + realName: "OpenMRS Scrum Bot", startListening: "!scrumon", stopListening: "!scrumoff", sayBuildFailures: "!scrumon" @@ -22,4 +25,4 @@ nconf } }); -module.exports = nconf; \ No newline at end of file +module.exports = nconf; diff --git a/docker-compose-overrides.yml b/docker-compose-overrides.yml new file mode 100644 index 0000000..0515069 --- /dev/null +++ b/docker-compose-overrides.yml @@ -0,0 +1,4 @@ +elasticsearch: + ports: + – "9200:9200" + - "9300:9300" diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml new file mode 100644 index 0000000..31d01bc --- /dev/null +++ b/docker-compose-prod.yml @@ -0,0 +1,9 @@ +elasticsearch: + ports: + - "127.0.0.1:9200:9200" + - "127.0.0.1:9300:9300" +web: + ports: + - "80:3000" + environment: + - NODE_ENV=production diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6b4ced1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +web: + build: . + 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" + diff --git a/ircbot.js b/ircbot.js index eeed62a..da1b791 100644 --- a/ircbot.js +++ b/ircbot.js @@ -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; @@ -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('motd', function(message) { + log.info("Connected to " + CHANNEL); +}); client.addListener('error', function (message) { log.error(message); @@ -74,7 +79,7 @@ client.addListener('message', function (from, to, message) { bamboo.summarizeBrokenBuilds().then(function (summary) { _.each(summary, function (line) { postMessage(line); - }) + }); }); } }); @@ -82,4 +87,4 @@ client.addListener('message', function (from, to, message) { module.exports.shouldStartListening = shouldStartListening; module.exports.shouldStopListening = shouldStopListening; module.exports.shouldListBuildFailures = shouldListBuildFailures; -module.exports.postMessage = postMessage; \ No newline at end of file +module.exports.postMessage = postMessage;