Capistrano::Vmf
VM Farms integration for Capistrano. If you're deploying a Rails app to VM Farms then this is a set of tasks that will conform to their best practices, and some generators that get you the most out of your hosting.
In particular,
- Unicorn server configured for zero downtime restarts
- Default directories already configured
- Installs Ruby and sets as default
- Generators to configure NewRelic
Installation
Once you've got Capistrano installed,
Add this line to your application's Gemfile:
gem 'capistrano-vmf'
And then execute:
$ bundle
Usage
Require in Capfile
to use the default task:
require 'capistrano/vmf'
For your config/deploy.rb
, you'll want as a minimum:
# Point cap to your application
lock '3.1.0'
set :application, 'vmftest'
set :repo_url, 'git@bitbucket.org:yourname/repo.git'
set :pty, true
set :rvm1_ruby_version, "2.0.0-p247"
Then, in each config/deploy/*.rb
(corresponding to your environment)
# The list of servers, one line each
server '1.2.3.4', user: 'deploy', roles: %w{web app}
# The primary domain name of this environment, that you gave to VMF
set :site_name, "vmf.ertw.com"
# The list of services that get restarted.
set :supervisor_services, %w[unicorn resque-dev]
Note that options set in deploy.rb
are overridden in the environment file, and all these options are valid at either level.
Configurable options:
set :ruby_version, "2.0.0-p247" # Pick the version of Ruby you'll use
set :site_name, "test.example.com" # The hostname of your application (VMF has this, too)
# Each environment will probably have it's own in `config/deploy/*.rb`
set :supervisor_services, %q[unicorn resque] # the list of services to restart (supervisord)
Generators
This gem provides two generators that set up Unicorn and NewRelic RPM according to VM Farms recommended configuration.
Unicorn
Unicorn is a high performance application server that allows you to restart your application with zero downtime. When you restart, a new set of unicorn processes are spun up leaving the old ones to handle requests. The new servers start taking requests when the booting is complete, then the old servers are killed. VM Farms has special configuration on their side to do the zero downtime restarts correctly.
To use Unicorn in your application, run
bundle exec rails generate vmf:unicorn
bundle install
It will update your Gemfile and add a config/unicorn.rb
. By default 4 application servers are run but this is easily changed by talking to VM Farms support.
NewRelic
VM Farms has a partnership with NewRelic to give you free access to a standard account which provides detailed application performance monitoring. You will need a license key from VM Farms, then run
bundle exec rails generate vmf:newrelic
bundle install
You will be prompted for the licence key.
Other stuff
Have a Redis server? Define it:
server 'user@redisserver', roles: %w{redis}, no_release: true
Then you have two tasks:
redis:keys - shows all the keys
redis:flush - flush all the Redis keys
Do you want to store secrets in a config file on the server?
set :linked_files, %w{config/database.yml} # in your deploy
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} # Same for directories
Then copy the local file config/database.yml to all your servers
cap production files:copy[config/database.yml] # copies local database.yml to all servers
Contributing
- 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