dockerfile-rails
dockerfile-rails copied to clipboard
Use `.tool-versions` file from `asdf` for node (and other tool) version detection
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
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?
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.