| @@ -0,0 +1,29 @@ | ||
| 1 | +FROM ubuntu:14.04 | |
| 2 | +MAINTAINER ian@blenke.com | |
| 3 | + | |
| 4 | +ENV DEBIAN_FRONTEND noninteractive | |
| 5 | +RUN apt-get update && \ | |
| 6 | + apt-get install -y software-properties-common && \ | |
| 7 | + add-apt-repository -y ppa:git-core/ppa && \ | |
| 8 | + add-apt-repository -y ppa:brightbox/ruby-ng && \ | |
| 9 | + apt-get update && \ | |
| 10 | + apt-get install -y build-essential checkinstall postgresql-client \ | |
| 11 | + git-core mysql-server redis-server python2.7 python-docutils \ | |
| 12 | + libmysqlclient-dev libpq-dev zlib1g-dev libyaml-dev libssl-dev \ | |
| 13 | + libgdbm-dev libreadline-dev libncurses5-dev libffi-dev \ | |
| 14 | + libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev \ | |
| 15 | + ruby2.1 ruby2.1-dev supervisor && \ | |
| 16 | + gem install --no-ri --no-rdoc bundler && \ | |
| 17 | + rm -rf /var/lib/apt/lists/* | |
| 18 | + | |
| 19 | +ADD scripts/ /scripts | |
| 20 | +RUN chmod 755 /scripts/setup /scripts/init | |
| 21 | + | |
| 22 | +RUN /scripts/setup | |
| 23 | + | |
| 24 | +VOLUME /var/lib/mysql | |
| 25 | + | |
| 26 | +EXPOSE 5000 | |
| 27 | + | |
| 28 | +CMD ["/scripts/init"] | |
| 29 | + | 
| @@ -0,0 +1,2 @@ | ||
| 1 | +build: | |
| 2 | + docker build -t cantino/huginn . | 
| @@ -0,0 +1,124 @@ | ||
| 1 | +Huginn for docker with multiple container linkage | |
| 2 | +================================================= | |
| 3 | + | |
| 4 | +This image runs a linkable [Huginn](https://github.com/cantino/huginn) instance. | |
| 5 | + | |
| 6 | +There is an automated build repository on docker hub for [cantino/huginn](https://registry.hub.docker.com/builds/github/cantino/huginn/). | |
| 7 | + | |
| 8 | +This was patterned after [sameersbn/gitlab](https://registry.hub.docker.com/u/sameersbn/gitlab) by [ianblenke/huginn](http://github.com/ianblenke/huginn), and imported here for official generation of a docker hub auto-build image. | |
| 9 | + | |
| 10 | +The scripts/init script generates a .env file containing the variables as passed as per normal Huginn documentation. | |
| 11 | +The same environment variables that would be used for Heroku PaaS deployment are used by this script. | |
| 12 | + | |
| 13 | +The scripts/init script is aware of mysql and postgres linked containers through the environment variables: | |
| 14 | + | |
| 15 | + MYSQL_PORT_3306_TCP_ADDR | |
| 16 | + MYSQL_PORT_3306_TCP_PORT | |
| 17 | + | |
| 18 | +and | |
| 19 | + | |
| 20 | + POSTGRESQL_PORT_5432_TCP_ADDR | |
| 21 | + POSTGRESQL_PORT_5432_TCP_PORT | |
| 22 | + | |
| 23 | +Its recommended to use an image that allows you to create a database via environmental variables at docker run, like `paintedfox / postgresql` or `centurylink / mysql`, so the db is populated when this script runs. | |
| 24 | + | |
| 25 | +If you do not link a database container, a built-in mysql database will be started. | |
| 26 | +There is an exported docker volume of /var/lib/mysql to allow persistence of that mysql database. | |
| 27 | + | |
| 28 | +Additionally, the database variables may be overridden from the above as per the standard Huginn documentation: | |
| 29 | + | |
| 30 | + DATABASE_ADAPTER #(must be either 'postgres' or 'mysql2') | |
| 31 | + DATABASE_HOST | |
| 32 | + DATABASE_PORT | |
| 33 | + | |
| 34 | +This script will run database migrations (rake db:migrate) which should be idempotent. | |
| 35 | + | |
| 36 | +It will also seed the database (rake db:seed) unless this is defined: | |
| 37 | + | |
| 38 | + DO_NOT_SEED | |
| 39 | + | |
| 40 | +This same seeding initially defines the "admin" user with a default password of "password" as per the standard Huginn documentation. | |
| 41 | + | |
| 42 | +If you do not wish to have the default 6 agents, you will want to set the above environment variable after your initially deploy, otherwise they will be added automatically the next time a container pointing at the database is spun up. | |
| 43 | + | |
| 44 | +The CMD launches Huginn via the scripts/init script. This may become the ENTRYPOINT later. It does take under a minute for Huginn to come up. Use environmental variables that match your DB's creds to ensure it works. | |
| 45 | + | |
| 46 | +## Usage | |
| 47 | + | |
| 48 | +Simple stand-alone usage: | |
| 49 | + | |
| 50 | + docker run -it -p 5000:5000 cantino/huginn | |
| 51 | + | |
| 52 | +To link to another mysql container, for example: | |
| 53 | + | |
| 54 | + docker run --rm --name newcentury_mysql -p 3306 \ | |
| 55 | + -e MYSQL_DATABASE=huginn \ | |
| 56 | + -e MYSQL_USER=huginn \ | |
| 57 | + -e MYSQL_PASSWORD=somethingsecret \ | |
| 58 | + -e MYSQL_ROOT_PASSWORD=somethingevenmoresecret \ | |
| 59 | + cantino/huginn | |
| 60 | + docker run --rm --name huginn --link newcentury_mysql:MYSQL -p 5000:5000 \ | |
| 61 | + -e DATABASE_NAME=huginn \ | |
| 62 | + -e DATABASE_USER=huginn \ | |
| 63 | + -e DATABASE_PASSWORD=somethingsecret \ | |
| 64 | + cantino/huginn | |
| 65 | + | |
| 66 | +To link to another container named 'postgres': | |
| 67 | + | |
| 68 | + docker run --rm --name huginn --link POSTGRES:mysql -p 5000:5000 -e "DATABASE_USER=huginn" -e "DATABASE_PASSWORD=pass@word" cantino/huginn | |
| 69 | + | |
| 70 | +## Environment Variables | |
| 71 | + | |
| 72 | +Other Huginn 12factored environment variables of note, as generated and put into the .env file as per Huginn documentation: | |
| 73 | + | |
| 74 | +    APP_SECRET_TOKEN=${APP_SECRET_TOKEN:-CHANGEME} | |
| 75 | +    DOMAIN=${HUGINN_HOST:-localhost}:${PORT:-5000} | |
| 76 | +    ${ASSET_HOST:+ASSET_HOST=${ASSET_HOST}} | |
| 77 | +    DATABASE_ADAPTER=${DATABASE_ADAPTER:-mysql2} | |
| 78 | +    DATABASE_ENCODING=${DATABASE_ENCODING:-utf8} | |
| 79 | +    DATABASE_RECONNECT=${DATABASE_RECONNECT:-true} | |
| 80 | +    DATABASE_NAME=${DATABASE_NAME:-huginn} | |
| 81 | +    DATABASE_POOL=${DATABASE_POOL:-5} | |
| 82 | +    DATABASE_USERNAME=${DATABASE_USERNAME:-root} | |
| 83 | +    DATABASE_PASSWORD="${DATABASE_PASSWORD}" | |
| 84 | +    DATABASE_PORT=${DATABASE_PORT:-3306} | |
| 85 | +    DATABASE_HOST=${DATABASE_HOST:-localhost} | |
| 86 | +    DATABASE_PORT=${DATABASE_PORT:-3306} | |
| 87 | +    ${DATABASE_SOCKET:+DATABASE_SOCKET=${DATABASE_SOCKET:-/tmp/mysql.sock}} | |
| 88 | +    ${RAILS_ENV:+RAILS_ENV=${RAILS_ENV:-production}} | |
| 89 | +    FORCE_SSL=${FORCE_SSL:-false} | |
| 90 | +    INVITATION_CODE=${INVITATION_CODE:-try-huginn} | |
| 91 | +    SMTP_DOMAIN=${SMTP_DOMAIM=-example.com} | |
| 92 | +    SMTP_USER_NAME=${SMTP_USER_NAME:-you@gmail.com} | |
| 93 | +    SMTP_PASSWORD=${SMTP_PASSWORD:-somepassword} | |
| 94 | +    SMTP_SERVER=${SMTP_SERVER:-smtp.gmail.com} | |
| 95 | +    SMTP_PORT=${SMTP_PORT:-587} | |
| 96 | +    SMTP_AUTHENTICATION=${SMTP_AUTHENTICATION:-plain} | |
| 97 | +    SMTP_ENABLE_STARTTLS_AUTO=${SMTP_ENABLE_STARTTLS_AUTO:-true} | |
| 98 | +    EMAIL_FROM_ADDRESS=${EMAIL_FROM_ADDRESS:-huginn@example.com} | |
| 99 | +    AGENT_LOG_LENGTH=${AGENT_LOG_LENGTH:-200} | |
| 100 | +    AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-your aws access key id}" | |
| 101 | +    AWS_ACCESS_KEY="${AWS_ACCESS_KEY:-your aws access key}" | |
| 102 | +    AWS_SANDBOX=${AWS_SANDBOX:-false} | |
| 103 | +    FARADAY_HTTP_BACKEND=${FARADAY_HTTP_BACKEND:-typhoeus} | |
| 104 | +    DEFAULT_HTTP_USER_AGENT="${DEFAULT_HTTP_USER_AGENT:-Huginn - https://github.com/cantino/huginn}" | |
| 105 | +    ALLOW_JSONPATH_EVAL=${ALLOW_JSONPATH_EVAL:-false} | |
| 106 | +    ENABLE_INSECURE_AGENTS=${ENABLE_INSECURE_AGENTS:-false} | |
| 107 | +    ${USE_GRAPHVIZ_DOT:+USE_GRAPHVIZ_DOT=${USE_GRAPHVIZ_DOT:-dot}} | |
| 108 | +    TIMEZONE="${TIMEZONE:-Pacific Time (US & Canada)}" | |
| 109 | + | |
| 110 | +The defaults used are the Huginn defaults as per the [.env.example](https://github.com/cantino/huginn/blob/master/.env.example) file. | |
| 111 | + | |
| 112 | +## Building on your own | |
| 113 | + | |
| 114 | +You don't need to do this on your own, because there is an [automated build](https://registry.hub.docker.com/u/cantino/huginn/) for this repository, but if you really want: | |
| 115 | + | |
| 116 | +    docker build --rm=true --tag={yourname}/huginn . | |
| 117 | + | |
| 118 | +## Source | |
| 119 | + | |
| 120 | +The source is [available on GitHub](https://github.com/cantino/docker-huginn/). | |
| 121 | + | |
| 122 | +Please feel free to submit pull requests and/or fork at your leisure. | |
| 123 | + | |
| 124 | + | 
| @@ -0,0 +1,136 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +set -e | |
| 3 | + | |
| 4 | +cd /app | |
| 5 | + | |
| 6 | +# is a mysql or postgresql database linked? | |
| 7 | +# requires that the mysql or postgresql containers have exposed | |
| 8 | +# port 3306 and 5432 respectively. | |
| 9 | +if [ -n "${MYSQL_PORT_3306_TCP_ADDR}" ]; then | |
| 10 | +  DATABASE_ADAPTER=${DATABASE_ADAPTER:-mysql2} | |
| 11 | +  DATABASE_HOST=${DATABASE_HOST:-${MYSQL_PORT_3306_TCP_ADDR}} | |
| 12 | +  DATABASE_PORT=${DATABASE_PORT:-${MYSQL_PORT_3306_TCP_PORT}} | |
| 13 | +elif [ -n "${POSTGRESQL_PORT_5432_TCP_ADDR}" ]; then | |
| 14 | +  DATABASE_ADAPTER=${DATABASE_ADAPTER:-postgres} | |
| 15 | +  DATABASE_HOST=${DATABASE_HOST:-${POSTGRESQL_PORT_5432_TCP_ADDR}} | |
| 16 | +  DATABASE_PORT=${DATABASE_PORT:-${POSTGRESQL_PORT_5432_TCP_PORT}} | |
| 17 | +fi | |
| 18 | + | |
| 19 | +cat <<EOF > /app/.env | |
| 20 | +APP_SECRET_TOKEN=${APP_SECRET_TOKEN:-CHANGEME} | |
| 21 | +DOMAIN=${DOMAIN:+${HUGINN_HOST:-localhost}:${PORT:-5000}} | |
| 22 | +${ASSET_HOST:+ASSET_HOST=${ASSET_HOST}} | |
| 23 | +DATABASE_ADAPTER=${DATABASE_ADAPTER:-mysql2} | |
| 24 | +DATABASE_ENCODING=${DATABASE_ENCODING:-utf8} | |
| 25 | +DATABASE_RECONNECT=${DATABASE_RECONNECT:-true} | |
| 26 | +DATABASE_NAME=${DATABASE_NAME:-huginn} | |
| 27 | +DATABASE_POOL=${DATABASE_POOL:-5} | |
| 28 | +DATABASE_USERNAME=${DATABASE_USERNAME:-root} | |
| 29 | +DATABASE_PASSWORD="${DATABASE_PASSWORD}" | |
| 30 | +DATABASE_PORT=${DATABASE_PORT:-3306} | |
| 31 | +DATABASE_HOST=${DATABASE_HOST:-localhost} | |
| 32 | +DATABASE_PORT=${DATABASE_PORT:-3306} | |
| 33 | +${DATABASE_SOCKET:+DATABASE_SOCKET=${DATABASE_SOCKET:-/tmp/mysql.sock}} | |
| 34 | +${RAILS_ENV:+RAILS_ENV=${RAILS_ENV:-production}} | |
| 35 | +FORCE_SSL=${FORCE_SSL:-false} | |
| 36 | +INVITATION_CODE=${INVITATION_CODE:-try-huginn} | |
| 37 | +SMTP_DOMAIN=${SMTP_DOMAIM=-example.com} | |
| 38 | +SMTP_USER_NAME=${SMTP_USER_NAME:-you@gmail.com} | |
| 39 | +SMTP_PASSWORD=${SMTP_PASSWORD:-somepassword} | |
| 40 | +SMTP_SERVER=${SMTP_SERVER:-smtp.gmail.com} | |
| 41 | +SMTP_PORT=${SMTP_PORT:-587} | |
| 42 | +SMTP_AUTHENTICATION=${SMTP_AUTHENTICATION:-plain} | |
| 43 | +SMTP_ENABLE_STARTTLS_AUTO=${SMTP_ENABLE_STARTTLS_AUTO:-true} | |
| 44 | +EMAIL_FROM_ADDRESS=${EMAIL_FROM_ADDRESS:-huginn@example.com} | |
| 45 | +AGENT_LOG_LENGTH=${AGENT_LOG_LENGTH:-200} | |
| 46 | +AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-your aws access key id}" | |
| 47 | +AWS_ACCESS_KEY="${AWS_ACCESS_KEY:-your aws access key}" | |
| 48 | +AWS_SANDBOX=${AWS_SANDBOX:-false} | |
| 49 | +FARADAY_HTTP_BACKEND=${FARADAY_HTTP_BACKEND:-typhoeus} | |
| 50 | +DEFAULT_HTTP_USER_AGENT="${DEFAULT_HTTP_USER_AGENT:-Huginn - https://github.com/cantino/huginn}" | |
| 51 | +ALLOW_JSONPATH_EVAL=${ALLOW_JSONPATH_EVAL:-false} | |
| 52 | +ENABLE_INSECURE_AGENTS=${ENABLE_INSECURE_AGENTS:-false} | |
| 53 | +${USE_GRAPHVIZ_DOT:+USE_GRAPHVIZ_DOT=${USE_GRAPHVIZ_DOT:-dot}} | |
| 54 | +TIMEZONE="${TIMEZONE:-Pacific Time (US & Canada)}" | |
| 55 | +EOF | |
| 56 | +chmod ugo+r /app/.env | |
| 57 | +source /app/.env | |
| 58 | + | |
| 59 | +# use default port number if it is still not set | |
| 60 | +case "${DATABASE_ADAPTER}" in | |
| 61 | +  mysql2) DATABASE_PORT=${DATABASE_PORT:-3306} ;; | |
| 62 | +  postgres) DATABASE_PORT=${DATABASE_PORT:-5432} ;; | |
| 63 | + *) echo "Unsupported database adapter. Available adapters are mysql2, and postgres." && exit 1 ;; | |
| 64 | +esac | |
| 65 | + | |
| 66 | +# start supervisord | |
| 67 | +/usr/bin/supervisord -c /etc/supervisor/supervisord.conf | |
| 68 | + | |
| 69 | +# start mysql server if ${DATABASE_HOST} is localhost | |
| 70 | +if [ "${DATABASE_HOST}" == "localhost" ]; then | |
| 71 | +  if [ "${DATABASE_ADAPTER}" == "postgres" ]; then | |
| 72 | + echo "DATABASE_ADAPTER 'postgres' is not supported internally. Please provide DATABASE_HOST." | |
| 73 | + exit 1 | |
| 74 | + fi | |
| 75 | + | |
| 76 | + # configure supervisord to start mysql (manual) | |
| 77 | + cat > /etc/supervisor/conf.d/mysqld.conf <<EOF | |
| 78 | +[program:mysqld] | |
| 79 | +priority=20 | |
| 80 | +directory=/tmp | |
| 81 | +command=/usr/bin/mysqld_safe | |
| 82 | +user=root | |
| 83 | +autostart=false | |
| 84 | +autorestart=true | |
| 85 | +stdout_logfile=/var/log/supervisor/%(program_name)s.log | |
| 86 | +stderr_logfile=/var/log/supervisor/%(program_name)s.log | |
| 87 | +EOF | |
| 88 | + supervisorctl reload | |
| 89 | + | |
| 90 | + # fix permissions and ownership of /var/lib/mysql | |
| 91 | + chown -R mysql:mysql /var/lib/mysql | |
| 92 | + chmod 700 /var/lib/mysql | |
| 93 | + | |
| 94 | + # initialize MySQL data directory | |
| 95 | + if [ ! -d /var/lib/mysql/mysql ]; then | |
| 96 | + mysql_install_db --user=mysql | |
| 97 | + fi | |
| 98 | + | |
| 99 | + echo "Starting mysql server..." | |
| 100 | + supervisorctl start mysqld >/dev/null | |
| 101 | + | |
| 102 | + # wait for mysql server to start (max 120 seconds) | |
| 103 | + timeout=120 | |
| 104 | +  while ! mysqladmin -uroot ${DATABASE_PASSWORD:+-p$DATABASE_PASSWORD} status >/dev/null 2>&1 | |
| 105 | + do | |
| 106 | + timeout=$(expr $timeout - 1) | |
| 107 | + if [ $timeout -eq 0 ]; then | |
| 108 | + echo "Failed to start mysql server" | |
| 109 | + exit 1 | |
| 110 | + fi | |
| 111 | + sleep 1 | |
| 112 | + done | |
| 113 | + | |
| 114 | +  if ! echo "USE ${DATABASE_NAME}" | mysql -uroot ${DATABASE_PASSWORD:+-p$DATABASE_PASSWORD} >/dev/null 2>&1; then | |
| 115 | + DB_INIT="yes" | |
| 116 | +    echo "CREATE DATABASE IF NOT EXISTS \`${DATABASE_NAME}\` DEFAULT CHARACTER SET \`utf8\` COLLATE \`utf8_unicode_ci\`;" | mysql -uroot ${DATABASE_PASSWORD:+-p$DATABASE_PASSWORD} | |
| 117 | +    echo "GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON \`${DATABASE_NAME}\`.* TO 'root'@'localhost';" | mysql -uroot ${DATABASE_PASSWORD:+-p$DATABASE_PASSWORD} | |
| 118 | + fi | |
| 119 | +fi | |
| 120 | + | |
| 121 | +# Assuming we have a created database, run the migrations and seed it idempotently. | |
| 122 | +[ -z "${DO_NOT_MIGRATE}" ] && sudo -u huginn -EH bundle exec rake db:migrate | |
| 123 | +[ -z "${DO_NOT_SEED}" ] && sudo -u huginn -EH bundle exec rake db:seed | |
| 124 | + | |
| 125 | +[ -n "$INTENTIONALLY_SLEEP" ] && sleep $INTENTIONALLY_SLEEP | |
| 126 | + | |
| 127 | +# Fixup the Procfile and prepare the PORT | |
| 128 | +[ -z "${DO_NOT_RUN_JOBS}" ] && perl -pi -e 's/^jobs:/#jobs:/' /app/Procfile | |
| 129 | +perl -pi -e 's/rails server$/rails server -p \$PORT/' /app/Procfile | |
| 130 | +export PORT | |
| 131 | + | |
| 132 | +# Start huginn | |
| 133 | +sudo -u huginn -EH bundle exec foreman start | |
| 134 | + | |
| 135 | +# As the ENTRYPOINT script, when this exits the docker container will Exit. | |
| 136 | +exit 0 | 
| @@ -0,0 +1,39 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +set -e | |
| 3 | + | |
| 4 | +# Initialize variables used by Huginn at installation time | |
| 5 | + | |
| 6 | +# Huginn is 12factor aware, embrace that fact for use inside of docker | |
| 7 | +ON_HEROKU=${ON_HEROKU:-true} | |
| 8 | + | |
| 9 | +# Shallow clone the huginn project repo | |
| 10 | +git clone --depth 1 https://github.com/cantino/huginn /app | |
| 11 | + | |
| 12 | +cd /app | |
| 13 | + | |
| 14 | +# add a huginn group and user | |
| 15 | +adduser --group huginn | |
| 16 | +adduser --disabled-login --ingroup huginn --gecos 'Huginn' --no-create-home --home /app huginn | |
| 17 | +adduser huginn sudo | |
| 18 | +passwd -d huginn | |
| 19 | + | |
| 20 | +# Change the ownership to huginn | |
| 21 | +chown -R huginn:huginn /app | |
| 22 | + | |
| 23 | +# create required tmp and log directories | |
| 24 | +sudo -u huginn -H mkdir -p tmp/pids tmp/cache tmp/sockets log | |
| 25 | +chmod -R u+rwX log tmp | |
| 26 | + | |
| 27 | +# install gems required by Huginn, use local cache if available | |
| 28 | +if [ -d "/scripts/cache" ]; then | |
| 29 | + mv /scripts/cache vendor/ | |
| 30 | + chown -R huginn:huginn vendor/cache | |
| 31 | +fi | |
| 32 | +sudo -u huginn -H bundle install --deployment --without development test | |
| 33 | + | |
| 34 | +# silence setlocale message (THANKS DEBIAN!) | |
| 35 | +cat > /etc/default/locale <<EOF | |
| 36 | +LC_ALL=en_US.UTF-8 | |
| 37 | +LANG=en_US.UTF-8 | |
| 38 | +EOF | |
| 39 | + |