Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save seanwash/2128a9da945ae5379bb5 to your computer and use it in GitHub Desktop.
Save seanwash/2128a9da945ae5379bb5 to your computer and use it in GitHub Desktop.
Deploy Rails 4 app with Dokku on DigitalOcean

Deploy Rails 4 app with Dokku on DigitalOcean

Install dokku

First create a Ubuntu 13.04 x64 droplet on DigitalOcean Control Panel

Then ssh with root account, run this in termianl:

$ wget -qO- https://raw.github.com/progrium/dokku/master/bootstrap.sh | sudo bash

Config dokku

$ cat ~/.ssh/id_rsa.pub | ssh [email protected] "gitreceive upload-key dokku"

$ git remote add dokku git@[SERVER_IP_ADDRESS]:[APP_NAME]

Deploy Rails app

Add gem 'rails_12factor' to Gemfile

Then install dokku PG plugin: https://github.com/Kloadut/dokku-pg-plugin

cd /var/lib/dokku/plugins
git clone https://github.com/Kloadut/dokku-pg-plugin postgresql
dokku plugins-install

Create app database

root@mg-dokku:~# dokku postgresql:create [APP_NAME]

Then $ git push dokku master to deploy.

When it finished, run $ docker ps -a to show status:

root@mg-dokku:~# docker ps -a
ID                  IMAGE                  COMMAND                CREATED             STATUS              PORTS
290ae95c5ae7        app/mg:latest          /bin/bash -c /start    3 minutes ago       Up 3 minutes        49153->49153
1b79bc29ae77        postgresql/mg:latest   /usr/bin/start_pgsql   6 minutes ago       Up 6 minutes        49156->5432
root@mg-dokku:~#

But we have not run database migrations yet. Let's do it:

root@mg-dokku:~# docker run -i -t app/mg /bin/bash
root@085f103bec8a:/# cd app/
root@085f103bec8a:/app# RAILS_ENV=production rake db:migrate
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

It fails, we try another way:

root@mg-dokku:~# docker run app/mg /bin/bash -c "cd /app ; rake db:migrate"
rake aborted!
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0

Fails too. :(

Here's a workaround: dokku/dokku#156 (comment)

root@085f103bec8a:/app# export HOME=/app
root@085f103bec8a:~# for file in /app/.profile.d/*; do source $file; done
root@085f103bec8a:~# hash -r
root@085f103bec8a:~# cd /app
root@085f103bec8a:~# RAILS_ENV=production rake db:migrate
==  DeviseCreateAdmins: migrating =============================================
-- create_table(:admins)
   -> 0.0125s
-- add_index(:admins, :email, {:unique=>true})
   -> 0.0034s
-- add_index(:admins, :reset_password_token, {:unique=>true})
   -> 0.0039s
==  DeviseCreateAdmins: migrated (0.0229s) ====================================

==  CreateCustomers: migrating ================================================
-- create_table(:customers)
   -> 0.0079s
==  CreateCustomers: migrated (0.0087s) =======================================

==  AddDeviceTypeToCustomers: migrating =======================================
-- add_column(:customers, :device_type, :string, {:default=>""})
   -> 0.0068s
==  AddDeviceTypeToCustomers: migrated (0.0075s) ==============================

Then visit http://[SERVER_IP_ADDRESS]:49153

Yeah!

Config Nginx

http://wiki.nginx.org/HttpProxyModule

location / {
  proxy_pass        http://localhost:49153;
  proxy_set_header  X-Real-IP  $remote_addr;
}
@seanwash
Copy link
Author

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