Deploying Rails
Automate, Deploy, Scale, Maintain,
and Sleep at Night
by Anthony Burns, Tom Copeland
Version: P1.0 (July, 2012)
Copyright 2012 Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Table of Contents
Copyright 2012, The Pragmatic Bookshelf.
What Readers Are Saying About Deploying Rails
Deploying Rails will help you transform your deployment process from brittle chaos into something organized, understandable, and repeatable.
Trek Glowacki |
Independent developer |
Covering such a wide range of useful topics such as deployment, configuration management, and monitoring, in addition to using industry-standard tools following professionally founded best practices, makes this book an indispensable resource for any Rails developer.
Mitchell Hashimoto |
Lead developer, Vagrant |
Targeted for the developer, Deploying Rails presents, in a clear and easily understandable manner, a bevy of some of the less intuitive techniques it has taken me years to assemble as a professional. If you build Rails apps and have ever asked, Where/how do I deploy this? this book is for you.
James Retterer |
Senior software engineer, Getty Images |
Preface
Ruby on Rails has taken the web application development world by storm. Those of us who have been writing web apps for a few years remember the good ol days when the leading contenders for web programming languages were PHP and Java, with Perl, Smalltalk, and even C++ as fringe choices. Either PHP or Java could get the job done, but millions of lines of legacy code attest to the difficulty of using either of those languages to deliver solid web applications that are easy to evolve.
But Ruby on Rails changed all that. Now thousands of developers around the world are writing and delivering high-quality web applications on a regular basis. Lots of people are programming in Ruby. And there are plenty of books, screencasts, and tutorials for almost every aspect of bringing a Rails application into being.
We say almost every aspect because theres one crucial area in which Rails applications are not necessarily a joy; that area is deployment. The most elegant Rails application can be crippled by runtime environment issues that make adding new servers an adventure, unexpected downtime a regularity, scaling a difficult task, and frustration a constant. Good tools do exist for deploying, running, monitoring, and measuring Rails applications, but pulling them together into a coherent whole is no small effort.
In a sense, we as Rails developers are spoiled. Since Rails has such excellent conventions and practices, we expect deploying and running a Rails application to be a similarly smooth and easy path. And while there are a few standard components for which most Rails developers will reach when rolling out a new application, there are still plenty of choices to make and decisions that can affect an applications stability.
And thats why weve written this book. After several years of full-time consulting for companies that were writing and fielding Rails applications, weve learned a few things about running busy Rails applications in production environments. Throughout this book well explore various aspects of deploying Rails applications, and well review and apply the practices and tools that helped us keep our consulting clients happy by making their Rails applications reliable, predictable, and, generally speaking, successful. When you finish reading this book, youll have a firm grasp on whats needed to deploy your application and keep it running. Youll also pick up valuable techniques and principles for constructing a production environment that watches for impending problems and alerts you before things go wrong.
Who Should Read This Book?
This book is for Rails developers who, while comfortable with coding in Ruby and using Rails conventions and best practices, may be less sure of how to get a completed Rails application deployed and running on a server. Just as you learned the Rails conventions for structuring an applications code using REST and MVC, youll now learn how to keep your application faithfully serving hits, how to know when your application needs more capacity, and how to add new resources in a repeatable and efficient manner so you can get back to adding features and fixing bugs.
This book is also for system administrators who are running a Rails application in production for the first time or for those who have a Rails application or two up and running but would like to improve the runtime environment. You probably already have solid monitoring and metrics systems; this book will help you monitor and measure the important parts of your Rails applications. In addition, you may be familiar with Puppet, the open source system provisioning tool. If so, by the end of this book youll have a firm grasp on using Puppet, and youll have a solid set of Puppet manifests. Even if youre already using Puppet, you may pick up a trick or two from the manifests that weve compiled.
Finally, this book is for project managers who are overseeing a project where the primary deliverable is a Rails application that performs some business functionality. You can use the major sections in this book as a checklist. Theres a chapter on monitoring; what kind of monitoring is being done on your application, and what kind of situations might occur where would you like to trigger some sort of alert? Theres a chapter on metrics; what kind of charts and graphs would best tell you how the application is meeting the businesss needs? If your application has some basic story for each chapter in this book, youll know that youre covering the fundamentals of a solid Rails application environment.
What Is in the Book?
This book is centered around an example social networking application called MassiveApp. While MassiveApp may not have taken the world by storm just yet, were confident that its going to be a winner, and we want to build a great environment in which MassiveApp can grow and flourish. This book will take us through that journey.
Well start with Chapter 2, , where well learn how to set up our own virtual server with Vagrant, an open source tool that makes it easy to configure and manage VirtualBox virtual machines.