dockerfile-rails icon indicating copy to clipboard operation
dockerfile-rails copied to clipboard

Use `.tool-versions` file from `asdf` for node (and other tool) version detection

Open olbrich opened this issue 1 year ago • 2 comments

https://github.com/rubys/dockerfile-rails/blob/718a4ad457d4a1330cc39788bdf55a07531adbbd/lib/generators/dockerfile_generator.rb#L712

.tool-versions may also contain information about ruby, yarn, and python, java, awscli, azure-cli, elixir, etc.. versions formatted like...

ruby 3.2.0
nodejs 19.6.0
yarn 1.22.19
python 3.10.7 2.7.18

olbrich avatar Mar 07 '23 13:03 olbrich

Looks like tool versions not only have multiple versions, but also comments. The following should grab only the first version:

IO.read('.tool-versions').scan(/^(\w+)\s+(\d+\.\d+\.\d+)/).to_h

Then there is the question of precedence. If there is a .ruby-version and a .tool-versions file present, which one should be used? My initial leanings are to take the more specific one first.

Finally, if there is a .tool-versions file, dockerfile-rails should NOT write out a redundant .node-versions file.

Sound about right?

rubys avatar Mar 07 '23 14:03 rubys

Sounds about right... I also found this spec for the file format.

I would not write out the .node-versions file if a .tool-versions file exists.

It also looks like asdf will fall back to reading a .ruby-version file if configured to do so, or .nvmrc or .node-versions. See nodejs plugin.

For the ruby version, I'd probably use whatever version the Gemfile.lock specifies, for node, I'd probably raise an error if both a .tool-versions file and a .node-versions file existed and the versions didn't match.

olbrich avatar Mar 12 '23 02:03 olbrich