Guest User

Untitled

a guest
Dec 14th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. require "bundler/capistrano"
  2.  
  3. # Below will speed-up deploy by doing a git diff from last deploy
  4. # set :deploy_via, :remote_cache
  5.  
  6. set :scm, :git
  7. set :repository, "jet@209.166.65.132:aceleathergoods.git"
  8. set :branch, "origin/dev_ruby-1.9.3-p194"
  9. set :migrate_target, :current
  10. set :ssh_options, { :forward_agent => true }
  11. set :rails_env, "production"
  12. set :deploy_to, "/home/deployer/apps/aceleathergoods"
  13. set :normalize_asset_timestamps, false
  14.  
  15. set :user, "deployer"
  16. set :group, "staff"
  17. set :use_sudo, false
  18.  
  19. role :web, "209.166.65.132"
  20. role :app, "209.166.65.132"
  21. role :db, "209.166.65.132", :primary => true
  22.  
  23. set(:latest_release) { fetch(:current_path) }
  24. set(:release_path) { fetch(:current_path) }
  25. set(:current_release) { fetch(:current_path) }
  26.  
  27. set(:current_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
  28. set(:latest_revision) { capture("cd #{current_path}; git rev-parse --short HEAD").strip }
  29. set(:previous_revision) { capture("cd #{current_path}; git rev-parse --short HEAD@{1}").strip }
  30.  
  31. default_environment["RAILS_ENV"] = 'production'
  32.  
  33. default_environment["PATH"] = "/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@Spree_1.1.1/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/bin:/bin"
  34. default_environment["GEM_HOME"] = "/usr/local/rvm/gems/ruby-1.9.3-p194"
  35. default_environment["GEM_PATH"] = "/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194@Spree_1.1.1"
  36. default_environment["RUBY_VERSION"] = "ruby-1.9.3-p194"
  37.  
  38. default_run_options[:shell] = 'bash'
  39.  
  40. namespace :deploy do
  41. desc "Deploy your application"
  42. task :default do
  43. update
  44. restart
  45. end
  46.  
  47. desc "Setup your git-based deployment app"
  48. task :setup, :except => { :no_release => true } do
  49. dirs = [deploy_to, shared_path]
  50. dirs += shared_children.map { |d| File.join(shared_path, d) }
  51. run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
  52. run "git clone #{repository} #{current_path}"
  53. end
  54.  
  55. task :cold do
  56. update
  57. migrate
  58. end
  59.  
  60. task :update do
  61. transaction do
  62. update_code
  63. end
  64. end
  65.  
  66. desc "Update the deployed code."
  67. task :update_code, :except => { :no_release => true } do
  68. run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
  69. finalize_update
  70. end
  71.  
  72. desc "Update the database (overwritten to avoid symlink)"
  73. task :migrations do
  74. transaction do
  75. update_code
  76. end
  77. migrate
  78. restart
  79. end
  80.  
  81. task :finalize_update, :except => { :no_release => true } do
  82. run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
  83.  
  84. # mkdir -p is making sure that the directories are there for some SCM's that don't
  85. # save empty folders
  86. run <<-CMD
  87. rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
  88. mkdir -p #{latest_release}/public &&
  89. mkdir -p #{latest_release}/tmp &&
  90. ln -s #{shared_path}/log #{latest_release}/log &&
  91. ln -s #{shared_path}/system #{latest_release}/public/system &&
  92. ln -s #{shared_path}/tmp/pids #{latest_release}/tmp/pids &&
  93. ln -sf #{shared_path}/database.yml #{latest_release}/config/database.yml
  94. CMD
  95.  
  96. if fetch(:normalize_asset_timestamps, true)
  97. stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
  98. asset_paths = fetch(:public_children, %w(images stylesheets javascripts)).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
  99. run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
  100. end
  101. end
  102.  
  103. desc "Zero-downtime restart of Unicorn"
  104. task :restart, :except => { :no_release => true } do
  105. run "kill -s USR2 `cat #{shared_path}/tmp/pids/unicorn.aceleathergoods.pid`"
  106. end
  107.  
  108. desc "Start unicorn"
  109. task :start, :except => { :no_release => true } do
  110. run "cd #{current_path} ; bundle exec unicorn_rails -c config/unicorn.rb -D"
  111. end
  112.  
  113. desc "Stop unicorn"
  114. task :stop, :except => { :no_release => true } do
  115. run "kill -s QUIT `cat #{shared_path}/tmp/pids/unicorn.aceleathergoods.pid`"
  116. end
  117.  
  118. namespace :rollback do
  119. desc "Moves the repo back to the previous version of HEAD"
  120. task :repo, :except => { :no_release => true } do
  121. set :branch, "HEAD@{1}"
  122. deploy.default
  123. end
  124.  
  125. desc "Rewrite reflog so HEAD@{1} will continue to point to at the next previous release."
  126. task :cleanup, :except => { :no_release => true } do
  127. run "cd #{current_path}; git reflog delete --rewrite HEAD@{1}; git reflog delete --rewrite HEAD@{1}"
  128. end
  129.  
  130. desc "Rolls back to the previously deployed version."
  131. task :default do
  132. rollback.repo
  133. rollback.cleanup
  134. end
  135. end
  136. end
  137.  
  138. def run_rake(cmd)
  139. run "cd #{current_path}; #{rake} #{cmd}"
  140. end
Add Comment
Please, Sign In to add comment