kamal icon indicating copy to clipboard operation
kamal copied to clipboard

Updated deploy.yml template to fetch the Ruby version automatically

Open igor-alexandrov opened this issue 1 year ago • 7 comments

Rails default Dockerfile requires the RUBY_VERSION argument. Kamal should have an example how to read the Ruby version automatically.

igor-alexandrov avatar Oct 12 '24 17:10 igor-alexandrov

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"

kylekeesling avatar Oct 15 '24 19:10 kylekeesling

Yes, this probably should be added to the Rails default Dockerfile.

igor-alexandrov avatar Oct 16 '24 05:10 igor-alexandrov

Happy to take a crack at that if you think it’d be useful.

kylekeesling avatar Oct 16 '24 10:10 kylekeesling

I opened a PR as a jumping off point here: https://github.com/rails/rails/pull/53369

kylekeesling avatar Oct 18 '24 19:10 kylekeesling

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

kylekeesling avatar Oct 18 '24 21:10 kylekeesling

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.

igor-alexandrov avatar Oct 19 '24 07:10 igor-alexandrov

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

fidalgo avatar Oct 19 '24 09:10 fidalgo