namespace :bundler do desc <<-DESC Install the current Bundler environment. By default, gems will be \ installed to the shared/bundle path. Gems in the development and \ test group will not be installed. The install command is executed \ with the --deployment and --quiet flags. By default, bundler will not be run on servers with no_release: true. You can override any of these defaults by setting the variables shown below. set :bundle_roles, :all set :bundle_servers, -> { release_roles(fetch(:bundle_roles)) } set :bundle_binstubs, -> { shared_path.join('bin') } set :bundle_gemfile, -> { release_path.join('Gemfile') } set :bundle_path, -> { shared_path.join('bundle') } set :bundle_without, %w{development test}.join(' ') set :bundle_flags, '--deployment --quiet' set :bundle_jobs, nil set :bundle_env_variables, {} set :bundle_clean_options, "" DESC task :install do on fetch(:bundle_servers) do within release_path do with fetch(:bundle_env_variables) do options = [] options << "--gemfile #{fetch(:bundle_gemfile)}" if fetch(:bundle_gemfile) options << "--path #{fetch(:bundle_path)}" if fetch(:bundle_path) if fetch(:bundle_check_before_install) && test(:bundle, :check, *options) info "The Gemfile's dependencies are satisfied, skipping installation" else options << "--binstubs #{fetch(:bundle_binstubs)}" if fetch(:bundle_binstubs) options << "--jobs #{fetch(:bundle_jobs)}" if fetch(:bundle_jobs) options << "--without #{fetch(:bundle_without)}" if fetch(:bundle_without) options << "#{fetch(:bundle_flags)}" if fetch(:bundle_flags) execute :bundle, :install, *options end end end end end desc <<-DESC Maps all binaries to use `bundle exec` by default. Add your own binaries to the array with the command shown below. set :bundle_bins, fetch(:bundle_bins) + %w(my_new_binary) DESC task :map_bins do fetch(:bundle_bins).each do |command| SSHKit.config.command_map.prefix[command.to_sym].push("bundle exec") end end desc "Remove unused gems installed by bundler" task :clean do on fetch(:bundle_servers) do within release_path do with fetch(:bundle_env_variables) do execute :bundle, :clean, fetch(:bundle_clean_options) end end end end end Capistrano::DSL.stages.each do |stage| after stage, 'bundler:map_bins' end namespace :load do task :defaults do set :bundle_bins, %w{gem rake rails} set :bundle_roles, :all set :bundle_servers, -> { release_roles(fetch(:bundle_roles)) } set :bundle_binstubs, nil set :bundle_gemfile, nil set :bundle_path, -> { shared_path.join('bundle') } set :bundle_without, %w{development test}.join(' ') set :bundle_flags, '--deployment --quiet' set :bundle_jobs, 4 set :bundle_env_variables, {} set :bundle_clean_options, "" set :bundle_check_before_install, true end end