0.0
No commit activity in last 3 years
No release in over 3 years
Some capistrano automation to handle apps deployed to VM Farms
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request