Skip to content

Commit

Permalink
changed all bundler options to be optional
Browse files Browse the repository at this point in the history
setting one of the options to a nil-value will exclude it from the final
bundler command
  • Loading branch information
Kriechi committed Nov 29, 2013
1 parent f1bd207 commit f2e42f6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 31 deletions.
47 changes: 31 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
40 changes: 25 additions & 15 deletions lib/capistrano/tasks/bundler.cap
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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

0 comments on commit f2e42f6

Please sign in to comment.