Skip to content

Commit

Permalink
Add platform information to windows support docs (#1473)
Browse files Browse the repository at this point in the history
* Add platform information to windows support docs

Update windows docs to specify how to add Heroku's platform to the Gemfile.lock. In #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 #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 #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 #1472

* Update warning message to be less confusing

Based on this conversation #1469 (comment)
  • Loading branch information
schneems authored Jun 25, 2024
1 parent 4d2621c commit 640b216
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 7 additions & 1 deletion changelogs/unreleased/windows_gemfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/language_pack/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions spec/hatchet/ruby_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 640b216

Please sign in to comment.