Skip to content

Commit

Permalink
reworked filtering rvm tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Aug 9, 2013
1 parent e2a0e48 commit b20fefb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
1 change: 1 addition & 0 deletions lib/eycap.rb
@@ -1,5 +1,6 @@
require 'eycap/lib/ey_logger'
require 'eycap/lib/ey_logger_hooks'
require 'eycap/lib/rvm_helper'
require 'eycap/recipes/apache'
require 'eycap/recipes/backgroundrb'
require 'eycap/recipes/bundler'
Expand Down
27 changes: 27 additions & 0 deletions lib/eycap/lib/rvm_helper.rb
@@ -0,0 +1,27 @@
Capistrano::Configuration.instance(:must_exist).load do

def reformat_code(code)
code.split("\n").map(&:strip).join("; ")
end

# Allow parallel execution of rvm and non rvm commands
def run_rvm_or(command_rvm, command_else = "true")
parallel do |session|
command_else = reformat_code(command_else)
rvm_role = fetch(:rvm_require_role)
if Capistrano.const_defined?(:RvmMethods)
# command_with_shell is defined in RvmMethods so rvm/capistrano has to be required first
command_rvm = command_with_shell(reformat_code(command_rvm), fetch(:rvm_shell))
if rvm_role # mixed
session.when "in?(:#{rvm_role})", command_rvm
session.else command_else
else # only rvm
session.else command_rvm
end
else # no rvm
session.else command_else
end
end
end

end
38 changes: 17 additions & 21 deletions lib/eycap/recipes/bundler.rb
Expand Up @@ -5,32 +5,28 @@
namespace :bundler do
desc "Automatically installed your bundled gems if a Gemfile exists"
task :bundle_gems, :roles => :app, :except => {:no_bundle => true} do
parallel do |session|
rvm_role = fetch(:rvm_require_role,"rvm")
if exists?(:rvm_shell)
session.when "in?(:#{rvm_role})", command_with_shell(<<-SHELL.split("\n").map(&:strip).join("; "), fetch(:rvm_shell))
if [ -f #{release_path}/Gemfile ]
then cd #{release_path} && bundle install --without=#{bundle_without} --system
fi
SHELL
end
session.else <<-SHELL.split("\n").map(&:strip).join("; ")
mkdir -p #{shared_path}/bundled_gems
if [ -f #{release_path}/Gemfile ]
then cd #{release_path} && bundle install --without=#{bundle_without} --binstubs #{release_path}/bin --path #{shared_path}/bundled_gems --quiet
fi
if [ ! -h #{release_path}/bin ]
then ln -nfs #{release_path}/bin #{release_path}/ey_bundler_binstubs
fi
SHELL
end
only_with_rvm = <<-SHELL
if [ -f #{release_path}/Gemfile ]
then cd #{release_path} && bundle install --without=#{bundle_without} --system
fi
SHELL
only_without_rvm = <<-SHELL
mkdir -p #{shared_path}/bundled_gems
if [ -f #{release_path}/Gemfile ]
then cd #{release_path} && bundle install --without=#{bundle_without} --binstubs #{release_path}/bin --path #{shared_path}/bundled_gems --quiet
fi
if [ ! -h #{release_path}/bin ]
then ln -nfs #{release_path}/bin #{release_path}/ey_bundler_binstubs
fi
SHELL
run_rvm_or only_with_rvm, only_without_rvm
end
task :bundle_config, :roles => :app, :only => {:no_bundle => true} do
<<-SHELL.split("\n").map(&:strip).join("; ")
run_rvm_or "true", <<-SHELL
bundle config --local BIN /data/#{application}/releases/#{release_path}/bin
bundle config --local PATH /data/#{application}/shared/bundled_gems
bundle config --local DISABLE_SHARED_GEMS "1"
bundle config --local WITHOUT test:development
bundle config --local WITHOUT test:development
SHELL
end
after "deploy:symlink_configs","bundler:bundle_gems"
Expand Down
14 changes: 4 additions & 10 deletions lib/eycap/recipes/rvm.rb
Expand Up @@ -10,16 +10,10 @@
fi
DESC
task :create_wrappers, :roles => :app, :except => {:no_bundle => true} do
parallel do |session|
rvm_role = fetch(:rvm_require_role,"rvm")
if exists?(:rvm_shell)
session.when "in?(:#{rvm_role})", command_with_shell(<<-SHELL.split("\n").map(&:strip).join("; "), fetch(:rvm_shell))
rvm alias create #{application} #{fetch(:rvm_ruby_string,nil)}
rvm wrapper #{application} --no-links --all
SHELL
end
session.else "true" # minimal NOOP
end
run_rvm_or <<-SHELL
rvm alias create #{application} #{fetch(:rvm_ruby_string,nil)}
rvm wrapper #{application} --no-links --all
SHELL
end

after "bundler:bundle_gems","rvm:create_wrappers"
Expand Down

0 comments on commit b20fefb

Please sign in to comment.