Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workaround Ruby 3.3.3 net-pop bug #108

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

require "rails"
Rails.env = "test"

require "bundler/gem_tasks"

# Run `rake release` to release a new version of the gem.
Expand Down
12 changes: 12 additions & 0 deletions lib/dockerfile-rails/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def scan_rails_app
@git ||= ENV["RAILS_ENV"] != "test" && parser.specs.any? do |spec|
spec.source.instance_of? Bundler::Source::Git
end

# determine if the application is affected by the net-pop bug
# https://github.com/ruby/ruby/pull/11006#issuecomment-2176562332
if RUBY_VERSION == "3.3.3" && @gemfile.include?("net-pop")
@netpopbug = parser.specs.find { |spec| spec.name == "net-pop" }.dependencies.empty?
end
end

if File.exist? "Gemfile"
Expand Down Expand Up @@ -86,5 +92,11 @@ def scan_rails_app
def using_trilogy?
@gemfile.include?("trilogy") || @gemfile.include?("activerecord-trilogy-adapter")
end

### patches ###
if RUBY_VERSION == "3.3.3"
Bundler::LockfileParser.new(Bundler.read_file("Gemfile.lock"))

end
end
end
9 changes: 9 additions & 0 deletions lib/generators/dockerfile_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,15 @@ def generate_app
STDERR.puts "\n" + shell.set_color(message, Thor::Shell::Color::RED, Thor::Shell::Color::BOLD)
end

if @netpopbug && !dockerfile.include?("net-pop")
message = "Ruby 3.3.3 net-pop bug detected."
STDERR.puts "\n" + shell.set_color(message, Thor::Shell::Color::RED, Thor::Shell::Color::BOLD)
STDERR.puts "Please see https://github.com/ruby/ruby/pull/11006"
STDERR.puts "Change your Ruby version, or run `bin/rails generate dockerfile`,"
STDERR.puts "or add the following to your Dockerfile:"
STDERR.puts 'RUN sed -i "/net-pop (0.1.2)/a\ net-protocol" Gemfile.lock'
end

if (options.sqlite3? || @sqlite3) && !dockerfile.include?("DATABASE_URL") && File.exist?("fly.toml")
toml = IO.read("fly.toml")
if !toml.include?("[[env]]")
Expand Down
3 changes: 3 additions & 0 deletions lib/generators/templates/Dockerfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ ENV <%= build_env.join(" \\\n ") %>
<% end -%>
# Install application gems
COPY<% if options.link? %> --link<% end %> Gemfile Gemfile.lock <% if references_ruby_version_file? %>.ruby-version <% end %>./
<% if @netpopbug && Rails.env != "test" -%>
RUN sed -i "/net-pop (0.1.2)/a\ net-protocol" Gemfile.lock
<% end -%>
<% if options.cache? -%>
RUN --mount=type=cache,id=bld-gem-cache,sharing=locked,target=/srv/vendor \
<% if private_gemserver_env_variable_name -%>
Expand Down
Loading