BUNDLE_APP_CONFIG
env var not available during bundler/setup
run (RUBYOPT="-rbundler/setup")
#6667
Comments
Hei! This looks the same as puma/puma#1593? I tried to reproduce it, but couldn't... 😞 One question though, does it get fixed if you change https://github.com/puma/puma/blob/395337df4a3b27cc14eeab048016fb1ee85d2f83/lib/puma/launcher.rb#L267 to use |
That's it! Changing that line in the Puma gem's launcher.rb fixed the problem. Now, the list of environment variables is (as printed in
Thanks you very much @deivid-rodriguez for pointing out that the problem is with Puma. I was looking for all usages of I am surprised that you were not able to reproduce it. I am not doing anything out of the ordinary. My usage is as vanilla as it can be. Please let me know if you need any other information from me. And let me know if I should close this issue and add on to issue 1593 in Puma? |
I'm glad it works for you! I was also surprised that I couldn't reproduce. If my blind guess didn't work I was going to ask you, where does the "bundler/setup" causing the issue gets added to Regarding the |
I thought the |
You're right, |
I have asked this same question on SO too: https://stackoverflow.com/questions/51879025/starting-puma-w-o-bundle-exec-works-doesnt-work-with-bundle-exec-bundle-app . I haven't received any response yet. So, I am reproducing it here, hoping for more relevant eyes on it.
I have created a docker container with a Rails 5.2 app. The Dockerfile is here: https://pastebin.com/T1hjYtJ8 . The compose file is here: https://pastebin.com/VEJBT8ZK . They may not be strictly relevant to this question, but still I am giving links to the configs, just in case. It is a pretty standard Dockerfile and compose file.
The
puma.rb
used in the app is shown here: https://pastebin.com/ic9ig3bC .When I create the container, puma is executed as
bundle exec puma -C config/puma.rb
. The puma process throws errors in thepuma_error.log
file:It is saying that it cannot find some gem. That gem happens to be a testing gem. But I am starting the puma process with my environment set to
staging
. All the required environment variables are set correctly. The output ofenv
in the container is shown below:So, I do not understand why bundler setup is trying to load the development and testing gems.
If I run the puma process without the "bundle exec", like so:
puma -C config/puma.rb
, then the app works! Comparing the differences between having and not having the "bundle exec", I noticed that the problem was theRUBYOPT="-rbundler/setup"
environment variable, which gets set bybundle exec
.For some reason, the bundler setup process is trying to load my development and testing gems.
After more debugging, I have narrowed down the problem to this: there is a
BUNDLE_APP_CONFIG
environment variable set to/usr/local/bundle/
by the base Ruby docker image. All my gems are also installed to this folder. The bundler config is also in this folder (this config file has the all-important--without
/BUNDLE_WITHOUT: "development:test"
setting). Bundler is supposed to read thisBUNDLE_APP_CONFIG
environment variable to find the config file. But this environment variable is not available whenbundler/setup
is running! So, bundler ends up using a default config, which loads gems from all groups (default, development and test).To investigate this, I added the following line in
/usr/local/lib/ruby/site_ruby/2.5.0/bundler/setup.rb
:puts "++++++++++ In setup.rb = All ENV variables: #{ENV.to_h}."
The output is below (in
puma_access.rb
):You will notice that the
BUNDLE_APP_CONFIG
environment variable is missing from this list. You will notice that this ENV var IS available in the shell (output ofenv
). It is also available if I runbundle exec env
.Why is this environment variable being removed during the
bundler/setup
run? I am assuming that this removal is being done by bundler, but I may be wrong. I am not able to find where it is being removed.Any help would be appreciated. Thank you!
The output of
bundle env
is attached.bundle_env.txt
The text was updated successfully, but these errors were encountered: