From f2e42f695e82a2cebd811f41a12f5e585270f4d2 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Tue, 19 Nov 2013 17:04:44 +0100 Subject: [PATCH] changed all bundler options to be optional setting one of the options to a nil-value will exclude it from the final bundler command --- README.md | 47 +++++++++++++++++++++----------- lib/capistrano/tasks/bundler.cap | 40 +++++++++++++++++---------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 944c229e..73f274a8 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@ # Capistrano::Bundler -Bundler for support for Capistrano 3.x +Bundler specific tasks for Capistrano v3: + + * cap production bundler:install + +It also prefixes certain binaries to use `bundle exec`. ## Installation Add this line to your application's Gemfile: - gem 'capistrano', '~> 3.0.0' + gem 'capistrano', '~> 3.0' gem 'capistrano-bundler' And then execute: @@ -23,25 +27,36 @@ Require in `Capfile` to use the default task: require 'capistrano/bundler' -The task will run before `deploy:updated` as part of Capistrano's default deploy, -or can be run in isolation with `cap production bundler:install` - -Configurable options, shown here with defaults: +The task will run before `deploy:updated` as part of Capistrano's default deploy, or can be run in isolation with `cap production bundler:install` - set :bundle_gemfile, -> { release_path.join('Gemfile') } - set :bundle_dir, -> { shared_path.join('bundle') } - set :bundle_flags, '--deployment --quiet' - set :bundle_without, %w{development test}.join(' ') - set :bundle_binstubs, -> { shared_path.join('bin') } - set :bundle_roles, :all - set :bundle_bins, %w(gem rake rails) - -By default, the plugin adds `bundle exec` prefix to common executables listed in `bundle_bins` option. You can add any custom executable to this list: +By default, the plugin adds `bundle exec` prefix to common executables listed in `bundle_bins` option. This currently applies for `gem`, `rake` and `rails`. +You can add any custom executable to this list: ```ruby -set :bundle_bins, fetch(:bundle_bins).push %w(my_new_binary) +set :bundle_bins, fetch(:bundle_bins, []).push %w(my_new_binary) ``` +Configurable options: + + set :bundle_roles, :all # this is default + set :bundle_binstubs, -> { shared_path.join('bin') } # this is default + set :bundle_gemfile, -> { release_path.join('MyGemfile') } # default: nil + set :bundle_path, -> { shared_path.join('bundle') } # this is default + set :bundle_without, %w{development test}.join(' ') # this is default + set :bundle_flags, '--deployment --quiet' # this is default + +This would execute the following bundle command on all servers +(actual paths depend on the real deploy directory): + + bundle install \ + --binstubs /my_app/shared/bin \ + --gemfile /my_app/releases/20130623094732/MyGemfile \ + --path /my_app/shared/bundle \ + --without development test \ + --deployment --quiet + +If any option is set to `nil` it will be excluded from the final bundle command. + ## Contributing 1. Fork it diff --git a/lib/capistrano/tasks/bundler.cap b/lib/capistrano/tasks/bundler.cap index f552e022..3239da32 100644 --- a/lib/capistrano/tasks/bundler.cap +++ b/lib/capistrano/tasks/bundler.cap @@ -7,25 +7,35 @@ namespace :bundler do You can override any of these defaults by setting the variables shown below. + set :bundle_roles, :all + + set :bundle_binstubs, -> { shared_path.join('bin') } set :bundle_gemfile, -> { release_path.join('Gemfile') } - set :bundle_dir, -> { shared_path.join('bundle') } - set :bundle_flags, '--deployment --quiet' + set :bundle_path, -> { shared_path.join('bundle') } set :bundle_without, %w{development test}.join(' ') - set :bundle_binstubs, -> { shared_path.join('bin') } - set :bundle_roles, :all + set :bundle_flags, '--deployment --quiet' DESC task :install do on roles fetch(:bundle_roles) do within release_path do - execute :bundle, "--gemfile #{fetch(:bundle_gemfile)}", - "--path #{fetch(:bundle_dir)}", - fetch(:bundle_flags), - "--binstubs #{fetch(:bundle_binstubs)}", - "--without #{fetch(:bundle_without)}" + options = ["install"] + options << "--binstubs #{fetch(:bundle_binstubs)}" if fetch(:bundle_binstubs) + options << "--gemfile #{fetch(:bundle_gemfile)}" if fetch(:bundle_gemfile) + options << "--path #{fetch(:bundle_path)}" if fetch(:bundle_path) + options << "--without #{fetch(:bundle_without)}" if fetch(:bundle_without) + options << "#{fetch(:bundle_flags)}" if fetch(:bundle_flags) + + execute :bundle, options 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).push %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") @@ -41,12 +51,12 @@ end namespace :load do task :defaults do - set :bundle_gemfile, -> { release_path.join('Gemfile') } - set :bundle_dir, -> { shared_path.join('bundle') } - set :bundle_flags, '--deployment --quiet' - set :bundle_without, %w{development test}.join(' ') - set :bundle_binstubs, -> { shared_path.join('bin') } - set :bundle_roles, :all set :bundle_bins, %w{gem rake rails} + + set :bundle_roles, :all + set :bundle_binstubs, -> { shared_path.join('bin') } + set :bundle_path, -> { shared_path.join('bundle') } + set :bundle_without, %w{development test}.join(' ') + set :bundle_flags, '--deployment --quiet' end end