I'm having trouble with bundler deploying to our servers after a recent ruby/gems upgrade. Despite hours of Googling, I can't figure out what's going on.
bundle install
on development like usual, commit Gemfile and Gemfile.lock to github- Run the deploy script from the server fetches the new github code, runs
bundle install
, and restarts the server all runs perfectly. New gems are loaded just like it should. - BUT running the exact same deploy script via non-interactive ssh fails with the error:
Bundler::ProductionError: You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
If this is a development machine, remove the /srv/code/Gemfile freeze
by running `bundle config unset deployment`.
The list of sources changed
This leads me to believe that rvm isn't initializing as it should in the non-interactive shell.
What I've Tried
- Resetting the default rvm version to the current ruby version (2.7.8)
- running
. /etc/profile.d/rvm.sh
at the top of the deploy script to initialize rvm correctly
More Details .bundle/config
BUNDLE_DEPLOYMENT: "true"
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "onsite:development:test"
deploy script
git fetch --all
git reset --hard origin/production
. /etc/profile.d/rvm.sh
/usr/share/rvm/gems/ruby-2.7.8/bin/bundler install
This all happened after a ruby upgrade to 2.7.8. As part of that upgrade the nokogiri gem was updated as well to 1.15.4. Based on some recommendations, I added linux to the Gemfile platforms via bundle lock --add-platform x86_64-linux
My guess is it all has something to do with this... maybe.
The Gemfile.lock includes:
PLATFORMS
ruby
x86_64-darwin-20
x86_64-linux
My biggest confusion is why it works perfectly when run via bash
ssh [email protected]
/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb
but fails when run non-interactively via
ssh [email protected] '/usr/share/rvm/rubies/ruby-2.7.8/bin/ruby /path_to_script/deploy.rb
And for reference: Bundler version 2.4.18 RoR 4.2.11.34 (Rails LTS) Ruby 2.7.8