Skip to content

Instantly share code, notes, and snippets.

@hiasinho
Last active January 26, 2017 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiasinho/8b23901b229d0ce4a8bb to your computer and use it in GitHub Desktop.
Save hiasinho/8b23901b229d0ce4a8bb to your computer and use it in GitHub Desktop.
DigitalOcean, Dokku, Rails, PostgreSQL

Instructions

References:

Prepare Dokku server and client

  1. Create a new Droplet on DigitalOcean
  • Name the Droplet after your Domain (yourdomain.com)
  • Choose Applications -> Dokku
  • Create Droplet
  1. Access Dokku setup using the Server IP in the Browser
  • ssh key is already filled in
  • Configure the hostname (yourdomain.com)
  • Check "Use virtualhost naming for apps"
  • Finish Setup
  1. Install PostgreSQL on Dokku Server
  • SSH to the server
  • cd /var/lib/dokku/plugins
  • git clone https://github.com/Kloadut/dokku-pg-plugin.git postgresql
  • dokku plugins-install
  1. Install Dokku client on dev machine
  • git clone git@github.com:progrium/dokku.git ~/.dokku
  • Add to .zshrv alias dokku='$HOME/.dokku/contrib/dokku_client.sh'
  • Add the following to ~/.ssh/config:
Host <yourdomain.com>
RequestTTY yes

Optional: Add swap

If you use a small instance type, add some swap to your server see docs

  1. (Optional) Add swap
  • System has swap? sudo swapon -s or free -m
  • Check disk space df -h
  • sudo fallocate -l 4G /swapfile
  • Check if correct ls -lh /swapfile
  • Secure swap file sudo chmod 600 /swapfile
  • Verify swap file ls -lh /swapfile
  • Set up swap sudo mkswap /swapfile
  • Enable swap sudo swapon /swapfile
  • System has swap? sudo swapon -s or free -m
  1. (Optional) Make swap permanent
  • sudo vim /etc/fstab
  • At bottom, add /swapfile none swap sw 0 0
  1. (Optional) Tweak swap settings
  • Check swapiness cat /proc/sys/vm/swappiness
  • For a Desktop, a swappiness setting of 60 is not a bad value. For a VPS system, we'd probably want to move it closer to 0
  • Set swapiness temp: sudo sysctl vm.swappiness=10
  • Set swapiness perm: sudo vim /etc/sysctl.conf and add vm.swappiness=10
  • Check vfs_cache_pressure: cat /proc/sys/vm/vfs_cache_pressure == 100
  • Set cache temp: sudo sysctl vm.vfs_cache_pressure=50
  • Set cache perm: sudo vim /etc/sysctl.conf and add vm.vfs_cache_pressure = 50

Rails App

  1. Create a new rails app and cd into the directory
  2. Initialize git and do first commit git init && git add . && git commit -am 'First commit'
  3. Add remote git remote add dokku dokku@yourdomain.com:<app_name>
  4. dokku postgresql:create <app_name> (must be the app name)
  5. dokku postgresql:link <app_name> <app_name>
  6. Push it git push dokku master
  7. dokku run rake db:migrate
  8. dokku url

Problems

rails-assets.org not working

Create a .env file and add at least export BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-ruby

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