Skip to content

Instantly share code, notes, and snippets.

@cch1
Created October 19, 2010 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cch1/634832 to your computer and use it in GitHub Desktop.
Save cch1/634832 to your computer and use it in GitHub Desktop.
Post-Migration version
# Please install the Engine Yard Capistrano gem
# gem install eycap --source http://gems.engineyard.com
require "eycap/recipes"
require 'new_relic/recipes'
# The following code has been lifted from config.rb
AppConfig = begin
require 'ostruct'
require 'yaml'
require 'erb'
config_dir = Pathname.pwd.join('config') # Assume cap makes Rails root be the current working directory
secrets_file = config_dir + "secrets.yml"
secrets = (YAML.load(ERB.new(File.read(secrets_file)).result) || {}) rescue {}
OpenStruct.new(secrets).freeze
end
# =============================================================================
# ENGINE YARD REQUIRED VARIABLES
# =============================================================================
# You must always specify the application and repository for every recipe. The
# repository must be the URL of the repository you want this recipe to
# correspond to. The :deploy_to variable must be the root of the application.
set :keep_releases, 5
set :application, "yacht"
set :repository, "git@osprey.yacht.com:yacht.git"
set :user, "yacht_prod"
set :password, AppConfig.deploy[:password]
set :deploy_to, "/data/#{application}"
# This will execute the Git revision parsing on the *remote* server rather than locally
#set :real_revision, lambda { source.query_revision(revision) { |cmd| capture(cmd) } }
# Tell Git to init/update submodules on deploy.
set :git_enable_submodules, 1
set :branch, 'production'
set :deploy_via, :remote_cache
set :monit_group, "yacht"
set :scm, :git
set :runner, "yacht_prod"
#set :use_sudo, false # Attempt to prevent root-owned stuff, particularly tmp/attach directory
set :use_sudo, true # Gem installs get screwed up otherwise.
set :production_database, "yacht_production"
set :production_dbhost, "westwindmarine-mysql-production-master"
set :dbuser, "yacht_db"
set :dbpass, AppConfig.deploy[:dbpass]
# comment out if it gives you trouble. newest net/ssh needs this set.
ssh_options[:paranoid] = false
# =============================================================================
# ROLES
# =============================================================================
# You can define any number of roles, each of which contains any number of
# machines. Roles might include such things as :web, or :app, or :db, defining
# what the purpose of each machine is. You can also specify options that can
# be used to single out a specific subset of boxes in a particular role, like
# :primary => true.
task :testdir do
run "mkdir -p #{shared_path}/x"
run <<-CMD
rm -rf #{shared_path}/y &&
ln -nfs #{shared_path}/x #{shared_path}/y
CMD
end
task :production do
role :web, "209.251.187.83:7000" # yacht [mongrel] [mysql50-10-master]
role :app, "209.251.187.83:7000", :mongrel => true, :memcached => true
role :db , "209.251.187.83:7000", :primary => true
set :rails_env, "production"
set :environment_database, defer { production_database }
set :environment_dbhost, defer { production_dbhost }
end
# =================== custom asset-oriented tasks =============================
depend :remote, :directory, "#{shared_path}/attachments"
namespace :attachments do
task :symlink, :roles => :app do
# First clear the new release of any stowaway attachments (although .gitignore should ensure this
# directory does not exist in the repository), then symbolically link the shared (across releases)
# attachments directory into the proper location within the release directory hierarchy.
# WARNING: running this task manually on an existing release should fail early -but if not it may
# purge all attachments!
# UPDATE: Too scary. I've removed the purging of stowaways: rm -rf #{release_path}/public/attachments &&
run <<-CMD
ln -nfs #{shared_path}/attachments #{release_path}/public/attachments
CMD
end
end
after "deploy:update_code", "attachments:symlink"
# =================== custom secrets management tasks =============================
depend :remote, :file, "#{shared_path}/config/secrets.yml"
namespace :deploy do
task :copy_secrets do
# Copy the file into the release. We don't link the file because it is never changed by the app.
run "cp #{shared_path}/config/secrets.yml #{release_path}/config/secrets.yml"
end
end
after "deploy:update_code", "deploy:copy_secrets"
# ======================== custom gem installer ====================================
namespace :gems do
desc "Install configured gems"
task :install, :roles => :app do
# We move to the release path to ensure NEW requirements are installed
# NB: the init script for the attach plugin attempts to create tmp/attach. If the following rake
# task is run as root (sudo), then the temp directory is owned by root as well -painful!
# For now, don't sudo -just run it as the runner user.
run "cd #{release_path} && rake RAILS_ENV=production gems:install"
end
end
after "deploy:symlink_configs", "gems:install"
# ==================================================================================
# Any custom after tasks can go here.
after "deploy:symlink_configs", "yacht_custom"
task :yacht_custom, :roles => :app, :except => {:no_release => true, :no_symlink => true} do
sudo <<-CMD
monit restart sendmail_updater
monit restart bouncer
CMD
end
# Fetch the tags from the repo (we display them in an admin interface)
after "deploy:update_code", "fetch_tags"
task :fetch_tags, :roles => :app, :except => {:no_release => true, :no_symlink => true} do
`git fetch --tags`
end
# =============================================================================
# New Relic deployment notifier
# We need to run this after our collector mongrels are up and running
# This goes out even if the deploy fails, sadly
after "deploy:update", "newrelic:notice_deployment"
# =============================================================================
# Do not change below unless you know what you are doing!
after "deploy", "deploy:cleanup"
after "deploy:migrations" , "deploy:cleanup"
after "deploy:update_code", "deploy:symlink_configs"
# uncomment the following to have a database backup done before every migration
before "deploy:migrate", "db:dump"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment