Over a million developers have joined DZone.

Rails Environment Specific Capistrano Includes/Overrides

DZone's Guide to

Rails Environment Specific Capistrano Includes/Overrides

· ·
Free Resource
This cap technique allows you to include environment specific tasks and namespaces as well as override anything in the master deploy.rb. Its rather simplistic.

Add your environment specific cap scripts into RAILS_ROOT/config/deployments/.

Example command-line usage:

# RAILS_ENV=production cap deploy


# cap deploy rails_env=beta

# Example needed variables at the top of your deploy.rb

set :default_env,  'beta'
set :rails_env,     ENV['rails_env'] || ENV['RAILS_ENV'] || default_env
set :extra_deploys, 'config/deployments/'


# Now add this to the bottom of your deploy.rb, last thing to load.

if extra_deploys && File.exists?(extra_deploys+rails_env+".rb")
  puts "Loaded #{extra_deploys+rails_env}.rb" if load extra_deploys+rails_env
  puts "Could not find #{extra_deploys+rails_env}.rb"

You may change your default_env or any other piece to fit into your deployments. The secret is "load" method call burried in that latter code portion above. The reason you load at the end of your deploy.rb is so you can override anything defined above that call in your environment specific scripts.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}