Leanpub Header

Skip to main content

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.

Minimum price

$20.00

$30.00

You pay

$30.00

Author earns

$24.00
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
1,129
Readers
About

About

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

This is the fifth edition of this book, updated April 2021 and using current releases of Chef, Capistrano, Rails and Sidekiq as well as Ubuntu 20.04 LTS.

The fifth edition is currently in progress, with the core path of setting up a server and deploying with Capistrano completed including all sample code. The price is temporarily reduced while the supplementary chapters on what's happening behind the scenes and advanced configuration are completed, everyone who buys the book gets free updates for life.

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. 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. It includes a "Five minute VPS" quickstart section for the impatient.

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.

It also includes detailed sample code and complete instructions for deploying Sidekiq workers, configuring NGinx Virtualhosts and automatic SSL with LetsEncrypt. Finally it covers how to setup automated database backups and a will soon include a bonus chapter on integrating deployment with CI.

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.

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

Author

About the Author

Ben Dixon

Currently based in London, I've been developing web applications for over ten years, over the last few years specialising in Ruby on Rails development and deployment. I'm co-founder & CTO of Catapult an on demand staffing platform serving some of the UK's largest enterprises. Previously I built an online codeschool platform as well as being the technical lead at a health and fitness startup providing the SpeedoFit swimming app & timetabling for venues such as the London Olympic Pool.

As part of these projects 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 debugging obscure indexing issues.

Offpeak I'm an obsessive indoor climber and lover of good wine, strong coffee and a (very) amateur photographer.

Translations

Translations

Languages

Contents

Table of Contents

Intro

  1. Preface to the fifth edition (2021)
  2. Current status of the fifth edition
  3. The purpose of this book
  4. Who is this book not for
  5. If you’re in a hurry
  6. About Me
  7. Why This Book Exists
  8. Intended Audience
  9. Pre-requisites
  10. Structure of Part 1 - Setting up the server
  11. Structure of Part 2 - Deploying to the server
  12. Version

The Stack

  1. Overview
  2. Ubuntu 20.04 LTS
  3. Nginx
  4. Postgresql
  5. Ruby + rbenv
  6. Redis
  7. Memcached
  8. Why This Stack
  9. Adapting to your stack

Tools And Terminology

  1. Introduction
  2. Automation
  3. Introducing Chef
  4. Terminology
  5. Working without a Chef server - Chef Zero
  6. Leveraging the Community

Installing Tools

  1. Overview
  2. Installing Tools

Quick Start

  1. Overview
  2. Next Steps

Creating a new project & Berkshelf

  1. Generating a Chef Repo
  2. Berkshelf
  3. Berksfile.lock
  4. Configuring Knife
  5. Recap / Quick Reference
  6. Up Next

Using Knife

  1. Overview
  2. SSH Access
  3. Setting up a node for Chef
  4. Editing data in Chef & Setting Our Editor
  5. Editing a node definition
  6. Editing attributes
  7. Adding to the run list
  8. Creating and editing roles
  9. Applying configuration to a node (converging)
  10. Working with data bags
  11. Other useful commands
  12. Quick Reference
  13. Up Next

Creating a Chef Cookbook

  1. Overview
  2. Prerequisites
  3. Generating a Cookbook
  4. Underscores in cookbook names
  5. Adding the cookbook to Berkshelf
  6. Structure of a Cookbook
  7. Installing Redis Manually
  8. Converting this into a simple Chef Cookbook
  9. Adding the recipe to the node definition
  10. Applying the updated node definition
  11. Is This Cookbook “Bad” or “Wrong”
  12. Limitations of the simple Cookbook
  13. Improving our Cookbook the Chef Way
  14. Template Directories
  15. Updating The Node
  16. Adding flexibility with attributes
  17. Conclusion

Node and Role Definitions

  1. Overview
  2. Attribute Hierarchy
  3. Node Definitions
  4. Role Definitions
  5. Breaking a System Into Roles
  6. Limitations of Roles

A Template for Rails Servers

  1. Overview
  2. The Example Configuration

Basic Server Setup

  1. Overview
  2. Unattended Upgrades
  3. Automatic System Time via NTP
  4. Locales

Security

  1. Overview
  2. No Magic Bullet
  3. Common Pitfalls
  4. SSH Hardening
  5. Firewall
  6. Users
  7. Sudo

Ruby & Gem Dependencies

  1. Overview
  2. Rbenv v RVM
  3. How rbenv works
  4. The rbenv Cookbook
  5. Gem Dependencies

Monit

  1. Which configuration goes where
  2. The importance of a custom monitoring configuration
  3. System level monitoring
  4. Monitoring Pids
  5. Monitoring Ports
  6. Free Space Monitoring
  7. Alerts and avoiding overload
  8. Serving the web interface with Nginx

nginx

  1. Overview
  2. Why Nginx
  3. The Cookbook
  4. Virtualhosts
  5. Monitoring

PostgreSQL

  1. Overview
  2. Installation
  3. Accessing the psql console
  4. Creating Databases
  5. Adding users to Databases
  6. Listing all databases and permissions
  7. Configuring Authentication
  8. Allow External Access
  9. Mangaging pg_hba.conf with chef
  10. Importing and Exporting Databases
  11. Monit

Redis and Memcached

  1. Redis
  2. Memcached
  3. Conclusion

Deploying with Capistrano Quickstart

  1. Overview
  2. Capistrano
  3. Steps
  4. Copying configuration to the destination server
  5. Conclusion

Deploying with Capistrano

  1. Overview
  2. Stages
  3. Adding Capistrano to an application
  4. Installation
  5. Capistrano 3 is Rake
  6. The Capfile
  7. Common configuration
  8. Running tests
  9. Hooks
  10. Setting up stages
  11. Generating Remote Configuration Files
  12. Database Credentials
  13. Deploying
  14. Conclusion

Writing Custom Capistrano Tasks

  1. Overview
  2. File Structure
  3. The Task
  4. A note on Namespacing

Unicorn Configuration and Zero Downtime Deployment (Deprecated)

  1. Overview
  2. Unicorn and the request flow
  3. Basic Configuration
  4. Unix Signals
  5. Unicorn Init script
  6. Zero Downtime Deployment
  7. Gemfile Reloading
  8. Troubleshooting Process for Zero Downtime Deployment

Nginx Virtualhosts and SSL

  1. Overview
  2. A Basic Virtualhost
  3. DNS Overview
  4. Forcing HTTPS
  5. Adding SSL
  6. Chaining SSL Certificates
  7. Updating SSL Certificates

Sidekiq

  1. Overview
  2. Sidekiq Version 3
  3. Capistrano Integration

Backups

  1. Overview
  2. Structure
  3. Getting Started
  4. Triggering Backups with Whenever
  5. Conclusion

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub