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

Fix user binstubs not on PATH and fix PATH order #383

Merged
merged 22 commits into from
Jan 13, 2025

Conversation

schneems
Copy link
Contributor

@schneems schneems commented Jan 9, 2025

Superscedes #382. Close #380

  • Adds the ability to rename a layer in commons
  • Uses this ability to rename ruby to binruby which allows executables intalled via bundle install to take precedence
  • Adds /workspace/bin to the PATH with a layer name that comes after gems and binruby

Commits are small and in order.

GUS-W-17544084

Note that this places `/layers/heroku_ruby/gems/bin` before `/layers/heroku_ruby/binruby` on the path. Related to, but doesn't entirely fix #380.
Using `-a` also shows that there's more than one value present.
It's common and expected that Rails applications will include a `bin` directory containing "binstubs" of executables their app depends on. For example https://github.com/heroku/ruby-getting-started/tree/5e7ce01610a21cf9e5381daea66f79178e2b3c06/bin. They're largely used to ensure that bundler is invoked/used so that you can run `bin/rails` rather than needing to use `bundle exec rails`. However it's not strictly limited to only that.

This change: Adds the `bin` folder in the root of the workspace to the PATH and changes the layer to `venv` so it is loaded after other layers (and takes precedence in the case of a PATH prepend).

This fixes the previously committed failing test.

Close #380
@schneems schneems force-pushed the schneems/add-user-binstubs branch from 10a45ed to 2bec8ef Compare January 9, 2025 21:36
@schneems schneems marked this pull request as ready for review January 9, 2025 21:42
@schneems schneems requested a review from a team as a code owner January 9, 2025 21:42
@schneems schneems marked this pull request as draft January 10, 2025 00:01
The Application Contract does not specify that commands such as `rake -P` will be called with `bundle exec` and the classic buildpack does not rely on `bundle exec` internally. This brings the CNB closer to parity with the classic buildpack.

In the container environment, the first gems on the PATH should be those installed by the buildpack, negating the strict need to call `bundle exec` as you would on a development machine.

Usually prepending a Ruby command with `bundle exec` will have no discernible difference for an application that's bug free. This is evidenced by all tests passing with this change. However someone can commit their own `bin/rake` or `bin/rails` and we should use this over the executable installed via `bundle install`.
@schneems schneems force-pushed the schneems/add-user-binstubs branch from 6f97cb5 to b17681c Compare January 10, 2025 22:51
At runtime, the alphabetical order of the layer name determines the order it is loaded. At build time, the order that the `env` variable is modified determines the order.

At both build and runtime we want the bin stubs to come first on the PATH when executing user defined code. This was already working for runtime, but wasn't for build time as the "gems" layer was being prepended to the path after the "venv" layer (because the `venv` layer was being defined first, last definition wins).

I originally tried to fix this by defining the PATH inside of the "gems" layer along with the gems path but ran into heroku/libcnb.rs#899. The libcnb.rs project loads the user defined PATH modification last, but I'm unclear if that's spec defined behavior or not https://github.com/buildpacks/spec/blob/main/buildpack.md#layer-paths.
@schneems schneems force-pushed the schneems/add-user-binstubs branch from b17681c to c91cee5 Compare January 10, 2025 22:57
@schneems schneems marked this pull request as ready for review January 10, 2025 23:39
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Rubber stamp to unblock you; let me know if you'd prefer a more in-depth review)

@schneems schneems merged commit 4452d3a into main Jan 13, 2025
6 checks passed
@schneems schneems deleted the schneems/add-user-binstubs branch January 13, 2025 22:03
heroku-linguist bot added a commit that referenced this pull request Jan 13, 2025
## heroku/ruby

### Fixed

- Executables from the applications `bin` directory will be placed on the path before dependencies installed via bundler ([#383](#383))
- Binaries from user installed gems will be placed on the path before binaries that ship with Ruby ([#383](#383))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binary order is incorrect
2 participants