/config/deploy.rb

https://bitbucket.org/UIUCLibrary/dspace-rails · Ruby · 99 lines · 61 code · 20 blank · 18 comment · 1 complexity · eee981af329030140ae42a780bbacaf6 MD5 · raw file

  1. require 'bundler/capistrano'
  2. require 'tmpdir'
  3. require 'fileutils'
  4. set :production_server, "vanaheim.cites.illinois.edu"
  5. set :staging_server, "vanaheim-dev.cites.illinois.edu"
  6. default_run_options[:shell] = '/bin/bash -l'
  7. set :deploy_via, :copy
  8. set :copy_strategy, :export
  9. task :staging do
  10. role :web, staging_server
  11. role :app, staging_server
  12. role :db, staging_server, :primary => true
  13. end
  14. task :production do
  15. role :web, production_server
  16. role :app, production_server
  17. role :db, production_server, :primary => true
  18. before 'deploy:update_code', 'deploy:rsync_ruby'
  19. end
  20. set :application, "dspace-rails"
  21. set :rails_env, ENV['RAILS_ENV'] || 'production'
  22. set :scm, :git
  23. set :repository, 'git@bitbucket.org:UIUCLibrary/dspace-rails.git'
  24. #uncomment line below to call git from remote server (comment :deploy_via, :copy)
  25. #set :deploy_via, :remote_cache
  26. #directories on the server to deploy the application
  27. #the running instance gets links to [deploy_to]/current
  28. set :home, "/services/ideals-dspace"
  29. set :deploy_to, "#{home}/dspace-rails"
  30. set :shared_config, "#{shared_path}/config"
  31. set :public, "#{current_path}/public"
  32. set :user, 'ideals-dspace'
  33. set :use_sudo, false
  34. namespace :deploy do
  35. task :start do
  36. # run "cd #{home}/bin ; ./start-bibapp"
  37. end
  38. task :stop do
  39. # run "cd #{home}/bin ; ./stop-bibapp"
  40. end
  41. task :restart, :roles => :app, :except => {:no_release => true} do
  42. # ;
  43. end
  44. desc "create a config directory under shared"
  45. task :create_shared_dirs do
  46. run "mkdir #{shared_path}/config"
  47. end
  48. desc "copy shared configuration"
  49. task :copy_config do
  50. ['database.yml'].each do |file|
  51. run "cp #{shared_config}/#{file} #{current_path}/config/#{file}"
  52. end
  53. end
  54. #Since we can't build on the production server we have to copy the ruby and bundle gems from the test server.
  55. #Note that this does mean that a lot of stale gems may accumulate over time.
  56. #For the test server, when we move to the new servers, and assuming that we use rvm, the standard procedure should suffice to clear out
  57. #gems directly associated with the ruby (clear and rebuild the gemset).
  58. #For the shared bundle, make sure the latest code is installed and then move the capistrano shared/bundle and run
  59. #cap staging bundle:install. Assuming that is fine the old bundle can be removed
  60. #For the production server, you'll have to remove the local cache and also the target directories on the production
  61. #server. Then run this and everything should be copied over.
  62. #That said, I think by preserving the local copy, instead of having it in /tmp, should really render weeding the old
  63. #gems out into an optional activity. (Of course, bundler and rvm help with this as well.)
  64. desc "rsync the ruby directory from the test server to the production server"
  65. task :rsync_ruby do
  66. local_cache_dir = "/home/hading/cache/etd-reports"
  67. rsync("#{home}/.rvm/", "#{local_cache_dir}/ruby/")
  68. rsync("#{shared_path}/bundle/", "#{local_cache_dir}/bundle/")
  69. # rsync("#{home}/.passenger/", "#{local_cache_dir}/passenger/")
  70. end
  71. def rsync(remote, local)
  72. staqing_id = "#{user}@#{staging_server}"
  73. production_id = "#{user}@#{production_server}"
  74. system "rsync -avPe ssh #{staqing_id}:#{remote} #{local}"
  75. system "rsync -avPe ssh #{local} #{production_id}:#{remote}"
  76. end
  77. end
  78. after 'deploy:setup', 'deploy:create_shared_dirs'
  79. after 'deploy:create_symlink', 'deploy:copy_config'