CHEF-37444: add ~/.chef/ruby/VERSION/gems to GEM_PATH for dynamic plugin loading - #1963
Conversation
Confirmed: the actual root cause is in chef/appbundler (env_sanitizer clears GEM_HOME/GEM_PATH via ::Gem.clear_paths and never restores user/chef gem paths), which is still actively used in the chef-19 Habitat build pipeline for ohai, chef, knife, chef-cli, and chef-test-kitchen-enterprise. Filed the upstream fix request there. Given the upstream fix will take longer to land and release, resolving this review so the per-repo workaround here isnt blocked -- please just link back to the appbundler upstream issue in the PR description so we remember to remove this workaround once appbundler ships the real fix.
|
Discussed with @sanghinitin and while this isn't ideal, the only solution that comes close is an intermediate package which would still require repo-specific changes |
0dad7ff to
75e610d
Compare
…gin loading
- binstub_patch.rb: inject Gem.user_dir (~/.gem/ruby/VERSION) and
~/.chef/ruby/RUBY_API_VERSION/gems into GEM_PATH ahead of existing
paths so gems installed via `gem install` or `chef gem install`
are immediately visible to the ohai binstub.
- habitat/plan.sh, habitat/aarch64-darwin/plan.sh: expand the runtime
wrapper's GEM_PATH to four entries:
1. $pkg_prefix/vendor (ohai's vendored deps, flat)
2. $pkg_prefix/vendor/ruby/VERSION (bundler-nested deps, e.g. train-core)
3. ~/.gem/ruby/VERSION (standard `gem install` target)
4. ~/.chef/ruby/VERSION/gems (`chef gem install` target)
ruby_gem_version is now derived from the packaged Ruby's on-disk
lib/ruby/gems/ directory instead of executing `ruby -e`, which
could silently fail during Habitat's do_install phase and leave the
version segment empty. Falls back to 3.4.0 with a build_line warning.
- habitat/plan.ps1: inject binstub_patch.rb into Windows binstubs after
appbundler generates them, using the same require-rubygems insertion
point used on Linux/macOS.
Signed-off-by: nitin sanghi <nsanghi@progress.com>
Signed-off-by: nitin sanghi <nsanghi@progress.com>
75e610d to
5e65398
Compare
Summary
Ohai plugins installed via
chef gem installland in~/.chef/ruby/<RUBY_API_VERSION>/gems, but this path was never added tothe runtime
GEM_PATH. As a result, any gem installed that way wasinvisible to the packaged ohai binary even after re-running the binstub.
This PR fixes the issue by expanding
GEM_PATHin three places: the Rubybinstub patch, and both the Linux/macOS and Windows Habitat wrappers.
Root Cause Evidence
https://progresssoftware.atlassian.net/browse/CHEF-34004
Changes Made
binstub_patch.rb
GEM_PATHassignment.GEM_PATH:$pkg_prefix/vendor— ohai vendored deps (flat layout)Gem.user_dir→~/.gem/ruby/VERSION— standardgem installtarget~/.chef/ruby/RUBY_API_VERSION/gems—chef gem installtarget.uniqso paths are never duplicated when the block runs twice.habitat/plan.sh & habitat/aarch64-darwin/plan.sh
GEM_PATHentries:$pkg_prefix/vendor— flat vendor tree$pkg_prefix/vendor/ruby/VERSION— bundler-nested tree (train-core etc.)${HOME}/.gem/ruby/VERSION— standard gem install${HOME}/.chef/ruby/VERSION/gems— chef gem installruby_gem_versionis now derived from the packaged Ruby's on-disklib/ruby/gems/directory viabasenameinstead of executingruby -e. The latter can silently fail duringdo_install(runtime libpaths are not yet set up), producing an empty version string that
corrupts all
GEM_PATHentries. Falls back to3.4.0with abuild_linewarning if the glob still yields nothing.habitat/plan.ps1
appbundler.batgenerates Windows binstubs, injectsbinstub_patch.rbimmediately after therequire "rubygems"line ineach binstub — the same insertion point used on Linux/macOS.
Verification
After
hab pkg build .andhab pkg install:This work was completed with AI assistance following Progress AI policies