Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

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- | sudo bash

Config dokku

$ cat ~/.ssh/ | ssh root@ "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:

cd /var/lib/dokku/plugins
git clone 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

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:

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


Config Nginx

location / {
  proxy_pass        http://localhost:49153;
  proxy_set_header  X-Real-IP  $remote_addr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment