Downgrade/Revert Ruby Version on Heroku - ruby-on-rails

I recently updated my Heroku app from Ruby 2.3.1 to 2.4.0, but I now need to revert back to version 2.3.1.
To Update:
I changed the version in the Gemfile from 2.3.1 to 2.4.0. Everything went fine, but I need to go back to 2.3.1 because of problems specific to me with 2.4.0
To Revert:
I've tried changing the version back to 2.3.1 in my Gemfile (as ruby "2.3.1") but it just throws the bundler error Your Ruby version is 2.4.0, but your Gemfile specified 2.3.1
How do I change my Ruby version back to 2.3.1 on Heroku?
Here is the error on deployment:
ID yupp
-----> heroku-buildpack-rgeo-prep app detected
-----> Removing cached .bundle/config
Writing new .bundle/config
-----> VendorBinaries app detected
-----> Found a .vendor_urls file
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.4.0
###### WARNING:
You have the `.bundle/config` file checked into your repository
It contains local state like the location of the installed bundle
as well as configured git local gems, and other settings that should
not be shared between multiple checkouts of a single repo. Please
remove the `.bundle/` folder from your repo and add it to your `.gitignore` file.
https://devcenter.heroku.com/articles/bundler-configuration
-----> Installing dependencies using bundler 1.13.7
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Warning: the running version of Bundler (1.13.7) is older than the version that created the lockfile (1.14.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Your Ruby version is 2.4.0, but your Gemfile specified 2.3.1
Bundler Output: Warning: the running version of Bundler (1.13.7) is older than the version that created the lockfile (1.14.3). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
Your Ruby version is 2.4.0, but your Gemfile specified 2.3.1
!
! Failed to install gems via Bundler.
! Detected a mismatch between your Ruby version installed and
! Ruby version specified in Gemfile or Gemfile.lock:
! https://devcenter.heroku.com/articles/ruby-versions#your-ruby-version-is-x-but-your-gemfile-specified-y
!
! Push rejected, failed to compile Ruby app.
! Push failed

I figured it out. Here are the steps
Locally:
Change the Ruby version from 2.4.0 to 2.3.1
Verify the version is 2.3.1 with ruby -v
Run gem install bundler && gem install rails
Run bundle install
Commit the Gemfile and Gemfile.lock and push to Heroku

Related

Deploy to dokku fails because of ruby-buildpack + bundler?

I'm deploying a rails app to dokku. The Versions are:
ruby 3.1.2
bundler 2.3.26 (on my development machine)
gem 3.3.22 (on my development machine)
when i try to deploy to dokku, the heroku ruby buildpack is used, and I get
the following output:
-----> Ruby app detected
-----> Installing bundler 2.2.21
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.1.2
-----> Installing dependencies using bundler 2.2.21
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
[330, #<Thread:0x00007fc0e8b43c90 run>, #<NameError: uninitialized constant Gem::Source
(defined?(#source) && #source) || Gem::Source::Installed.new
^
The crazy thing: I have another app with the same configuration where it works:
-----> Ruby app detected
-----> Installing bundler 2.2.21
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.1.2
-----> Installing dependencies using bundler 2.2.21
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
Fetching gem metadata from https://rubygems.org/.........
My research so far:
This seems to be the problem described here as an issue with bundler 2.3.7 first described in February 2022. But my buildpack uses bundler 2.2.21, so it should not be affected?
The newest ruby-buildpack from heroku seems to have been released in 2021?
Can this be right?
This fixed the problem for one app:
upgrade to ruby 3.1.3 (by editing ruby version in Gemfile and in .ruby-version)
bundle install
bundle lock --add-platform x86_64-linux
After one successfull install I could also roll back to the old ruby version, before upgrade, and successfully install that.
How? Why? What is going on here?
Now another app that used to work stopped working.
Purging the dokku build cache fixed the problem:
dokku repo:purge-cache
correction: this helped for some applications, not for all

Heroku Deployment - Rails 6.1.3 - Bundle install failing - Gemfile.lock platform addition

I am trying to deploy a simple Ruby on Rails web app using Heroku. When I attempt to deploy the web app, I get a bundler error saying the correct platform is not within the Gemfile.lock
Here is the build log:
-----> Building on the Heroku-20 stack
! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
Detected buildpacks: Ruby,Node.js
See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Ruby app detected
-----> Installing bundler 2.1.4
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-3.0.0
-----> Installing dependencies using bundler 2.1.4
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
Your bundle only supports platforms ["aarch64-linux"] but your local platform is
x86_64-linux. Add the current platform to the lockfile with `bundle lock
--add-platform x86_64-linux` and try again.
Bundler Output: Your bundle only supports platforms ["aarch64-linux"] but your local platform is
x86_64-linux. Add the current platform to the lockfile with `bundle lock
--add-platform x86_64-linux` and try again.
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
I attempted to add the platform to the Gemfile.lock file but was hit with this dependency error:
matt#matt-desktop:~/projects/auto-bags$ bundle lock --add-platform x86_64-linux
Fetching gem metadata from https://rubygems.org/............
Resolving dependencies.........
Bundler found conflicting requirements for the Ruby version:
In Gemfile:
Ruby (~> 3.0.0.0)
capybara (>= 3.26) was resolved to 3.35.3, which depends on
nokogiri (~> 1.8) was resolved to 1.11.1, which depends on
Ruby (< 3.1.dev, >= 2.5)
I have not found a successful fix online. There were some suggestions to remove the Gemfile.lock file but that broke my local server which makes sense. I'll be happy to provide more information if necessary.
running the following command should fix your issue.
bundle lock --add-platform x86_64-linux
bundle install
git add . ; git commit -m fix
Reference
https://www.moncefbelyamani.com/understanding-the-gemfile-lock-file/#platforms
https://bundler.io/man/gemfile.5.html#PLATFORMS
https://github.com/rubygems/rubygems/issues/4269#issuecomment-758564690

Deployment failed on heroku - Ruby on Rails

Im having a problem to deploy a new version of my Ruby on Rails app on heroku.
Heroku build log:
-----> Ruby app detected
-----> Installing bundler 2.0.2
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.6.6
Ruby version change detected. Clearing bundler cache.
Old: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
New:
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
/usr/bin/env: ‘bash’: Argument list too long
Bundler Output: /usr/bin/env: ‘bash’: Argument list too long
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
Important notes:
I haven't changed the Ruby version;
I've tryed to deploy another Ruby on Rails app, and realize that i'm not able to deploy any Ruby on Rails app.
Anyone with the same problem or any idea to help?
Apparently, the problem is related to a buildpack version released at July, 13. I solved the issue removing this update and specifying the version of Ruby buildpack
$ heroku buildpacks:remove heroku/ruby
and then
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-ruby#v217

Ruby 2.6.1 and Bundler 2.0.1 to Heroku : should I write a Procfile?

I'm facing errors I can't handle while trying to deploy an app to Heroku (it's my first time).
# ERROR when I try to `git push heroku master`
remote: -----> Detecting rake tasks
remote:
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! Activating bundler (2.0.1) failed:
remote: ! Could not find 'bundler' (2.0.1) required by your /tmp/build_e569680f858939ef8f1f8ef3e8902eff/Gemfile.lock.
remote: ! To update to the latest version installed on your system, run `bundle update --bundler`.
remote: ! To install the missing version, run `gem install bundler:2.0.1`
remote: ! Checked in 'GEM_PATH=/tmp/build_e569680f858939ef8f1f8ef3e8902eff/vendor/bundle/ruby/2.6.0', execute `gem env` for more information
remote: !
remote: ! To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'
# heroku buildpacks
=== staging-det-music Buildpack URLs
1. heroku/nodejs
2. heroku/ruby
# Gemfile.lock
RUBY VERSION
ruby 2.6.1p33
BUNDLED WITH
2.0.1
I've tried several solutions, like:
running RAILS_ENV=production bundle exec rake assets:precompile (see here)
adding the RAILS_SERVE_STATIC_FILES key (same)
upgrade Ruby to 2.6.3 (see here, can't find 2.6.3 with rbenv nor rvm)
I believe it might be due to this issue. Am I concerned by this point ?
2) When using binstubs to run a command instead of bundle exec the wrong
version of Bundler can get activated when using Ruby 2.6.x. This bug
is reported to Ruby Core and will be fixed when Ruby 2.6.3 is
released.
In the short term, the workaround is to ensure all commands in the
Procfile and app.json are prefaced with bundle exec. For example:
web: bundle exec bin/rails server -p $PORT -e $RAILS_ENV
worker: bundle exec sidekiq -C config/sidekiq.yml
As a newbie I feel really lost, could anyone help me on this ?
Thanks for your time
SOLUTION: found here removing BUNDLED WITH and the following line in Gemfile.lock
There are known issues with Bundler 2 on Heroku, including this one:
A Gemfile.lock that specifies bundler 2.0.2 does not work with bundler 2.0.1
If you attempt to deploy an app that uses bundler 2.0.2 onto the Heroku platform with bundler 2.0.1 you may get this error:
`find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
This is due to a bug in the Rubygems bundler version checking code. To avoid this issue, upgrade your Ruby version. It is fixed in 2.5.5+ and 2.6.3+. If you do not update, your Ruby version then every new release of Bundler 2.x will trigger this issue.
Upgrade Ruby to at least version 2.6.3 locally, update the ruby version in your Gemfile, bundle install, commit the changes, and redeploy.

Install local gems via bundle on heroku not working

I'm trying to install my app to heroku. But I'm having an issue with a gem. Its a private gem and we don't have a private gem server setup, so I've cloned the gem locally as a submodule inside the app.
When I push to heroku I get this error:
! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
Detected buildpacks: Ruby,Node.js
See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.5.1
-----> Installing dependencies using bundler 1.15.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.2). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
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.
The gemspecs for path gems changed
Bundler Output: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.2). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
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.
The gemspecs for path gems changed
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
When I removed the locally install gem it all worked fine.
So strong hunch is that bundler 1.15.2 handles local gems differently and it's causing a conflict.
In my Gemfile, not inside any group, I have gem 'portkey', path: './gems/portkey/'
At the top of my Gemfile.lock I have
PATH
remote: gems/portkey
specs:
portkey (0.1.10)
bitly
omniauth-google-oauth2 (~> 0.5.3)
rails (~> 5.2.1)
rebrandly
shortener (~> 0.8.0)
will_paginate
Heroku doesn't support bundler 1.16.2 yet afaik
I'm using rails 5/ruby-2.5 and I don't seem be able to downgrade bundler to 1.15.2 and generate an older version of the lockfile
I can't easily make this gem accessible any other way.
I'm stumped how I can make the install of this gem work, and suggestions would be greatly appreciated.
Had a similar issue, solved by upgrading to Bundler 2.0.1 (which is now supported by Heroku).
For 1.x version they still use 1.15.2 though.

Resources