rails
rails copied to clipboard
Use `ruby file: ".ruby-version"` for new apps
Motivation / Background
Fixes #51014
Previously, new apps would have a Ruby version set in both the Gemfile and the .ruby-version file. This duplication makes it more difficult to quickly change an application's ruby version as users must remember to update multiple files.
Detail
This commit updates the app generator's Gemfile to read the Ruby version from the .ruby-version file. Since this feature was introduced in the latest version of Bundler, it will only be enabled if a supported version of Bundler is used.
Additional information
Alternatively, another solution mentioned on the original PR adding .ruby-version was that the .ruby-version file could be removed once rvm/rbenv support reading the Ruby version from the Gemfile. This has a downside that many other tools like chruby do not have plans to support reading a Ruby version from the Gemfile, and so users of those tools would have a worse experience if the .ruby-version file is removed.
Checklist
Before submitting the PR make sure the following are checked:
- [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
- [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex:
[Fix #issue-number]
- [x] Tests are added or updated if you fix a bug or add a feature.
- [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.
Drafted because rubygems/rubygems#6985 hasn't quite been released yet
@skipkayhil
bundle install
requires .ruby-version
, so you should modify the Dockerfile as well.
I think you should modify the following parts.
https://github.com/rails/rails/blob/d99e355390ec3abea129eed88f003ef2171c5177/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt#L42-L46
@skipkayhil
bundle install
requires.ruby-version
, so you should modify the Dockerfile as well. I think you should modify the following parts.https://github.com/rails/rails/blob/d99e355390ec3abea129eed88f003ef2171c5177/railties/lib/rails/generators/rails/app/templates/Dockerfile.tt#L42-L46
Indeed this is one of the caveats of .ruby-version
support in Bundler. It should be copied next to Gemfile
to production container even it's original purpose is mostly for development. :shrug:
Did you find a way to address the Dockerfile as well?
Yes I was wrapping it up yesterday, let me push it up
Edit: unless you mean can the Dockerfile also read the .ruby-version for the image version, in which case I have not addressed that
Also, do we need the version split if Ruby 3.1+ is now required?
Also, do we need the version split if Ruby 3.1+ is now required?
We do definitely need the split on using file:
since it was added in Bundler 2.4.20 and Ruby 3.1 ships with Bundler 2.3.3
Although I wonder if we couldn't just force Bundler 2.4+ with the install of Rails?
Also, shouldn't "ruby file: ".ruby-version"" just be the default in bundler?
@dhh this should be ready to go 👍