Skip to content

Commit

Permalink
Fix parsing ruby version for Dockerfile packages
Browse files Browse the repository at this point in the history
Previously, the version regular expressions never matched
Gem.ruby_version because Gem::Version is not a string. In addition,
ruby_version was undefined and this was not caught before because the
case statement never evaluated those branches.

This commit fixes both of those issues, so that ruby versions like 2.7.0
will correctly install "python" instead of "python-is-python3"
  • Loading branch information
skipkayhil committed Feb 23, 2023
1 parent ee6a7ba commit 95b3b31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions railties/lib/rails/generators/app_base.rb
Expand Up @@ -520,11 +520,11 @@ def dockerfile_build_packages
# how python is installed with the bullseye release. Below
# is based on debian release included with the Ruby images on
# Dockerhub.
case Gem.ruby_version
when /^2.7/
bullseye = ruby_version >= "2.7.4"
when /^3.0/
bullseye = ruby_version >= "3.0.2"
case Gem.ruby_version.to_s
when /^2\.7/
bullseye = Gem.ruby_version >= "2.7.4"
when /^3\.0/
bullseye = Gem.ruby_version >= "3.0.2"
else
bullseye = true
end
Expand Down
11 changes: 11 additions & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -1047,6 +1047,17 @@ def test_dockerfile
end
end

def test_old_rubies_do_not_use_bullseye_python
Gem.stub(:ruby_version, Gem::Version.new("2.7.0")) do
run_generator [destination_root, "--js=esbuild"]
end

assert_file "Dockerfile" do |content|
assert_match(/python/, content)
assert_no_match(/python-is-python3/, content)
end
end

def test_skip_docker
run_generator [destination_root, "--skip-docker"]

Expand Down

0 comments on commit 95b3b31

Please sign in to comment.