Capistrano tasks for deploying Rails applications using Ubuntu 10.04, rbenv, nginx, Unicorn and PostgreSQL. Based on the excellent Railscasts by Ryan Bates, with permission of course. If you are new to Capistrano or setting up a VPS, I highly recommend subscribing to his pro screencasts and watching the following:
- Deploying to a VPS (Pro)
- Capistrano Tasks (Free)
- Capistrano Recipes (Pro)
I am not affiliated with Railscasts, I'm just a fan.
- Capistrano
- Fresh Ubuntu 10.04 or 11.10 install
Add these lines to your application's Gemfile:
gem 'capistrano'
gem 'cap_bootstrap'
And then execute:
$ bundle
Setup a new Ubuntu 10.04 slice. Add a user called deployer with sudo privileges.
In your project, run the following:
capify .
Then run this generator with an optional IP address to copy over a deploy.rb that is more suited to this gem. The application name defaults to the same name as your rails app and the repository is pulled from your .git/config.
rails g cap_bootstrap:install 99.99.99.99
Double check the settings in config/deploy.rb and then run:
cap deploy:install
cap deploy:setup
cap deploy:cold
Shown below are the default advanced settings, but they can overridden.
set(:domain) { "#{application}.com" }
set :postgresql_host, "localhost"
set(:postgresql_user) { application }
set(:postgresql_database) { "#{application}_production" }
set :ruby_version, "1.9.3-p125"
set :rbenv_bootstrap, "bootstrap-ubuntu-10-04" # Or bootstrap-ubuntu-11-10
set(:unicorn_user) { user }
set(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
set(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
set(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
set :unicorn_workers, 2
Version 0.1 uses Ryan's recipes pulled directly from Railscast episode #337 Capistrano Recipes. You will always be able to access this version with tag v0.1.
Future versions will incorporate optional installs such as MySQL, Apache, Phusion Passenger and additional server config such as setting a hostname. Also considering changes to allow deploying multiple apps onto a single server and provisioning Linode slices using their api.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request