Additional recipes for use with capistrano to automate installation of a full-stack Rails environment! No need to mess with Chef, Puppet, etc. Several of these recipes are based on the Capistrano Recipes (#337) and Zero-Downtime Deployment (#373) episodes of RailsCasts.
We use these recipes at 55 Minutes to standardize our Rails deployments. All recipes are tailored for:
- Ubuntu 12.04 LTS
- Postmark for mail delivery
Add the capistrano-fiftyfive gem to the development group of your Rails application's Gemfile:
group :development do gem 'capistrano-fiftyfive', :github => '55minutes/capistrano-fiftyfive', :branch => :master end
And then execute:
2. Load the recipes
Add this to your app's
require "capistrano/fiftyfive" Capistrano::Fiftyfive.load(:autorun => true) set :project_root, File.expand_path("../..", __FILE__)
This will load all the capistrano-fiftyfive recipes, and run their tasks automatically during appropriate times of the deploy lifecycle. If you want to customize this behavior, see step 3 below.
Many of the recipes have default settings that can be overridden. Use your deploy.rb file to specify these overrides. If you use multistage, you can do environment-specific overrides. Here's an example:
set :unicorn_workers, 8
See the Reference section below for the full list of settings and their default values.
3. (Advanced) Customize which recipes are loaded and executed
Certain recipes can be excluded, using the
Capistrano::Fiftyfive.load(:exclude => [:cron, :delayed_job], :autorun => true)
If you know exactly the recipes you want, use
Capistrano::Fiftyfive.load(:only => [:nginx, :unicorn], :autorun => true)
If you want full control over how tasks are incorporated into the deploy
:autorun => false. Then declare your own rules using the
standard capistrano hooks. For example:
Capistrano::Fiftyfive.load(:only => :secrets, :autorun => false) after "deploy:finalize_update", "fiftyfive:secrets:symlink"
A working example
Check out our rails-starter project for a sample deploy.rb with multistage integration.
The power of the capistrano-fiftyfive recipes is that they take care of the entire setup of a bare Ubuntu 12.04 server, all the way to a fully configured and running Rails app on top up Unicorn, Nginx, rbenv, and PostgreSQL.
Of course, if you want full control, you can also run tasks individually.
Deploying to a new server from scratch
These steps assume you have loaded the full set of capistrano-fiftyfive
recipes in your deploy.rb, including
:autorun => true.
- Provision an Ubuntu 12.04 VPS at your hosting provider of choice.
- SSH into that VPS as root and run
aptitude update && aptitude safe-upgrade
- Create the admin group:
- Create a deployer user in that group:
adduser deployer --ingroup admin
- If you have an SSL key and certificate prepared, install them in
/etc/ssl. Otherwise, you can run
cap fiftyfive:ssl:generate_self_signed_crtto quickly create a temporary self-signed one.
Now, from your Rails project on your local machine, fire off these commands. These will install various packages, compile Ruby, set up the database, and deploy your app.
cap deploy:install cap deploy:setup cap deploy:cold
Running individual tasks
For a full description of the recipes you've installed, run:
All tasks from capistrano-fiftyfive will be prefixed with
can run these tasks just like any other capistrano task, like so:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request