From 640b216d4d496587100c673512f9c6bdc25c19b4 Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Tue, 25 Jun 2024 17:19:37 -0500 Subject: [PATCH] Add platform information to windows support docs (#1473) * Add platform information to windows support docs Update windows docs to specify how to add Heroku's platform to the Gemfile.lock. In https://github.com/heroku/heroku-buildpack-ruby/pull/1469 the behavior changed for Windows users. However if they're depending on a platform specific gem and they don't have the `x86_64-linux` platform locked then their dependency resolution will not use that information and their deploy will fail with a message saying to run those commands. By adding the instructions into the descanter article, warning message, and changelog entry there's a better chance windows users will succeed on their first deploy after https://github.com/heroku/heroku-buildpack-ruby/pull/1469 ## Commands breakdown Install the latest bundler version at the system level: ``` > gem install bundler ``` Update the current project to explicitly use the latest version of bundler: ``` > bundle update --bundler ``` Ensure that both `ruby` and `x86_64-linux` platforms are specified in the `Gemfile.lock`: ``` > bundle lock --add-platform ruby > bundle lock --add-platform x86_64-linux ``` Ensure bundler has resolved dependencies with all platforms in mind: ``` > bundle install ``` Commit the results to git: ``` > git add Gemfile.lock > git commit -m "Upgrade bundler" ``` * Fix variable access for windows users Reported in https://github.com/heroku/heroku-buildpack-ruby/issues/1472, the code was using an instance variable that does not exist so it raises an error. The `bundler` call is both a class and instance method https://github.com/heroku/heroku-buildpack-ruby/blob/4d2621c7dedff3edc95ee809d1cd71d6186fb796/lib/language_pack/ruby.rb#L27-L33. Internally it's stored as a class instance variable https://www.ruby-lang.org/en/documentation/faq/8/ so the data can be shared between the class and instances. The fix is to use `bundler` instead of `@bundler`. The test exercises and asserts that codepath was executed. Close https://github.com/heroku/heroku-buildpack-ruby/issues/1472 * Update warning message to be less confusing Based on this conversation https://github.com/heroku/heroku-buildpack-ruby/pull/1469#discussion_r1652055072 --- changelogs/unreleased/windows_gemfile.md | 8 +++++- lib/language_pack/ruby.rb | 5 +++- spec/hatchet/ruby_spec.rb | 34 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/changelogs/unreleased/windows_gemfile.md b/changelogs/unreleased/windows_gemfile.md index 53ca84f1..19920e44 100644 --- a/changelogs/unreleased/windows_gemfile.md +++ b/changelogs/unreleased/windows_gemfile.md @@ -8,6 +8,9 @@ Ruby applications that use Windows and Bundler 2.2+ will no longer have their `G ``` > gem install bundler > bundle update --bundler +> bundle lock --add-platform ruby +> bundle lock --add-platform x86_64-linux +> bundle install > git add Gemfile.lock > git commit -m "Upgrade bundler" ``` @@ -55,11 +58,14 @@ Heroku supports deploying applications developed on Windows, but [production dyn ``` > gem install bundler > bundle update --bundler +> bundle lock --add-platform ruby +> bundle lock --add-platform x86_64-linux +> bundle install > git add Gemfile.lock > git commit -m "Upgrade bundler" ``` -Windows applications using bundler 2.2+ will rely on bundler's support for multiple platforms to find and install an appropriate version. +After running these commands, Windows applications using bundler 2.2+ will rely on bundler's support for multiple platforms to find and install an appropriate version. ## Windows support with bundler before 2.2 diff --git a/lib/language_pack/ruby.rb b/lib/language_pack/ruby.rb index 284a69e5..ced465dc 100644 --- a/lib/language_pack/ruby.rb +++ b/lib/language_pack/ruby.rb @@ -695,7 +695,7 @@ def build_bundler if bundler.windows_gemfile_lock? if bundler.supports_multiple_platforms? - puts "Windows `Gemfile.lock` detected, bundler #{@bundler.version} supports multiple platforms, no action taken." + puts "Windows platform detected, preserving `Gemfile.lock` (#{bundler.version} >= 2.2)" else File.unlink("Gemfile.lock") ENV.delete("BUNDLE_DEPLOYMENT") @@ -713,6 +713,9 @@ def build_bundler > gem install bundler > bundle update --bundler + > bundle lock --add-platform ruby + > bundle lock --add-platform x86_64-linux + > bundle install > git add Gemfile.lock > git commit -m "Upgrade bundler" diff --git a/spec/hatchet/ruby_spec.rb b/spec/hatchet/ruby_spec.rb index 947f9ceb..e221c420 100644 --- a/spec/hatchet/ruby_spec.rb +++ b/spec/hatchet/ruby_spec.rb @@ -1,6 +1,40 @@ require_relative '../spec_helper' describe "Ruby apps" do + describe "with mingw platform" do + it "is detected as a Windows app" do + Hatchet::Runner.new("default_ruby").tap do |app| + app.before_deploy do + Pathname("Gemfile").write(<<~'EOF') + source "https://rubygems.org" + + gem "rake" + EOF + + Pathname("Gemfile.lock").write(<<~'EOF') + GEM + remote: https://rubygems.org/ + specs: + rake (13.2.1) + + PLATFORMS + x86-mingw32 + ruby + + DEPENDENCIES + rake + + BUNDLED WITH + 2.5.9 + EOF + end + + app.deploy do + expect(app.output).to include("Windows platform detected, preserving `Gemfile.lock`") + end + end + end + end # https://github.com/heroku/heroku-buildpack-ruby/issues/1025 describe "bin/rake binstub" do