Updated deploy.yml template to fetch the Ruby version automatically
Rails default Dockerfile requires the RUBY_VERSION argument. Kamal should have an example how to read the Ruby version automatically.
Hi Igor, great addition here! I ran into an additional step I had to work through to get this rolling and thought I'd share in case anyone else is in the same boat.
I had to make an additional change to my Dockerfile that copied the .ruby-version file over with the Gemfile so that it's available for bundler:
# Dockerfile
# Install application gems
COPY .ruby-version Gemfile Gemfile.lock ./
RUN bundle install && .....
This is because I use the following directive in my Gemfile:
# Gemfile
source "https://rubygems.org"
ruby file: ".ruby-version"
Yes, this probably should be added to the Rails default Dockerfile.
Happy to take a crack at that if you think it’d be useful.
I opened a PR as a jumping off point here: https://github.com/rails/rails/pull/53369
Rejected for now since the use of ruby file: .ruby-version is discouraged as a default by Rails. More info here:
https://github.com/rails/rails/issues/51089
I've always been wondering why do we need to duplicate the version of the interpreter in the Gemfile while we have it in the .ruby-version? The answer is pretty simple – we don't need to duplicate.
Just dropping this, despite agreeing we should have a common place to specify the ruby version, .ruby-version is not the only way to do it:
cat .tool-versions
ruby 3.3.3
nodejs 20.13.1
Gemfile already supports, so we can have:
ruby file: ".tool-versions"
So should we aim for the same? Here's the bundler implementation: https://github.com/rubygems/rubygems/blob/v3.5.22/bundler/lib/bundler/ruby_dsl.rb#L43