diff options
author | Marco Costa <mmarcottulio@gmail.com> | 2019-01-08 17:52:06 -0500 |
---|---|---|
committer | Yuji Yaginuma <yuuji.yaginuma@gmail.com> | 2019-01-09 07:52:06 +0900 |
commit | d79366b4c9619e70a2c292b3a7c0311618eba9be (patch) | |
tree | 5c1c65acc7930c9432d819a87b6e47c6de3a75b9 /railties/lib/rails | |
parent | 80c7038bbc8e83762f4396b18260f470d8621995 (diff) | |
download | rails-d79366b4c9619e70a2c292b3a7c0311618eba9be.tar.gz rails-d79366b4c9619e70a2c292b3a7c0311618eba9be.tar.bz2 rails-d79366b4c9619e70a2c292b3a7c0311618eba9be.zip |
Preserve Bundle configuration during app generation (#34755)
When generating a new rails application (rails new) using a custom template that
includes gems from an authenticated source, the user has to provide credentials to
bundler.
One way to do this is by exporting environment variables, for example:
export BUNDLE_GITHUB__COM=user:pass: provides credentials for bundler to fetch
gems from github.com.
The problem this PR addresses is that we are currently scrubs all /BUNDLE_.*/
environment variables by wrapping our system calls in Bundler.with_clean_env.
We do this because we don't want our commands executed against the generated project
to use the generator's bundler environment (e.g. our gems): the generated project should
use it's own configuration.
The problem with Bundler.with_clean_env is that, on top of restoring environment
variables to their original state, it also scrubs any /BUNDLE_.*/ variables, which is harmful for authenticated gem sources.
This PR replaces Bundler.with_clean_env with Bundler.with_original_env, which only
restores environment variables to their initial state, without additional scrubbing.
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/generators/app_base.rb | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 3778690ef6..8df2b32dd2 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -388,19 +388,21 @@ module Rails # its own vendored Thor, which could be a different version. Running both # things in the same process is a recipe for a night with paracetamol. # - # We unset temporary bundler variables to load proper bundler and Gemfile. - # # Thanks to James Tucker for the Gem tricks involved in this call. _bundle_command = Gem.bin_path("bundler", "bundle") require "bundler" - Bundler.with_clean_env do - full_command = %Q["#{Gem.ruby}" "#{_bundle_command}" #{command}] - if options[:quiet] - system(env, full_command, out: File::NULL) - else - system(env, full_command) - end + Bundler.with_original_env do + exec_bundle_command(_bundle_command, command, env) + end + end + + def exec_bundle_command(bundle_command, command, env) + full_command = %Q["#{Gem.ruby}" "#{bundle_command}" #{command}] + if options[:quiet] + system(env, full_command, out: File::NULL) + else + system(env, full_command) end end |