From 18c8385b6d1bacd56bfedf8850b722a1b23ff15d Mon Sep 17 00:00:00 2001 From: PJ Kelly Date: Wed, 11 Dec 2013 09:06:13 -0800 Subject: [PATCH] Allow for specification of environment variables when bundle-ing via the `bundle_env_variables` configuration option. --- CHANGELOG.md | 1 + README.md | 10 ++++++++++ lib/capistrano/tasks/bundler.cap | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cc78b60..702ae06b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # future release +* Added `bundle_env_variables` option for specifying environment variables that should be set when running `bundle`. * The `bundle_dir` option is now named `bundle_path` * Use `bundle install` instead of `bundle` * All options are now optional and can be excluded from the final bundle command by setting them to `nil` diff --git a/README.md b/README.md index 73f274a8..aa08151d 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Configurable options: 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 + set :bundle_env_variables, {} # this is default This would execute the following bundle command on all servers (actual paths depend on the real deploy directory): @@ -57,6 +58,15 @@ This would execute the following bundle command on all servers If any option is set to `nil` it will be excluded from the final bundle command. +### Environment Variables + +The `bundle_env_variables` option can be used to specify any environment variables you want present when running the `bundle` command: + +```ruby +# This translates to NOKOGIRI_USE_SYSTEM_LIBRARIES=1 when executed +set :bundle_env_variables, { nokogiri_use_system_libraries: 1 } +``` + ## Contributing 1. Fork it diff --git a/lib/capistrano/tasks/bundler.cap b/lib/capistrano/tasks/bundler.cap index 3239da32..cd834078 100644 --- a/lib/capistrano/tasks/bundler.cap +++ b/lib/capistrano/tasks/bundler.cap @@ -14,18 +14,21 @@ namespace :bundler do set :bundle_path, -> { shared_path.join('bundle') } set :bundle_without, %w{development test}.join(' ') set :bundle_flags, '--deployment --quiet' + set :bundle_env_variables, {} DESC task :install do on roles fetch(:bundle_roles) do within release_path do - 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 + with fetch(:bundle_env_variables, {}) do + 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 end