SHARE
TWEET

deploy.rb

a guest Jun 21st, 2012 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This is a sample Capistrano config file for rubber
  2.  
  3. set :rails_env, Rubber.env
  4.  
  5. on :load do
  6.   set :application, rubber_env.app_name
  7.   set :runner,      rubber_env.app_user
  8.   set :deploy_to,   "/mnt/#{application}-#{Rubber.env}"
  9.   set :copy_exclude, [".git/*", ".bundle/*", "log/*", ".rvmrc"]
  10. end
  11.  
  12. # Use a simple directory tree copy here to make demo easier.
  13. # You probably want to use your own repository for a real app
  14. set :scm, :none
  15. set :repository, "."
  16. set :deploy_via, :copy
  17.  
  18. # Easier to do system level config as root - probably should do it through
  19. # sudo in the future.  We use ssh keys for access, so no passwd needed
  20. set :user, 'root'
  21. set :password, nil
  22.  
  23. # Use sudo with user rails for cap deploy:[stop|start|restart]
  24. # This way exposed services (mongrel) aren't running as a privileged user
  25. set :use_sudo, true
  26.  
  27. # How many old releases should be kept around when running "cleanup" task
  28. set :keep_releases, 3
  29.  
  30. # Lets us work with staging instances without having to checkin config files
  31. # (instance*.yml + rubber*.yml) for a deploy.  This gives us the
  32. # convenience of not having to checkin files for staging, as well as
  33. # the safety of forcing it to be checked in for production.
  34. set :push_instance_config, Rubber.env != 'production'
  35.  
  36. # don't waste time bundling gems that don't need to be there
  37. set :bundle_without, [:development, :test, :staging] if Rubber.env == 'production'
  38.  
  39. # Allow us to do N hosts at a time for all tasks - useful when trying
  40. # to figure out which host in a large set is down:
  41. # RUBBER_ENV=production MAX_HOSTS=1 cap invoke COMMAND=hostname
  42. max_hosts = ENV['MAX_HOSTS'].to_i
  43. default_run_options[:max_hosts] = max_hosts if max_hosts > 0
  44.  
  45. # Allows the tasks defined to fail gracefully if there are no hosts for them.
  46. # Comment out or use "required_task" for default cap behavior of a hard failure
  47. rubber.allow_optional_tasks(self)
  48.  
  49. # Wrap tasks in the deploy namespace that have roles so that we can use FILTER
  50. # with something like a deploy:cold which tries to run deploy:migrate but can't
  51. # because we filtered out the :db role
  52. namespace :deploy do
  53.   rubber.allow_optional_tasks(self)
  54.   tasks.values.each do |t|
  55.     if t.options[:roles]
  56.       task t.name, t.options, &t.body
  57.     end
  58.   end
  59. end
  60.  
  61. namespace :deploy do
  62.   namespace :assets do
  63.     rubber.allow_optional_tasks(self)
  64.     tasks.values.each do |t|
  65.       if t.options[:roles]
  66.         task t.name, t.options, &t.body
  67.       end
  68.     end
  69.   end
  70. end
  71.  
  72. # load in the deploy scripts installed by vulcanize for each rubber module
  73. Dir["#{File.dirname(__FILE__)}/rubber/deploy-*.rb"].each do |deploy_file|
  74.   load deploy_file
  75. end
  76.  
  77. # capistrano's deploy:cleanup doesn't play well with FILTER
  78. after "deploy", "cleanup"
  79. after "deploy:migrations", "cleanup"
  80. task :cleanup, :except => { :no_release => true } do
  81.   count = fetch(:keep_releases, 5).to_i
  82.  
  83.   rsudo <<-CMD
  84.     all=$(ls -x1 #{releases_path} | sort -n);
  85.     keep=$(ls -x1 #{releases_path} | sort -n | tail -n #{count});
  86.     remove=$(comm -23 <(echo -e "$all") <(echo -e "$keep"));
  87.     for r in $remove; do rm -rf #{releases_path}/$r; done;
  88.   CMD
  89. end
  90.  
  91. if Rubber::Util.has_asset_pipeline?
  92.   # load asset pipeline tasks, and reorder them to run after
  93.   # rubber:config so that database.yml/etc has been generated
  94.   load 'deploy/assets'
  95.   callbacks[:after].delete_if {|c| c.source == "deploy:assets:precompile"}
  96.   callbacks[:before].delete_if {|c| c.source == "deploy:assets:symlink"}
  97.   before "deploy:assets:precompile", "deploy:assets:symlink"
  98.   after "rubber:config", "deploy:assets:precompile"
  99. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top