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.

525 readers

100% Happiness guarantee Learn more

Minimum: $20.00

Suggested: $30.00+

Ways to buy

  • Free sample download
  • 525 readers
  • 75% complete
  • Book language: English
  • Translations available: 1 translation
  • Updated

Translations

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 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 and handling schema migrations in a zero downtime environment.

The beauty of Heroku and other SaaS platforms is partly the tools they provide to make day to day administration simpler. This section also covers replicating this level of convenience on your own server, in particular:

  • Background jobs with Sidekiq
  • Managing SSL certificates
  • Log file rotation

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 available 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 and a detailed section on Configuring Zero Downtime deployment

Over the next few months I'll be adding additional chapters which go into detail on more advanced Nginx Virtualhosts, Unicorn configurations and so-on as well as ongoing housekeeping and maintenance tasks. I'll also continue to update the book with further chapters as and when I come across new tips and tricks.

Any feedback on content, structure or corrections very gratefully received, you can get me on twitter (@talkingquickly) or using the leanpub discuss button below.

Buy A Bundle, And Save

  • Reliably Deploying Rails Applications cover page
    • The Rails 4 Way cover page

    The Rails 4 Way + Reliably Deploying Rails Applications

    2 books for $79.00 $40.00

  • Reliably Deploying Rails Applications cover page
    • Sublime Productivity cover page

    Sublime Productivity + Reliably Deploying Rails Applications

    2 books for $55.00 $34.00

About the Author

Currently based between Google Campus, London and Paris, 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'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 the wrath of timezone switching.

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.

If you buy a Leanpub book you get all the updates to the book for free! All books are available in PDF, EPUB (for iPad) and MOBI (for Kindle). There is no DRM. There is no risk, just guaranteed happiness or your money back.

Table of Contents

  • 1.0 - Intro
    • The purpose of this book
    • About Me
    • Intended Audience
    • Pre-requisites
    • How to read this book
    • Structure of Part 1 (Chef)
    • Structure of Part 2 (Capistrano)
  • 2.0 - The Stack
    • Overview
    • Ubuntu 12.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 - 5 Minute Server
    • Overview
    • The Stack
    • Steps
  • 5.0 - Anatomy of a chef solo project
    • Overview
    • Creating a project
  • 5.1 - A Simple Chef Cookbook
    • Overview
    • Cloning the Redis recipe
    • Structure of the Redis Recipe
  • 5.2 - A Simple Node Definition
    • Overview
    • A redis node
    • Naming Node Definitions
  • 5.3 - A simple chef role
    • Overview
    • Creating a role definition
    • Default Attributes
    • json_class and chef_type
    • run_list
  • 5.4 - Applying a node definition to a VPS
    • Overview
    • Download additional cookbooks
    • Set up the VPS
    • Install chef on the remote machine
    • Make a change and re-apply
    • Summing Up
  • 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
    • Basic Packages
    • Adding a visual queue if you log into a production environment
    • Rails gem dependencies
  • 7.1 - Users
    • Overview
    • Users
    • Sudo
  • 07.2 - Security
    • Overview
    • A Note on security
    • Security Gotchas
    • Basic Measures
    • SSH Hardening
    • Unattended Upgrades
    • Automatically Updating Time
  • 7.3 - Firewall
    • Overview
    • UFW (Uncomplicated Firewall)
  • 7.4 - Applying the sample template to a VPS
    • Overview
    • Pre-requisites
    • Step by step
    • Showing that its worked
  • 8.0 - Installing Ruby
    • Overview
    • Rbenv v RVM
    • How rbenv works
    • The rbenv Cookbook
  • 9.0 - Monit
    • Overview
    • 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
  • Upstart
    • Overview
    • What monitors Monit?
    • Upstart Services
  • Forking My Monit Configurations
    • Overview
    • Why is creating your own Monit configurations so important?
    • Step by Step
  • 10.0 - Nginx
    • Overview
    • The Nginx Recipe
    • The place of Virtualhost files
    • The Default Virtualhost
  • 11.1 - 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
  • 11.2 - MySQL
    • Overview
    • Installation
    • Creating Databases
    • Configuring Authentication
    • Importing and Exporting Databases
    • Monit
    • Server Admin
  • 11.3 - MongoDB
    • Overview
    • Installation
    • Accessing the Mongo Shell
    • Importing and Exporting Databases
  • 11.4 - Redis
    • Overview
    • Installation
    • Security
    • Managing Size
    • Monit
  • 12.0 - Memcached
    • Overview
    • Installation
    • Security
    • Monit
  • 13.0 Testing with Vagrant
    • Overview
    • Getting Setup
    • SSHing in directly
    • Testing chef cookbooks
    • Users, Sudo and Root
    • Port Forwarding
  • 14.0 End of Part 1
    • Conclusion
  • 15.0 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.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 - Sidekiq
    • Overview
    • Sidekiq Version 3
    • Capistrano Integration

Last updated

This Book is for Sale Through Leanpub

Authors and publishers use Leanpub to publish amazing in-progress and completed books like this one.

Leanpub_logo_medium

Read

Leanpub has a wide selection of in-progress and completed books available to browse, purchase, and enjoy.

Browse the Bookstore

Write

Leanpub is free for authors and publishers to use. We pay authors or publishers 90% royalties minus 50 cents per sale.

Write a Book