Skip to content

Commit cae6844

Browse files
author
Sean P. Kane
committed
Initial Commit
0 parents  commit cae6844

23 files changed

+773
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitignore

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Node.js stuff
2+
node_modules
3+
*.log
4+
.hubot_history
5+
6+
#Mac OS X Stuff
7+
.DS_Store*
8+
9+
#Vagrant stuff
10+
.vagrant
11+
config.rb
12+
13+
#Things that have secrets in them
14+
secret-*
15+
newrelic.js
16+
srbot.rake
17+
centurion-configs

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:5.7.1
2+
3+
RUN mkdir -p /data/app/bin && mkdir -p /data/app/scripts
4+
5+
RUN apt-get -y update
6+
RUN apt-get -y install supervisor python-pip
7+
RUN easy_install -U pip
8+
RUN pip install supervisor-stdout
9+
RUN mkdir -p /var/log/supervisor
10+
11+
# Supervisor Configuration
12+
ADD ./supervisord/conf.d/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
13+
ADD ./supervisord/conf.d/hubot.conf /etc/supervisor/conf.d/hubot.conf
14+
15+
ADD ./bin /data/app/bin
16+
ADD ./scripts /data/app/scripts
17+
ADD ./*.json /data/app/
18+
19+
RUN cd /data/app && npm install
20+
21+
CMD supervisord -n
22+

README.md

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
## docker-hubot
2+
3+
docker-hubot is a chat bot built on the [Hubot][hubot] framework. It was initially generated by [generator-hubot][generator-hubot]. mybot now runs in a Docker container.
4+
5+
[hubot]: http://hubot.github.com
6+
[generator-hubot]: https://github.com/github/generator-hubot
7+
8+
### Development
9+
10+
#### Step 0: Local development setup (non-dockerized)
11+
12+
* Install Node & Redis (for hubot)
13+
14+
```
15+
brew install node
16+
brew install redis
17+
```
18+
19+
* Install Node Modules (for hubot)
20+
21+
```
22+
export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig
23+
npm install
24+
```
25+
26+
27+
### Step 1a: Running mybot Locally (non-dockerized)
28+
29+
If you are testing scripts that require persistence (redis brain), make sure you start Redis:
30+
31+
```
32+
redis-server &
33+
```
34+
35+
Hubot absorbs all of its configuration from environment variables, so you will want to create a `.config` file, and store the variables you need there. It's suggested to name the file `secret-dev-hubot.config`, since that is already listed in the `.gitignore` file.
36+
37+
Once you have your config file, you can start hubot locally in shell using:
38+
39+
```
40+
. secret-dev-hubot.config; bin/hubot --alias devbot --adapter shell
41+
```
42+
43+
You'll see some start up output about where your scripts come from and a
44+
prompt:
45+
46+
```
47+
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading adapter shell
48+
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading scripts from /home/tomb/Development/hubot/scripts
49+
[Sun, 04 Dec 2011 18:41:11 GMT] INFO Loading scripts from /home/tomb/Development/hubot/src/scripts
50+
Hubot>
51+
```
52+
53+
Then you can interact with srbot by typing `hubot help`.
54+
55+
```
56+
hubot> hubot help
57+
hubot> animate me <query> - The same thing as `image me`, except adds a few
58+
convert me <expression> to <units> - Convert expression to given units.
59+
help - Displays all of the help commands that Hubot knows about.
60+
...
61+
```
62+
63+
You can also test in Slack using the following command:
64+
65+
```
66+
. secret-dev-hubot.config; bin/hubot --alias hu --adapter slack
67+
```
68+
69+
### Step 1b: Running hubot Locally (Dockerized)
70+
71+
Start a local docker vm using docker-machine:
72+
73+
```
74+
docker-machine init
75+
docker-machine create --driver virtualbox default
76+
docker-machine env default
77+
eval $(docker-machine env default)
78+
```
79+
80+
There is a script in ./deploy you can use to run hubot locally. Here is
81+
how to get that running.
82+
83+
```
84+
. secret-dev-hubot.config; ./deploy/build_local_dev.sh
85+
```
86+
87+
---
88+
89+
# Scripting
90+
91+
An example script is included at `scripts/example.coffee`, so check it out to
92+
get started, along with the [Scripting Guide](https://github.com/github/hubot/blob/master/docs/scripting.md).
93+
94+
For many common tasks, there's a good chance someone has already one to do just
95+
the thing.
96+
97+
## hubot-scripts
98+
99+
There will inevitably be functionality that everyone will want. Instead
100+
of writing it yourself, you can check
101+
[hubot-scripts][hubot-scripts] for existing scripts.
102+
103+
To enable scripts from the hubot-scripts package, add the script name with
104+
extension as a double quoted string to the `hubot-scripts.json` file in this
105+
repo.
106+
107+
[hubot-scripts]: https://github.com/github/hubot-scripts
108+
109+
## external-scripts
110+
111+
Hubot is able to load scripts from third-party `npm` package. Check the package's documentation, but in general it is:
112+
113+
1. Add the packages as dependencies into your `package.json`
114+
2. `npm install` to make sure those packages are installed
115+
3. Add the package name to `external-scripts.json` as a double quoted string
116+
117+
You can review `external-scripts.json` to see what is included by default.
118+
119+
## Persistence
120+
121+
The bot relies on Redis for persistance; the data stored in Redis is consumed by Upboard to automatically fill out initial emergency info. While Redis is not required for local development, upon deployment, Redis should be available.
122+
123+
In addition, persistance will ensure that if the bot is restarted, emergency state is retained for all rooms.
124+
125+
If you are going to use the `hubot-redis-brain` package (strongly suggested), you will need to setup Redis and manually set the `REDIS_URL` variable.
126+
127+
[redis]: https://redis.io/
128+
129+
## Adapters
130+
131+
Adapters are the interface to the service you want your hubot to run on. This
132+
can be something like Campfire or IRC. There are a number of third party
133+
adapters that the community have contributed. Check
134+
[Hubot Adapters][hubot-adapters] for the available ones.
135+
136+
If you would like to run a non-Campfire or shell adapter you will need to add
137+
the adapter package as a dependency to the `package.json` file in the
138+
`dependencies` section.
139+
140+
Once you've added the dependency and run `npm install` to install it you can
141+
then run hubot with the adapter.
142+
143+
$ bin/hubot -a <adapter>
144+
145+
Where `<adapter>` is the name of your adapter without the `hubot-` prefix.
146+
147+
[hubot-adapters]: https://github.com/github/hubot/blob/master/docs/adapters.md
148+

Vagrantfile

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require 'socket'
2+
require 'fileutils'
3+
4+
Vagrant.require_version ">= 1.6.0"
5+
USER = ENV['USER']
6+
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'docker'
7+
8+
host_ip_obj = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
9+
host_ip = host_ip_obj.ip_address
10+
11+
# The Docker host typically uses CONFIG, hence LOCAL_CONFIG
12+
LOCAL_CONFIG = File.join(File.dirname(__FILE__), "config.rb")
13+
14+
# We don't define defaults for most things, as we really need
15+
# user defined variables for a lot of things
16+
#
17+
# Copy config.rb.sample to config.rb and edit as needed
18+
BIND_ADDRESS="0.0.0.0"
19+
ENVIRONMENT="development"
20+
SERVICE_NAME="bot"
21+
EXPRESS_USER="vagrant"
22+
EXPRESS_PASSWORD="vagrant"
23+
PORT="8080"
24+
HUBOT_ADAPTER="shell"
25+
HUBOT_ALIAS="hu"
26+
HUBOT_NAME="bot"
27+
HUBOT_AWS_KEY=""
28+
HUBOT_AWS_SECRET=""
29+
HUBOT_AWS_S3_BUCKET=""
30+
HUBOT_LOG_LEVEL="debug"
31+
REDIS_URL="redis://#{host_ip}:6379"
32+
HUBOT_SLACK_TOKEN=""
33+
34+
if File.exist?(LOCAL_CONFIG)
35+
# Supress warning messages.
36+
original_verbose, $VERBOSE = $VERBOSE, nil
37+
require LOCAL_CONFIG
38+
# Activate warning messages again.
39+
$VERBOSE = original_verbose
40+
end
41+
42+
Vagrant.configure("2") do |config|
43+
config.vm.provider "docker" do |d|
44+
d.vagrant_vagrantfile = "../coreos-vagrant/Vagrantfile"
45+
d.vagrant_machine = 'core-01'
46+
d.build_dir = "."
47+
d.host_vm_build_dir_options = { :type => "rsync", :rsync__exclude => ".git/" }
48+
d.force_host_vm = true
49+
d.ports = ["14242:#{PORT}"]
50+
d.env = {
51+
:DEV_HOST => host_ip,
52+
:BIND_ADDRESS => BIND_ADDRESS,
53+
:ENVIRONMENT => ENVIRONMENT,
54+
:EXPRESS_USER => EXPRESS_USER,
55+
:EXPRESS_PASSWORD => EXPRESS_PASSWORD,
56+
:PORT => PORT,
57+
:HUBOT_ADAPTER => HUBOT_ADAPTER,
58+
:HUBOT_ALIAS => HUBOT_ALIAS,
59+
:HUBOT_NAME => HUBOT_NAME,
60+
:HUBOT_LOG_LEVEL => HUBOT_LOG_LEVEL,
61+
:REDIS_URL => REDIS_URL,
62+
:HUBOT_SLACK_TOKEN => HUBOT_SLACK_TOKEN
63+
}
64+
d.remains_running = true
65+
end
66+
end
67+

bin/hubot

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
npm install
6+
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"
7+
8+
exec node_modules/.bin/hubot "$@"

bin/hubot-env

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
npm install
6+
export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"
7+
8+
exec node_modules/.bin/hubot --adapter ${HUBOT_ADAPTER} --alias ${HUBOT_ALIAS} --name ${HUBOT_NAME} "$@"

bin/hubot.cmd

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
3+
npm install && node_modules\.bin\hubot.cmd %*

config.rb.sample

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'socket'
2+
3+
host_ip_obj = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
4+
host_ip = host_ip_obj.ip_address
5+
6+
USER = ENV['USER']
7+
8+
#Docker ENV Variables
9+
BIND_ADDRESS="0.0.0.0"
10+
ENVIRONMENT="development"
11+
SERVICE_NAME="bot"
12+
SERVICE_ENV="development"
13+
EXPRESS_USER="vagrant"
14+
EXPRESS_PASSWORD="vagrant"
15+
PORT="8080"
16+
HUBOT_ADAPTER="slack"
17+
HUBOT_ALIAS="hu"
18+
HUBOT_NAME="bot"
19+
HUBOT_LOG_LEVEL="debug"
20+
HUBOT_SLACK_TOKEN=""
21+
REDIS_URL="redis://#{host_ip}:6379"

deploy/build_local_dev.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
docker build -t spkane/mybot:latest .
2+
docker push spkane/mybot:latest
3+
docker run \
4+
-e BIND_ADDRESS="${BIND_ADDRESS}" \
5+
-e ENVIRONMENT="${ENVIRONMENT}" \
6+
-e SERVICE_NAME="${SERVICE_NAME}" \
7+
-e SERVICE_ENV="${SERVICE_ENV}" \
8+
-e EXPRESS_USER="${EXPRESS_USER}" \
9+
-e EXPRESS_PASSWORD="${EXPRESS_PASSWORD}" \
10+
-e PORT="${PORT}" \
11+
-e HUBOT_ADAPTER="${HUBOT_ADAPTER}" \
12+
-e HUBOT_ALIAS="${HUBOT_ALIAS}" \
13+
-e HUBOT_NAME="${HUBOT_NAME}" \
14+
-e REDIS_URL="${REDIS_URL}" \
15+
-e HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}" \
16+
-d --restart="always" --name mybot spkane/mybot:latest
17+

deploy/build_production.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
docker run \
2+
-e BIND_ADDRESS="${BIND_ADDRESS}" \
3+
-e ENVIRONMENT="${ENVIRONMENT}" \
4+
-e SERVICE_NAME="${SERVICE_NAME}" \
5+
-e SERVICE_ENV="${SERVICE_ENV}" \
6+
-e EXPRESS_USER="${EXPRESS_USER}" \
7+
-e EXPRESS_PASSWORD="${EXPRESS_PASSWORD}" \
8+
-e PORT="${PORT}" \
9+
-e HUBOT_ADAPTER="${HUBOT_ADAPTER}" \
10+
-e HUBOT_ALIAS="${HUBOT_ALIAS}" \
11+
-e HUBOT_NAME="${HUBOT_NAME}" \
12+
-e REDIS_URL="${REDIS_URL}" \
13+
-e HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}" \
14+
-d --restart="always" --name mybot spkane/mybot:production
15+

deploy/build_staging.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
docker run \
2+
-e BIND_ADDRESS="${BIND_ADDRESS}" \
3+
-e ENVIRONMENT="${ENVIRONMENT}" \
4+
-e SERVICE_NAME="${SERVICE_NAME}" \
5+
-e SERVICE_ENV="${SERVICE_ENV}" \
6+
-e EXPRESS_USER="${EXPRESS_USER}" \
7+
-e EXPRESS_PASSWORD="${EXPRESS_PASSWORD}" \
8+
-e PORT="${PORT}" \
9+
-e HUBOT_ADAPTER="${HUBOT_ADAPTER}" \
10+
-e HUBOT_ALIAS="${HUBOT_ALIAS}" \
11+
-e HUBOT_NAME="${HUBOT_NAME}" \
12+
-e REDIS_URL="${REDIS_URL}" \
13+
-e HUBOT_SLACK_TOKEN="${HUBOT_SLACK_TOKEN}" \
14+
-d --restart="always" --name mybot spkane/mybot:staging
15+

dev-hubot.config

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Load this configuration into your shell environment using:
3+
#
4+
# source dev-hubot.config
5+
#
6+
# PLEASE 'cp dev-hubot.config secret-dev-hubot.config',
7+
# if you want to keep a copy of this script with your
8+
# KEYS and other secrets in it. Git will ignore it.
9+
#
10+
11+
export BIND_ADDRESS="0.0.0.0"
12+
export ENVIRONMENT="development"
13+
export SERVICE_NAME="mybot"
14+
export SERVICE_ENV="development"
15+
export EXPRESS_USER="mybot"
16+
export EXPRESS_PASSWORD="REDACTED"
17+
export PORT="8080"
18+
export HUBOT_ADAPTER="slack"
19+
export HUBOT_ALIAS="hu"
20+
export HUBOT_NAME="mybot"
21+
export HUBOT_LOG_LEVEL="debug"
22+
export REDIS_URL="redis://127.0.0.1:6379"
23+
export HUBOT_SLACK_TOKEN="redacted"

external-scripts.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"hubot-diagnostics",
3+
"hubot-help",
4+
"hubot-google-translate",
5+
"hubot-redis-brain"
6+
]

0 commit comments

Comments
 (0)