Skip to content

Instantly share code, notes, and snippets.

@Nilloc
Last active March 14, 2016 19:00
Show Gist options
  • Save Nilloc/13e5c599596c49d4bf86 to your computer and use it in GitHub Desktop.
Save Nilloc/13e5c599596c49d4bf86 to your computer and use it in GitHub Desktop.

Setup Dokku Rails 3.2+ app on Digital Ocean

Setting up new Dokku Droplet

Visit IP of new droplet and add credentials

For dokku instructions:
http://dokku.viewdocs.io/dokku/application-deployment

DNS Settings

yourdomain.com

Type Name Address
A @ X.X.X.X
A pop X.X.X.X
A mail X.X.X.X
A * X.X.X.X
MX 1 aspmx.l.google.com.
MX 5 alt1.aspmx.l.google.com.
MX 5 alt2.aspmx.l.google.com.
MX 10 alt3.aspmx.l.google.com.
MX 10 alt4.aspmx.l.google.com.
NS - ns1.digitalocean.com.
NS - ns2.digitalocean.com.
NS - ns3.digitalocean.com.

Adding Swap Space Dokku Droplet

To setup swapfile space

~# sudo fallocate -l 4G /swapfile
~# ls -lh /swapfile
> -rw-r--r-- 1 root root 4.0G Apr 28 17:19 /swapfile
~# sudo chmod 600 /swapfile
~# sudo mkswap /swapfile   # create swap
~# sudo swapon /swapfile   # activate
~# sudo swapon -s          # verify
~# free -m                 # corroborate

To make it perminent

  1. ~# sudo nano /etc/fstab
  2. then add a new line with /swapfile none swap sw 0 0
  3. save & exit

To tweak the swappiness

~# cat /proc/sys/vm/swappiness
> 60
~# sudo sysctl vm.swappiness=10
  1. ~# sudo nano /etc/sysctl.conf
  2. add a new line with vm.swappiness=10 to the end
  3. save & exit

Source

Creating a new Dokku app

  1. ~# dokku apps:create <app>
  2. ~# postgres:create <name>
  3. ~# postgres:link <name> <app>
  4. deploy with $ git push master production

Setting up Dokku/Docker Persistant Storage

Confirm rails app path:

~# dokku run app_name rails c
> Rails.root.to_s

The path is most likely to be /app

To add Persistant Storage:

~# mkdir -p /home/uploads/<app>
~# chown -R /home/uploads # (this may be uneeded)
~# dokku docker-options:add <app> run,deploy "-v /home/uploads/<app>:/app/public/projects/images"

To check the Docker Persistant Storage:

~# sudo docker ps
~# sudo docker inspect (app_image_NAME)

- Credit

Increase the max file size allowed:

  1. ~# pico /home/dokku/<app>/nginx.conf
  2. add client_max_body_size 20M; line to the server scope.

Running Migrations

~# dokku run <app> "rake db:migrate"

Keeping Ubuntu up-to-date

~# sudo apt-get update # gets list of updates
~# sudo apt-get upgrade # installs available updates but doesn't update dependencies

$ sudo apt-get dist-upgrade I don't use this because it sounds riskier

Viewing Logs (Remotely)

Continous logs

$ ssh root@address dokku logs <app> -t

One-time logs printout

$ ssh root@address dokku logs <app>

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