Skip to content

Commit

Permalink
Replace deprecated Bundler.with_clean_env with with_unbundled_env
Browse files Browse the repository at this point in the history
Also add tests for `GEM_HOME` environment variable preserving.

Also drop `BUNDLE_GEMFILE` preserving, resolve puma#2133

Also disable local `path` for `bundle install` in CI,
it makes `nio4r` unavailable.

Also install (update) `bundler` in CI,
old versions are incompatible.
  • Loading branch information
AlexWayfer committed Mar 6, 2020
1 parent c87cff2 commit 54b516e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ruby.yml
Expand Up @@ -39,9 +39,10 @@ jobs:
if: matrix.ruby < '2.3'
run: |
gem update --system 2.7.10 --no-document
gem install bundler
- name: bundle install
run: bundle install --jobs 4 --retry 3 --path=.bundle/puma
run: bundle install --jobs 4 --retry 3
- name: compile
run: bundle exec rake compile

Expand Down Expand Up @@ -87,7 +88,7 @@ jobs:
ruby-version: ${{ matrix.ruby }}

- name: bundle install
run: bundle install --jobs 4 --retry 3 --path=.bundle/puma
run: bundle install --jobs 4 --retry 3

- name: compile
if: matrix.ruby >= '2.4'
Expand Down
1 change: 1 addition & 0 deletions History.md
Expand Up @@ -17,6 +17,7 @@
* Preserve `BUNDLE_GEMFILE` env var when using `prune_bundler` (#1893)
* Send 408 request timeout even when queue requests is disabled (#2119)
* Rescue IO::WaitReadable instead of EAGAIN for blocking read (#2121)
* Replace deprecated `Bundler.with_clean_env` with `with_unbundled_env` (#2120)

* Refactor
* Remove unused loader argument from Plugin initializer (#2095)
Expand Down
8 changes: 3 additions & 5 deletions lib/puma/launcher.rb
Expand Up @@ -297,11 +297,9 @@ def prune_bundler
deps, dirs = dependencies_and_files_to_require_after_prune

log '* Pruning Bundler environment'
home = ENV['GEM_HOME']
bundle_gemfile = ENV['BUNDLE_GEMFILE']
Bundler.with_clean_env do
ENV['GEM_HOME'] = home
ENV['BUNDLE_GEMFILE'] = bundle_gemfile
gem_home = ENV['GEM_HOME']
Bundler.with_unbundled_env do
ENV['GEM_HOME'] = gem_home
ENV['PUMA_BUNDLER_PRUNED'] = '1'
args = [Gem.ruby, puma_wild_location, '-I', dirs.join(':'), deps.join(',')] + @original_argv
# Ruby 2.0+ defaults to true which breaks socket activation
Expand Down
12 changes: 11 additions & 1 deletion test/bundle_preservation_test/config.ru
@@ -1 +1,11 @@
run lambda { |env| [200, {'Content-Type'=>'text/plain'}, [ENV['BUNDLE_GEMFILE'].inspect]] }
run(
lambda do |env|
[
200,
{'Content-Type'=>'text/plain'},
[
[ENV['BUNDLE_GEMFILE'], ENV['GEM_HOME']].inspect
]
]
end
)
11 changes: 8 additions & 3 deletions test/test_preserve_bundler_env.rb
Expand Up @@ -12,9 +12,12 @@ def test_usr2_restart_preserves_bundler_environment
skip_unless_signal_exist? :USR2

@tcp_port = UniquePort.call
gem_home = "/home/bundle_env_preservation_test"
bundle_gemfile = "Gemfile.bundle_env_preservation_test"
env = {
"GEM_HOME" => gem_home,
# Intentionally set this to something we wish to keep intact on restarts
"BUNDLE_GEMFILE" => "Gemfile.bundle_env_preservation_test",
"BUNDLE_GEMFILE" => bundle_gemfile,
# Don't allow our (rake test's) original env to interfere with the child process
"BUNDLER_ORIG_BUNDLE_GEMFILE" => nil
}
Expand All @@ -27,9 +30,11 @@ def test_usr2_restart_preserves_bundler_environment
@pid = @server.pid
connection = connect
initial_reply = read_body(connection)
assert_match("Gemfile.bundle_env_preservation_test", initial_reply)
refute_match(bundle_gemfile, initial_reply)
assert_match(gem_home, initial_reply)
restart_server connection
new_reply = read_body(connection)
assert_match("Gemfile.bundle_env_preservation_test", new_reply)
refute_match(bundle_gemfile, new_reply)
assert_match(gem_home, initial_reply)
end
end

0 comments on commit 54b516e

Please sign in to comment.