0

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

3 Answers 3

1

Have you tried using rbenv instead of rvm? I've seen where that has helped in other similar type issues.

1
  • 2
    Welcome to Stackoverflow and congrats for providing your first answer! :-) However, in this case I would not recommend swapping out the complete ruby backend of the project if everything else is working fine, especially if there is a way to get it work (just not the poster's preferred way). Let's try something more surgical for a start.
    – Jens
    Commented Sep 4, 2023 at 9:56
0

If it works fine using noninteractive ssh, but fails using interactive ssh, my first approach would be to compare both environments (PATH, gem path, other variables) and see if both bundler instances are called the same way.

Have a look at your init scripts (.profile, .bash_profile, .bashrc, and the respective files in /etc) and compare. Perhaps this way:

# print (non)interactive environment to file
$ ssh user@host "set > noninteractive.txt"
$ ssh user@host
user@host$ set > interactive.txt
user@host$ diff -u interactive.txt noninteractive.txt

Maybe this gives you a hint as to where to look. Probably the RVM environment is setup differently in both cases ...

0

As usual, the devil is in the details. Easy fix, once you know what to look for.

I mentioned that I was calling bundle install via: /usr/share/rvm/gems/ruby-2.7.8/bin/bundler install

Turns out, using the gem wrapper is the preferred method when calling bundler via cron or ssh, etc. The easy fix is: /usr/share/rvm/gems/ruby-2.7.8/wrappers/bundler install

I am trying to find a good explanation on the difference and what gem wrappers actually provide (I think more explicit paths)... but a simple path change solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.