Skip to content

Commit 491a8f8

Browse files
committed
Copy whatever file is defined as Ruby version on Gemfile
1 parent dc0b603 commit 491a8f8

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/generators/dockerfile_generator.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,12 @@ def using_bun?
515515
end
516516

517517
def references_ruby_version_file?
518-
@references_ruby_version_file ||= IO.read("Gemfile").include?(".ruby-version")
518+
@references_ruby_version_file ||= ruby_version_file.present?
519+
end
520+
521+
def ruby_version_file
522+
match = IO.read("Gemfile").match(/ruby file: ["'](.*)["']/)
523+
match ? match[1] : nil
519524
end
520525

521526
def using_redis?

lib/generators/templates/Dockerfile.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
1010
<% end -%>
1111

12-
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
12+
# Make sure RUBY_VERSION matches the Ruby version in <%= ruby_version_file || '.ruby-version' %>
1313
ARG RUBY_VERSION=<%= RUBY_VERSION %>
1414
<% if api_client_dir -%>
1515
<%= render partial: 'node_client' %>
@@ -95,7 +95,7 @@ ENV <%= build_env.join(" \\\n ") %>
9595

9696
<% end -%>
9797
# Install application gems
98-
COPY<% if options.link? %> --link<% end %> Gemfile Gemfile.lock <% if references_ruby_version_file? %>.ruby-version <% end %>./
98+
COPY<% if options.link? %> --link<% end %> Gemfile Gemfile.lock <% if references_ruby_version_file? %><%= ruby_version_file %> <% end %>./
9999
<% if @netpopbug && Rails.env != "test" -%>
100100
RUN sed -i "/net-pop (0.1.2)/a\ net-protocol" Gemfile.lock
101101
<% end -%>

0 commit comments

Comments
 (0)