heroku / heroku-buildpack-ruby

Heroku's buildpack for Ruby applications.
MIT License
787 stars 1.87k forks source link

Support Bundler 2.4.20+ to enable `ruby file: '.ruby-version'` in Gemfile #1408

Open eliotsykes opened 9 months ago

eliotsykes commented 9 months ago

It'd be handy for the Heroku Ruby buildpack to enable using the ruby file: ... option in Gemfile by supporting Bundler 2.4.20.

This was introduced in Bundler 2.4.19:

ruby file: '.ruby-version'

Bundler 2.4.20 improved on this to support more formats, including .tool-versions:

ruby file: '.tool-versions'

Changelog entry: https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#2420-september-27-2023

dentarg commented 9 months ago

ruby File.read(".ruby-version") works well (if you didn't know)

eliotsykes commented 9 months ago

Thanks @dentarg 👍. Yes, I've used and liked that technique for some time too.

It works well for .ruby-version, although not so well for .tool-versions which requires a bit more work:

ruby(/^ruby\s(.*)$/.match(File.read(".tool-versions"))[1].strip)
schneems commented 9 months ago

Feature requests are the number 1 reason (after bug fixes) for us to rev the bundler version. So thanks for letting me know you want it!

As an FYI In the future https://github.com/heroku/buildpacks-ruby will eventually replace this buildpack (a long way off). It pulls the bundler version from the Gemfile.lock instead of using this "blessed" system, which I would like to move away from.

Timing-wise, I'm unsure when I'll be able to get this out. I'm mindful that a lot of companies have holidays coming up and a 1 in a million bug for bundler shows up pretty often for us (so I want to balance out stability, even if there's no known cause for concern).

To recap: Yes, I'll upgrade for sure. No commitment on the timeline, though.

janklimo commented 8 months ago

+1 for this. We recently switched to the new DSL in Gemfile but had to revert the change until the buildpack can support it. Thanks for looking into it @schneems!

dentarg commented 7 months ago

@schneems you might want to get to this before the next Rails release? If that release will include https://github.com/rails/rails/pull/49360

dentarg commented 6 months ago

Submitted ticket #1349048 to Heroku support about this

janklimo commented 5 months ago

I've verified deployment works now (using ruby file: '.tool-versions' in the Gemfile, Bundler 2.5.7). Looks like this can be closed.

erikaxel commented 5 months ago

We seem to still get errors when detecting rake tasks. Initially it is able to install all gems, but it fails on a later step.

remote: -----> Ruby app detected
remote: -----> Installing bundler 2.5.6
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.2.2
remote: -----> Installing dependencies using bundler 2.5.6

#snip: Removed a lot of gem install lines

remote:        Bundle completed (88.59s)
remote:        Cleaning up the bundler cache.
remote:        Removing bundler (2.5.6)
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:  !     /tmp/build_91067714/vendor/ruby-3.2.2/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your Ruby version is 3.2.2, but your Gemfile specified  (Bundler::RubyVersionMismatch)

bundle exec rake -P works fine locally.

dentarg commented 4 months ago

@schneems I think this issue can be closed now