Deploy your Rails App

Replacing Heroku

What is Heroku?

  • heroku login

  • heroku create

  • git push heroku master

A service for deploying applications

What Chris Says

"Nothing sweeter than git push production master"

How this works

  • git hook
    • post-receive hook
  • script that completes tasks

Getting started

Begin a Rails app

gem install rails && rbenv rehash
rails new jokes && cd jokes
bundle exec rails generate scaffold Joke joke:string punchline:string
bundle exec rake db:migrate

Quick configuration

  • config/routes
Rails.application.routes.draw do
  resources :jokes
  root to: 'jokes#index'
  • Gemfile
gem 'therubyracer', platforms: :ruby

Create the Droplet

  • Visit
  • "Log In"
  • "Create Droplet"
    • Ubuntu 14.04.4 x64
    • $5/mo
    • New York 3
    • Add your SSH key
    • Choose a hostname

Prepare our server

  • ssh root@XXX.XXX.XXX.XXX
  • Install packages
apt-get update
apt-get install git-core curl zlib1g-dev build-essential libssl-dev
libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev
libcurl4-openssl-dev python-software-properties libffi-dev
  • Create a user
useradd -m app
chsh app -s /bin/bash

Install Ruby

  • sudo su - app
  • Install rbenv
git clone ~/.rbenv
git clone ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
  • Install and use Ruby
rbenv install 2.3.0
rbenv global 2.3.0
gem install bundler

Let's Deploy

Setup a middleware for app

  • Update the Gemfile
group :production do
  gem 'puma'

Setup a middleware for server

  • Retrieve suggested Puma configuration
  • Update puma.conf
setuid app
setgid app
  • Add configuration to Bash execution

Server middleware (continued)

  • Deploy startup files
sudo cp puma.conf puma-manager.conf /etc/init
  • Configure Puma (/etc/puma.conf)



Run a web server

  • Install nginx
apt-get install nginx

Special sauce

Setup git remote

  • Setup the repository
sudo su - app && cd
mkdir ~/jokes-production && cd ~/jokes-production
git init --bare
  • Add the Hook!
    • ~/jokes-production/hooks/post-receive
    • post-receive from
    • chmod +x hooks/post-receive
  • Setup sudo
sudo sh -c 'echo "app ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-app'


Hit that deploy button

  • Add your server as a remote
git remote add production
  • And, as Chris says
    • "there's nothing sweeter than"
git push production master


Deploy your Rails App

By Andrew Tomaka

Deploy your Rails App

Replacing Heroku

  • 819