Guest User

Untitled

a guest
Oct 10th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. set :whenever_environment, defer { stage }
  2.  
  3. require 'capistrano/ext/multistage'
  4. require 'bundler/capistrano'
  5. require 'yaml'
  6. set :whenever_command, "bundle exec whenever"
  7. require 'whenever/capistrano'
  8.  
  9. $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
  10. require "rvm"
  11. require "rvm/capistrano"
  12. set :rvm_ruby_string, 'ruby-1.9.2-p290'
  13. set :rvm_type, :system # Copy the exact line. I really mean :user here
  14.  
  15. set :rvm_path, "/usr/local/rvm"
  16. set :rvm_bin_path, "#{rvm_path}/bin"
  17. set :rvm_lib_path, "#{rvm_path}/lib"
  18. set :keep_releases, 5
  19.  
  20.  
  21. set :default_environment, {
  22. #'PATH' => "/usr/local/rvm/gems/ruby-1.9.2-p180/bin:/usr/local/rvm/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:$PATH",
  23. #'PATH' => "/usr/local/rvm/bin:/usr/local/rvm/rubies/ruby-1.9.2-p290/bin:$PATH",
  24. #'PATH' => "/usr/local/rvm/bin:$PATH",
  25. 'RUBY_VERSION' => 'ruby-1.9.2-p290@global',
  26. 'GEM_HOME' => '/usr/local/rvm/gems/ruby-1.9.2-p290@global',
  27. 'GEM_PATH' => '/usr/local/rvm/gems/ruby-1.9.2-p290@global',
  28. 'BUNDLE_PATH' => '/usr/local/rvm/gems/ruby-1.9.2-p290@global' # If you are using bundler.
  29. }
  30.  
  31. set :user, "deploy"
  32. set :application, "youbuy"
  33. set :repository, 'git@github.com:youbeauty/youbuy.git'
  34. set :scm, :git
  35.  
  36. set :scm_verbose, true
  37. set :deploy_via, :remote_cache
  38. set :keep_releases, 5
  39.  
  40. set :use_sudo, false
  41.  
  42. set :stages, %w(staging production)
  43. set :default_stage, 'staging'
  44. set :normalize_asset_timestamps, false
  45. set :shared_children, %w(public/system log tmp/pids doc)
  46.  
  47. default_run_options[:pty] = true
  48. ssh_options[:forward_agent] = true
  49.  
  50. set :runner, user
  51.  
  52. set :whenever_identifier, defer { "#{application}_#{stage}" }
  53.  
  54.  
  55. after "deploy:restart", "deploy:cleanup"
  56. # after "deploy:update_code", "deploy:precompile_assets"
  57.  
  58.  
  59.  
  60.  
  61. namespace :deploy do
  62. desc "Copy config files"
  63. #
  64. after "deploy:update_code" do
  65. run "export RAILS_ENV=staging"
  66. run "ln -nfs #{shared_path}/public/assets #{release_path}/public/assets"
  67. run "ln -nfs #{shared_path}/public/spree #{release_path}/public/spree"
  68. # run "ln -nfs #{shared_path}/public/labels_shipment #{release_path}/public/labels_shipment"
  69. # run "ln -nfs #{shared_path}/public/shipment_labels #{release_path}/public"
  70. # run "ln -nfs #{shared_path}/public/product_data #{release_path}/public/product_data"
  71. # run "ln -nfs #{shared_path}/public/invoice #{release_path}/public/invoice"
  72. # run "ln -nfs #{shared_path}/doc/product_data #{release_path}/doc/product_data"
  73. # run "ln -nfs #{shared_path}/doc/product_data/ #{release_path}/doc/product_data/import_logs/"
  74.  
  75. run "ln -nfs #{shared_path}/log #{release_path}/log"
  76. run "ln -nfs #{shared_path}/tmp #{release_path}/tmp"
  77. run "cp -R #{shared_path}/config/database.yml #{release_path}/config/"
  78. run "cp -R #{shared_path}/config/environments/staging.rb #{release_path}/config/environments/staging.rb"
  79. sudo "chmod -R 0777 #{release_path}/tmp/"
  80. # sudo "chmod -R 0777 #{release_path}/public/labels_shipment"
  81. # sudo "chmod -R 0777 #{release_path}/public/spree/products"
  82. # sudo "chmod -R 0777 #{release_path}/public/product_data"
  83. # sudo "chmod -R 0777 #{release_path}/public/invoice"
  84. # sudo "chmod -R 0777 #{release_path}/doc/product_data"
  85. end
  86.  
  87. task :restart, :roles => :app, :except => { :no_release => true } do
  88. run "touch #{File.join(current_path,'tmp','restart.txt')}"
  89. end
  90.  
  91.  
  92. desc "Seed the database"
  93. task :seed, :roles => :db do
  94. # on_rollback { deploy.db.restore }
  95. run "cd #{current_path}"
  96. run "rake db:seed RAILS_ENV=staging"
  97. run "rake spree_sample:load RAILS_ENV=staging"
  98. end
  99.  
  100. desc 'run bundle install'
  101. task :bundle_install, :roles => :app do
  102. run "cd #{current_path} && bundle install --deployment --path #{shared_path}/bundle"
  103. end
  104.  
  105. desc "Reset the database"
  106. task :reset, :roles => :db do
  107. # on_rollback { deploy.db.restore }
  108. run "cd #{current_path}"
  109. run "rake db:migrate:reset RAILS_ENV=staging"
  110. end
  111.  
  112. # task :cleanup do
  113. # #do nothing
  114. # end
  115.  
  116. desc "Compile all the assets named in config.assets.precompile."
  117. task :precompile_assets do
  118. raise "Rails environment not set" unless rails_env
  119. task = "assets:precompile"
  120. run "cd #{release_path} && bundle exec rake #{task} RAILS_ENV=#{rails_env}"
  121. end
  122.  
  123. end
  124.  
  125. after "deploy:create_symlink", "deploy:bundle_install"
  126.  
  127. namespace :bundler do
  128. task :create_symlink, :roles => :app do
  129. shared_dir = File.join(shared_path, 'bundle')
  130. release_dir = File.join(current_release, '.bundle')
  131. run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
  132. end
  133.  
  134. task :bundle_new_release, :roles => :app do
  135. bundler.create_symlink
  136. run "cd #{release_path} && source $HOME/.bash_profile && bundle install"
  137. end
  138. end
  139.  
  140. #namespace :rvm do
  141. # task :trust_rvmrc do
  142. # run( "rvm rvmrc trust #{release_path}")
  143. # end
  144. #end
  145.  
  146.  
  147. desc "Dumps target database into development db"
  148. namespace :db do
  149. task :clone_to_local, :roles => [:db], :only => {:primary => true} do
  150. file = "#{application}.sql.bz2"
  151.  
  152. database = YAML::load_file('config/database.yml')
  153.  
  154. db_user = database[rails_env]['username']
  155. db_name = database[rails_env]['database']
  156.  
  157. local_db_user = database['development']['username']
  158. local_db_dev = database['development']['database']
  159.  
  160. run "pg_dump --clean --no-owner --no-privileges -U#{db_user} #{db_name} | bzip2 > #{file}" do |ch, stream, out|
  161. ch.send_data "#{db_password}\n" if out =~ /^Password:/
  162. puts out
  163. end
  164.  
  165. puts rsync = "rsync #{user}@#{db_host}:#{file} tmp"
  166. `#{rsync}`
  167. puts depackage = "bzcat tmp/#{file} | psql #{local_db_dev} -U#{local_db_user}"
  168. `#{depackage}`
  169. end
  170. end
  171.  
  172.  
  173. after 'deploy:finalize_update', 'bundler:bundle_new_release'
  174. #after "deploy", "rvm:trust_rvmrc"
Add Comment
Please, Sign In to add comment