Heroku rails deployment issues - ruby-on-rails

I'm trying to push my rails app to deployment via Heroku and whenever i do, i'm getting thrown this error:
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-2.7.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
/usr/bin/env: ‘jruby’: No such file or directory
Bundler Output: /usr/bin/env: ‘jruby’: No such file or directory
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app.
! Push failed
Jruby seems to be playing into this somewhere but i just can't figure it out. Any help would be appreciated.

Answer has been solved as of today. The problem was that somewhere along the line, jruby got included in the list of gem dependencies and snowballed into everything else. In order to fix the problem, I needed to remove all instances of jruby from all folders within the app and it was able to compile properly and deploy.

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

Heroku uses older Ruby version when running `bundle install`

I'm trying to run a Rails app on Ruby 2.7.1 on Heroku. Everything worked fine, then I changed something in my Gemfile to use Ruby 2.7's numbered parameters, and now the deploy fails with this error message:
remote: -----> Build succeeded!
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.0.2
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote:
remote: !
remote: ! There was an error parsing your Gemfile, we cannot continue
remote: !
remote: ! [!] There was an error parsing `Gemfile`: Undefined local variable or method `_1' for Gemfile. Bundler cannot continue.
remote: !
remote: ! # from /tmp/build_6681cf5c/Gemfile:22
remote: ! # -------------------------------------------
remote: ! # dependencies.any? { _1.name == gem_name }
remote: ! # -------------------------------------------
remote: ! . Bundler cannot continue.
It works fine locally and I've been using the same code in a few other Rails apps and deployment was never a problem.
Due to the error Undefined local variable or method '_1' for Gemfile. I assume a Ruby version < 2.7 is used when running bundle install.
The app itself runs fine on Ruby 2.7.1 though:
$ heroku run "ruby -v"
Running ruby -v on ⬢ myapp... up, run.7979 (Free)
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
There are a few other similar questions here on SO, but they all deal with Heroku not respecting the Ruby version set in Gemfile or .ruby-version, which is not the problem for me, just during bundle install it seems to use a different Ruby version for some reason...
Is there any way to debug this further, or force Ruby 2.7 even during bundle install on deployment?

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

Heroku Rails deployment/build error: Could not find 'bundler' (version) required by your Gemfile.lock

I have a Ruby on Rails and Redux/React app I have already pushed dozens of times to heroku via "git push heroku master" and it builds correctly. I recently tried to create a staging environment. After setting the remote, I run
git push staging master
And the webpack portion builds correctly, but once Heroku tries to build the Rails portion I get this error.
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_687b8b1cf6d6cbb297288640ccb0d405/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=vendor/bundle/ruby/2.5.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'`
To create the staging environment, I ran
heroku create --remote staging
in the root folder of the project.
I also have tried updating the bundler.
bundle update --bundler
&
gem install bundler:2.0.1
I tried precompiling assets as well, but nothing.
RAILS_ENV=production bundle exec rake assets:precompile
I ran
bundle exec rake -P
as suggested, but that did not fix it as well.
Another thing is when I push successfully, in the logs it shows I am using a different ruby version
Using Ruby version: ruby-2.3.4
remote: -----> Installing dependencies using bundler 2.0.2
In the staging logs it shows
Using Ruby version: ruby-2.5.5
remote: -----> Installing dependencies using bundler 2.0.2
Not sure if that helps. But any possible solutions can help!
Thanks!
The solution to issues like these it to ensure all environments (development, staging, production, CI) share the same Ruby version. This will make development and testing much more predictable.
Specify your Ruby version in the Gemfile (this build worked with Ruby 2.3.4, so that's what we'll use):
# Gemfile
ruby '2.3.4'

Resources