Module: Capistrano::NewArtrailsCapistrano::Helpers
- Defined in:
- lib/capistrano/new_artrails_capistrano/helpers.rb
Instance Method Summary collapse
- #backend_branch ⇒ Object
- #backend_local_cache ⇒ Object
- #backend_revision ⇒ Object
- #copy_command ⇒ Object
- #dir_exists?(path) ⇒ Boolean
- #file_exists?(path) ⇒ Boolean
- #new_artrails_capistrano_detect_manifest_path ⇒ Object
- #new_artrails_capistrano_run(cmd, options = {}, &block) ⇒ Object
- #new_artrails_capistrano_run_with_rvm_in_release_path(cmd, options = {}, &block) ⇒ Object
- #new_artrails_capistrano_sudo_as ⇒ Object
- #rsync_remote_cache ⇒ Object
Instance Method Details
#backend_branch ⇒ Object
6 7 8 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 6 def backend_branch fetch(:branch) || 'master' end |
#backend_local_cache ⇒ Object
14 15 16 17 18 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 14 def backend_local_cache application = fetch(:application) # "-#{fetch(:stage)}" fetch(:local_cache) || "/tmp/.#{application}_rsync_cache" end |
#backend_revision ⇒ Object
10 11 12 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 10 def backend_revision @backend_revision ||= `git ls-remote #{fetch(:repo_url)} #{backend_branch}`.split("\t").first end |
#copy_command ⇒ Object
32 33 34 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 32 def copy_command "rsync -a --no-p --no-g --delete" end |
#dir_exists?(path) ⇒ Boolean
28 29 30 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 28 def dir_exists?(path) test "[ -d #{path} ]" end |
#file_exists?(path) ⇒ Boolean
24 25 26 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 24 def file_exists?(path) test "[ -e #{path} ]" end |
#new_artrails_capistrano_detect_manifest_path ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 40 def new_artrails_capistrano_detect_manifest_path %w( .sprockets-manifest* manifest*.* ).each do |pattern| candidate = release_path.join('public', fetch(:assets_prefix), pattern) return capture(:ls, candidate).strip.gsub(/(\r|\n)/,' ') if test(:ls, candidate) end msg = 'Rails assets manifest file not found.' warn msg # Rails 5 only # fail Capistrano::FileNotFound, msg end |
#new_artrails_capistrano_run(cmd, options = {}, &block) ⇒ Object
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 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 67 def new_artrails_capistrano_run(cmd, ={}, &block) if cmd.include?('db:migrate') c = cmd.split(';') c.each_index do |index| if c[index].strip[0..4].include?('rake ') && c[index].include?('db:migrate') c[index] = " sudo -i -u #{new_artrails_capistrano_sudo_as} " + c[index] end end cmd = c.join(';') end if cmd.include?('find') cmd = "sudo -u #{new_artrails_capistrano_sudo_as} " + cmd end if cmd.strip[0..3] != 'pwd ' && !cmd.include?( 'sudo' ) && !cmd.include?( 'chmod +r+w+x' ) && !cmd.include?( 'chmod g+w' ) && !cmd.include?( 'chgrp -R mongrel' ) && !cmd.include?( 'find' ) if !cmd.include?( ' && (' ) && !cmd.include?( 'sh -c' ) cmd = cmd.gsub( /\s&&\s/, " && sudo -i -u #{new_artrails_capistrano_sudo_as} " ) end if !cmd.include?(' | (') && !cmd.include?('sh -c') cmd = cmd.gsub(/\s\|\s/, " | sudo -i -u #{new_artrails_capistrano_sudo_as} ") end cmd = "sudo -i -u #{new_artrails_capistrano_sudo_as} " + cmd end execute(cmd, , &block) end |
#new_artrails_capistrano_run_with_rvm_in_release_path(cmd, options = {}, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 54 def new_artrails_capistrano_run_with_rvm_in_release_path(cmd, ={}, &block) joined_cmd =<<-CMD sudo -iu #{fetch(:new_artrails_capistrano_sudo_as)} sh -c " source\\\\ '/usr/local/rvm/scripts/rvm' && cd #{fetch(:release_path)} && RAILS_ENV=#{fetch(:rails_env)} #{cmd} " CMD new_artrails_capistrano_run(joined_cmd.gsub(/\r?\n/, '').gsub(/\s+/, ' '), ) do block.call end end |
#new_artrails_capistrano_sudo_as ⇒ Object
20 21 22 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 20 def new_artrails_capistrano_sudo_as "#{fetch(:new_artrails_capistrano_sudo_as)}" || 'deploy' end |
#rsync_remote_cache ⇒ Object
36 37 38 |
# File 'lib/capistrano/new_artrails_capistrano/helpers.rb', line 36 def rsync_remote_cache fetch(:remote_cache) || "shared/cached-copy-#{fetch(:local_user) || 'deploy'}" end |