Created
October 8, 2009 18:01
-
-
Save tobias/205233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'new_relic/recipes' | |
set :rails_env, RUBBER_ENV | |
on :load do | |
set :application, rubber_env.app_name | |
set :runner, rubber_env.app_user | |
set :deploy_to, "/mnt/#{application}-#{RUBBER_ENV}" | |
end | |
ssh_options[:forward_agent] = true | |
set :repository, "[email protected]:account/repo_name.git" | |
set :scm, "git" | |
set :deploy_via, :remote_cache | |
set :branch, 'master' | |
#set :branch, 'rubber' | |
#set :scm, :none | |
#set :repository, "." | |
#set :deploy_via, :copy | |
# Easier to do system level config as root - probably should do it through | |
# sudo in the future. We use ssh keys for access, so no passwd needed | |
set :user, 'root' | |
set :password, nil | |
# Use sudo with user rails for cap deploy:[stop|start|restart] | |
# This way exposed services (mongrel) aren't running as a privileged user | |
set :use_sudo, true | |
# How many old releases should be kept around when running "cleanup" task | |
set :keep_releases, 3 | |
# Lets us work with staging instances without having to checkin config files | |
# (instance*.yml + rubber*.yml) for a deploy. This gives us the | |
# convenience of not having to checkin files for staging, as well as | |
# the safety of forcing it to be checked in for production. | |
set :push_instance_config, RUBBER_ENV != 'production' | |
# Allows the tasks defined to fail gracefully if there are no hosts for them. | |
# Comment out or use "required_task" for default cap behavior of a hard failure | |
rubber.allow_optional_tasks(self) | |
# Wrap tasks in the deploy namespace that have roles so that we can use FILTER | |
# with something like a deploy:cold which tries to run deploy:migrate but can't | |
# because we filtered out the :db role | |
namespace :deploy do | |
rubber.allow_optional_tasks(self) | |
tasks.values.each do |t| | |
if t.options[:roles] | |
task t.name, t.options, &t.body | |
end | |
end | |
end | |
# ============================================================================= | |
# TASKS | |
# ============================================================================= | |
Dir["#{File.dirname(__FILE__)}/rubber/deploy-*.rb"].each do |deploy_file| | |
load deploy_file | |
end | |
before "deploy:update_code", "setup_known_hosts" | |
after 'rubber:install_gems', 'install_slim_attributes' | |
after "rubber:setup_app_permissions", "di:create_tmp_cache" | |
after "rubber:setup_app_permissions", "di:fix_public_permissions" | |
after "deploy:update", "newrelic:notice_deployment" | |
after "deploy", "deploy:notify_campfire" | |
after "deploy:migrations", "deploy:notify_campfire" | |
task :setup_known_hosts do | |
run "echo 'github.com,65.74.180.52 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' > ~/.ssh/known_hosts" | |
end | |
task :install_slim_attributes do | |
sudo 'gem install slim-attributes -- --with-mysql-config' | |
end | |
namespace :di do | |
desc "creates cache dir" | |
task :create_tmp_cache, :roles => :app do | |
run "mkdir -p #{current_path}/tmp/cache" | |
end | |
task :fix_public_permissions, :roles => :app do | |
run "chown -R app:app #{current_path}/public" | |
end | |
end | |
namespace :deploy do | |
desc 'notifies campfire room of deploy' | |
task :notify_campfire do | |
begin | |
require 'tinder' | |
rails_env = fetch(:rails_env, "production") | |
local_user = ENV['USER'] || ENV['USERNAME'] | |
msg = "[#{application}/#{branch}] deployed to #{rails_env} by #{local_user} at #{Time.now}" | |
puts "Notifying Campfire with '#{msg}'" | |
campfire = Tinder::Campfire.new('cf-subdomain') | |
campfire.login('[email protected]', 'password') | |
room = campfire.find_room_by_name('Some Room') | |
room.speak(msg) | |
campfire.logout | |
rescue | |
#don't kill cap just because we can't notify | |
puts "Notifying Campfire failed, reason: #{$!}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment