This is an Ansible playbook to setup Dokku environment for production and test
-
Install Brew, Python and pip
-
Install Brew Cask
brew install cask
-
Download and install Ansible
pip install ansible
-
Clone this repo
git clone https://github.com/beedesk/deploy.git
-
Follow the step of "Environment Basic" (see above)
-
Install vagrant and setup environment
# Uses sudo or -K option # For verbose output use `-v` option. ansible-playbook setup_localhost.yml --connection=local -K
-
Run Vagrant
vagrant up # Note: # Vagrant will set up new VM for you and apply to it `setup_dokku.yml`, that will # set up dokku into VM. # If something goes wrong you can reapply `setup_dokku.yml` with command: # $ vagrant provision
-
Open dokku in browser and finish setup
-
Create and deploy project to test
Open project.yml
with text redactor and fill variables:
$ nano project.yml
vars:
backup_dir: /home/dokku/backup
backup_s3_bucket: backup
alert_command: "curl -fsS --retry 3 https://hchk.io/3d82de35-bce7-449d-8d54-274eae59d7f2 > /dev/null"
projects:
- {name: python-getting-started, url: "git@github.com:heroku/python-getting-started.git", dbname: python, env: [key=value, foo=bar]}
- {name: ruby-rails-sample, url: "git@github.com:heroku/ruby-rails-sample.git", dbname: ruby, env: [key=value, foo=bar]}
Then execute Ansible
ansible-playbook -i test_hosts project.yml
# warning: check ~/.ssh/known_hosts and remove dokku.me entry, if you got SSH UNREACHABLE problem
-
Follow the step of "Environment Basic" (see above)
-
Create a hosts file with
[dokku]
sectionvi prod_hosts
The hosts file should look like this:
[dokku] aws.ip.address ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/test-ansible.pem.txt [dokku:vars] git_remote_name=production
-
Setup production hosts
ansible-playbook -i prod_hosts setup_dokku.yml
-
Connect to your host in browser and finish dokku setup
-
Create and deploy project to prod
$ ansible-playbook -i prod_hosts project.yml
Here is what each of the steps above does:
setup_localhost.yml will:
- install vagrant and virtualbox (step 1)
- set ip in Vagrantfile, test_hosts and /etc/hosts (step 3)
- run vagrant up that triggered dokku.yml
- add ssh keys (step 3)
setup_dokku.yml will:
- set swap with roles/swap
- install dokku + plugins with roles/dokku (apt only install) (step 2, 4)
project.yml will:
- checkout given project to
apps
directory - create database per project (step 5, 6)
- create and push given project (step 7)
-
Download and Install Vagrant
- a. Create a new folder << vagrant folder >> (such as
ubuntu-docker
) cd << vagrant folder >>
vagrant init ubuntu/trusty64
vi VagrantFile
- Pick an IP address for Vagrant (such as 10.88.0.8)
- change line
config.vm.network "private_network", ip: "<< ip address >>"
vagrant up
- a. Create a new folder << vagrant folder >> (such as
-
Install Docker and Dokku
vagrant ssh
apt-get update
apt-get install git lxc-docker daemontools build-essential libtool
- Install dokku: (needed to run it twice last time, maybe a transient problem)
- cd && wget https://raw.github.com/progrium/dokku/v0.3.26/bootstrap.sh && sudo DOKKU_TAG=v0.3.26 bash bootstrap.sh
- Increase swap space (http://stackoverflow.com/a/17174672):
sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 && sudo mkswap /swapfile && sudo swapon /swapfile
- Enable swap at boot: add this line to
/etc/fstab
/swapfile swap swap defaults 0 0
-
Config host machine 7. Exit vagrant ssh shell 8. Edit
/etc/hosts
to add line: * << ip address >> dokku.me 9.cat ~/.ssh/id_rsa.pub | vagrant ssh dokku.me "sudo sshcommand acl-add dokku $USER"
* (reference: https://github.com/progrium/dokku/blob/master/docs/installation.md) * (for AWS test machine, do this:cat ~/.ssh/id_rsa.pub | ssh -i file.pem.txt ubuntu@<< aws public ip >>.amazonaws.com "sudo sshcommand acl-add dokku $USER"
) -
Install plugins
- log into vagrant
vagrant ssh
- create a sub directory for
plugins
:mkdir /var/etc/lib/dokku-plugins
cd /var/etc/lib/dokku-plugins
git clone https://github.com/ohardy/dokku-mariadb.git
git clone https://github.com/ohardy/dokku-psql.git
cd /var/etc/lib/dokku/plugins
ln -s /var/etc/lib/dokku-plugins/dokku-mariadb.git
ln -s /var/etc/lib/dokku-plugins/dokku-psql.git
sudo dokku plugins:install
- log into vagrant
-
Create a MariaDB "project" 1.
-
Update MySQL
FLUSH TABLES WITH READ LOCK; FLUSH LOGS; SET GLOBAL binlog_format = 'MIXED'; FLUSH LOGS; UNLOCK TABLES; # http://dba.stackexchange.com/a/6753
-
Create a project and push
- export $APP_NAME=<< app name >>
dokku app:create $APP_NAME
- Add an alias and source it
- Add this line to ~/.bash_profile:
alias dokkudev='ssh -t dokku@dokku.me'
- Source ~/.bash_profile:
source ~/.bash_profile
4a.dokku config:set $APP_NAME KEY_1=VALUE_1 [KEY_2=VALUE_2] ...
4b. Or, ssh into vagrantcd << vagrant folder >> && vagrant ssh
- And, edit
~dokku/<< app name >>ENV
directly - ** remember to include
export
in front of each lines - ** do not include any commented line (it will fail subsequence deploy)
dokkudev apps:restart $APP_NAME
# to cause config reload
- Add this line to ~/.bash_profile:
git remote add dokkudev dokku@dokku.me:$APP_NAME
git push dokkudev master
dokkudev logs $APP_NAME
- If error arise:
setuidgid: fatal: unable to run failure
, do step 2.5 ('daemontools')