tobias (owner)

Revisions

gist: 205233 Download_button fork
public
Public Clone URL: git://gist.github.com/205233.git
Embed All Files: show embed
rubber_deploy.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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, "git@github.com: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('cf-bot@domain.com', '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