Reliably Deploying Rails Applications
Reliably Deploying Rails Applications
Hassle free provisioning, reliable deployment
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.
- Preface to the fifth edition (2021)
- Current status of the fifth edition
- The purpose of this book
- Who is this book not for
- If you’re in a hurry
- About Me
- Why This Book Exists
- Intended Audience
- Structure of Part 1 - Setting up the server
- Structure of Part 2 - Deploying to the server
- Ubuntu 20.04 LTS
- Ruby + rbenv
- Why This Stack
- Adapting to your stack
Tools And Terminology
- Introducing Chef
- Working without a Chef server - Chef Zero
- Leveraging the Community
- Installing Tools
- Next Steps
Creating a new project & Berkshelf
- Generating a Chef Repo
- Configuring Knife
- Recap / Quick Reference
- Up Next
- SSH Access
- Setting up a node for Chef
- Editing data in Chef & Setting Our Editor
- Editing a node definition
- Editing attributes
- Adding to the run list
- Creating and editing roles
- Applying configuration to a node (converging)
- Working with data bags
- Other useful commands
- Quick Reference
- Up Next
Creating a Chef Cookbook
- Generating a Cookbook
- Adding the cookbook to Berkshelf
- 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
Node and Role Definitions
- Attribute Hierarchy
- Node Definitions
- Role Definitions
- Breaking a System Into Roles
- Limitations of Roles
A Template for Rails Servers
- The Example Configuration
Basic Server Setup
- Unattended Upgrades
- Automatic System Time via NTP
- No Magic Bullet
- Common Pitfalls
- SSH Hardening
Ruby & Gem Dependencies
- Rbenv v RVM
- How rbenv works
- The rbenv Cookbook
- Gem Dependencies
- 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
- Why Nginx
- The Cookbook
- 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
Redis and Memcached
Deploying with Capistrano Quickstart
- Copying configuration to the destination server
Deploying with Capistrano
- Adding Capistrano to an application
- Capistrano 3 is Rake
- The Capfile
- Common configuration
- Running tests
- Setting up stages
- Generating Remote Configuration Files
- Database Credentials
Writing Custom Capistrano Tasks
- File Structure
- The Task
- A note on Namespacing
Unicorn Configuration and Zero Downtime Deployment (Deprecated)
- Unicorn and the request flow
- Basic Configuration
- Unix Signals
- Unicorn Init script
- Zero Downtime Deployment
- Gemfile Reloading
- Troubleshooting Process for Zero Downtime Deployment
Nginx Virtualhosts and SSL
- A Basic Virtualhost
- DNS Overview
- Forcing HTTPS
- Adding SSL
- Chaining SSL Certificates
- Updating SSL Certificates
- Sidekiq Version 3
- Capistrano Integration
- Getting Started
- Triggering Backups with Whenever
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.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, 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.