Skip to content

Instantly share code, notes, and snippets.

@karimmtarek
Forked from joshteng/dokku_setup.md
Created May 21, 2016 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karimmtarek/044fbb5805deb962e351d4a22898a37c to your computer and use it in GitHub Desktop.
Save karimmtarek/044fbb5805deb962e351d4a22898a37c to your computer and use it in GitHub Desktop.
Using Dokku to deploy a Rails Application

#Goal Deploy your Rails App super easily with Dokku on Digital Ocean cheap cheap!

##Notes

  • Follow 12 factor design (include the rails_12factor gem)
  • Don't forget your Procfile with the command to start up your application server
  • I prefer using external hosted logging services like Logentries (not in this guide)
  • Set up performance monitoring AppSignal or New Relic (not in this guide)

##step 1 at digitalocean.com
Spin up a new VPS with Dokku (from experience, I suggest using at least 1GB if you are running both your database and application servers in one Droplet or you run out of memory pretty soon!)

##step 2 tunneled into server
SSH into your server and run apt-get update

##step 3 tunneled into server

  1. add postgres with following this guide: https://github.com/Kloadut/dokku-pg-plugin
  2. run dokku plugins-install if you haven't already
    *if there're issues while trying to install plugins because of some nginx errors, uninstall nginx apt-get remove nginx and reinstall apt-get install nginx (or any other package for that matter)

##step 4 tunneled into server except # 2 done locally in your application codebase

  1. create database dokku postgresql:create <app_name>
  2. change database.yml to use url environment variable url: <%= ENV['DATABASE_URL'] %>
  3. run dokku postgresql:link <app_name> <database_name> (this will link the postgres running on one docker container with my rails app in another docker container by simply configuring the env variable).

##step 5 in browser

  1. go to server IP address in browser and set SSH key and app naming url

##step 6 done in your local console

  1. add dokku as git remote (use ip address if don't want to set root domain as A record) git remote add dokku dokku@<your_ip_address_or_root_domain>:<app_name> see instructions if having trouble: https://github.com/progrium/dokku
  2. cat ~/.ssh/id_rsa.pub | ssh root@<your_ip_address> "sudo sshcommand acl-add dokku dokku"
  3. git push dokku master

##step 7 tunneled into server
On the server, run:

dokku run <app_name> rake db:migrate
dokku run <app_name> rake db:seed
dokku config:set <app_name> SOME_VARIABLE=SOMEVALUE ANOTHER_VARIABLE=ANOTHER_VALUE

https://github.com/progrium/dokku#environment-variable-management

##step 8 in browser

  1. point your subdomain to your Droplet (VPS)'s IP address (DNS A Record)! (you can choose to point your root domain to your server as well. I don't do this because I usually run my applications on a subdomain and a regular HTML info site on the root domain)
  2. test in browser! <app_name>.rootdomain.com

##Reference

##Questions I have I'm pretty new to DevOps and stuff (thanks to Heroku).
I've deployed Wordpress apps in the past and used Monit to monitor my daemon processes such as MySQL and Apache.
How would you do it with Docker? If you know something this please leave a comment below!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment