Reliably Deploying Rails Applications cover page
Reliably Deploying Rails Applications


Buy Now

Formats Included

Reliably Deploying Rails Applications

Hassle free provisioning, reliable deployment

A robust framework for provisioning servers with Chef and deploying reliably with Capistrano 3, including example code templates you can use directly.

Reliably Deploying Rails Applications cover page Edit
This book is 90% Complete


Buy Now

Free sample


Buy A Bundle And Save

About the Book

Mastering Rails application deployment

This book will show you from start to finish how to:

  • Setup a VPS from Scratch
  • Setup additional servers in minutes
  • Use Capistrano 3 to deploy quickly and reliably
  • Automate boring maintenance tasks

If you've got applications on Heroku which are costing you a fortune, this will provide you with the tools you need to move them onto a VPS. This includes running several Rails Applications on a single VPS - great for small side projects.

If you're already running your app on a VPS but the deploy process is flaky - it sometimes doesn't restart or loads the wrong version of the code - this book provides a template for making the process hassle free.

Section 1: Chef

How to automate provisioning new servers with chef. By the end you'll be able to get a new server up and ready to use within minutes.

Many standard Rails system configurations are supported out of the box with the example code (MySQL, PostgreSQL, MongoDB and Redis). For anything else, detailed instructions for setting up your own custom configurations and writing your own chef recipes are provided. 

The aim of this section is to build a re-usable blueprint you can use whenever you need to setup a new VPS.

Section 2: Capistrano 3

Using Capistrano 3 to automate every aspect of deployment, from updating code to managing assets and background workers.

Particular attention is paid to setting up zero downtime deployment - essential if you're iterating rapidly and want to deploy several times per day. This includes a section on common gotchas such as failing to reload the gemfile on deployment as well as a detailed guide to troubleshooting when it goes wrong.

I've spent hundreds of hours combing through blog posts, documentation and tweaking config files. This has got me to the stage where deploying to a VPS is as easy as - in fact often easier than - deploying to Heroku. If you want to do the same, this book will save you a lot of time.

Current Completion & Feedback

The first section - provisioning a server with chef - is complete, including instructions for PostgreSQL, MySQL and MongoDB. This includes a "Five minute VPS" quickstart section for the impatient.

The second section - deploying with Capistrano 3 - is also complete and includes all the information needed to get zero downtime deployments working with Rails 3/4 and Unicorn. As well as detailed sample code, it includes complete instructions for deploying Sidekiq workers, a detailed section on Configuring Zero Downtime deployment and instructions for configuring NGinx Virtualhosts and SSL. Finally it covers how to setup automated database backups and how to use Vagrant for testing.

The book is continuously updated as and when there are significant changes to Capistrano, Chef and other system components. 

Any feedback on content, structure or corrections very gratefully received, you can get me on twitter (@talkingquickly) or by emailing ben@talkingquickly.co.uk

  • 1 Translation
  • Feedback
  • Share this book

Table of Contents

  • 1.0 - Intro
    • The purpose of this book
    • About Me
    • Why This Book Exists
    • Intended Audience
    • Pre-requisites
    • How to read this book
    • Structure of Part 1 - Setting up the server
    • Structure of Part 2 - Deploying to the server
    • Version
  • 2.0 - The Stack
    • Overview
    • Ubuntu 14.04 LTS
    • Nginx
    • Unicorn
    • Postgresql / MongoDB / MySQL
    • Ruby (rbenv)
    • Redis
    • Memcached
    • Why This Stack
    • Adapting to your stack
  • 3.0 - Chef Definitions
    • Introduction
    • Automation
    • The Tools for automating provisioning
  • 4.0 Quick Start
    • Overview
    • The Stack
    • STeps
    • Provisioning the Server
    • Next Steps
  • 5.0 - Anatomy of a chef solo project
    • Overview
    • Creating a project
    • Setting up a node
    • Conclusion
  • 5.1 - Creating a Chef Cookbook
    • Overview
    • Generating a Cookbook
    • Structure of a Cookbook
    • Installing Redis Manually
    • Converting this into a simple Chef Cookbook
    • Adding the recipe to the node definition
    • Applying the updated node definition
    • Is This Cookbook “Bad” or “Wrong”
    • Limitations of the simple Cookbook
    • Improving our Cookbook the Chef Way
    • Updating The Node
    • Adding flexibility with attributes
    • Conclusion
  • 5.2 - Node and Role Definitions
    • Overview
    • Attribute Heirachy
    • Node Definitions
    • Role Definitions
    • Breaking a System Into Roles
    • Limitations of Roles
  • 6.0 - A Template for Rails Servers
    • Overview
    • The Example Configuration
  • 6.1 - Managing Cookbooks with Berkshelf
    • Overview
    • How Berkshelf works with knife solo
    • Getting Started
  • 7.0 - Basic Server Setup
    • Overview
    • Useful Tools
    • Unattended Upgrades
    • Automatic System Time via NTP
    • Locales
  • 8.0 - Security
    • Overview
    • No One Size Fits All
    • Common Pitfalls
    • SSH Hardening
    • Firewall
    • Users
    • Sudo
  • 9.0 - Rails Server Setup
    • Overview
    • Rbenv v RVM
    • How rbenv works
    • The rbenv Cookbook
    • Gem Dependencies
  • 10.0 - Monit
    • Which configuration goes where
    • The importance of a custom monitoring configuration
    • System level monitoring
    • Monitoring Pids
    • Monitoring Ports
    • Free Space Monitoring
    • Alerts and avoiding overload
    • Serving the web interface with Nginx
  • 11.0 - Nginx
    • Overview
    • Why Nginx
    • The Cookbook
    • Virtualhosts
    • Monitoring
  • 12 - PostgreSQL
    • Overview
    • Installation
    • Accessing the psql console
    • Creating Databases
    • Adding users to Databases
    • Listing all databases and permissions
    • Configuring Authentication
    • Allow External Access
    • Mangaging pg_hba.conf with chef
    • Importing and Exporting Databases
    • Monit
  • 13 - MySQL
    • Overview
    • Installation
    • Creating Databases
    • Configuring Authentication
    • Importing and Exporting Databases
    • Monit
    • Server Admin
  • 14 - Mongo
    • Overview
    • The cookbook
    • Monitoring
  • 15.0 - Redis and Memcached
    • Redis
    • Memcached
    • Conclusion
  • 16.0 Capistrano Quickstart
    • Overview
    • Steps
    • Copying configuration
    • Conclusion
  • 16.1 Deploying with Capistrano
    • Overview
    • Capistrano
    • Capistrano 2 or 3
    • Stages
    • Upgrading from V2
    • Adding Capistrano to an application
    • Installation
    • Capistrano 3 is Rake
    • The Capfile
    • Common configuration
    • Running tests
    • Hooks
    • Setting up stages
    • Generating Remote Configuration Files
    • Database Credentials
    • Deploying
    • Conclusion
  • 16.2 Writing Custom Capistrano Tasks
    • Overview
    • File Structure
    • The Task
    • A note on Namespacing
  • 17.0 - Unicorn Configuration and Zero Downtime Deployment
    • Overview
    • Unicorn and the request flow
    • Basic Configuration
    • Unix Signals
    • Init script
    • Zero Downtime Deployment
    • Gemfile Reloading
    • Troubleshooting Process for Zero Downtime Deployment
  • 18.0 Nginx Virtualhosts and SSL
    • Overview
    • A Basic Virtualhost
    • DNS Overview
    • Forcing HTTPS
    • Adding SSL
    • Chaining SSL Certificates
    • Updating SSL Certificates
  • 19.0 - Sidekiq
    • Overview
    • Sidekiq Version 3
    • Capistrano Integration
  • 20.0 Backups
    • Overview
    • Structure
    • Getting Started
    • Triggering Backups with Whenever
    • Conclusion
  • 21.0 Testing with Vagrant
    • Overview
    • Getting Setup
    • SSHing in directly
    • Testing chef cookbooks
    • Users, Sudo and Root
    • Port Forwarding

About the Author

Currently based between Google Campus, London, I've been developing web applications for over eight years. Over the last few years specialising in Ruby on Rails development and deployment. I work both as a consultant - primarily to startups - and on projects of my own. I spoke at Railsconf Chicago in 2014 on the topic of deploying Rails applications with Chef and Capistrano 3.

I'm the technical lead at a health and fitness startup who provide the timetabling for many of the UK's public leisure operators as well as producing an international iOS app (Speedo Fit) for swimmers sponsored by a major global fitness brand.

As part of developing the infrastucture for this I've dealt with everything from the usual rapid growth from 10's of requests per minute to 10's per second to more unusual challenges such as expanding infrastructure into China and dealing with obscure MongoDB indexing issues.

The Leanpub Unconditional, No Risk, 100% Happiness Guarantee

Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks. We process the refunds manually, so they may take a few days to show up.
See full terms.