Skip to content

CHEF-37441: Add ~/.chef/ruby/VERSION/gems to GEM_PATH for dynamic plugin loading - #192

Open
sanghinitin wants to merge 3 commits into
mainfrom
CHEF-37441-gem-install-support
Open

CHEF-37441: Add ~/.chef/ruby/VERSION/gems to GEM_PATH for dynamic plugin loading#192
sanghinitin wants to merge 3 commits into
mainfrom
CHEF-37441-gem-install-support

Conversation

@sanghinitin

@sanghinitin sanghinitin commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Ensures gems installed via chef gem install knife-<plugin> are immediately discoverable by knife at runtime, without requiring any additional configuration.

Problem

chef-cli gem install places gems under ~/.chef/ruby/<RUBY_API_VERSION>/gems (e.g. ~/.chef/ruby/3.4.0/gems). This path was not included in the GEM_PATH used by the knife binstubs or the Habitat runtime wrapper, so plugins such as knife-azure were invisible to knife even after knife rehash.

Changes

  • binstub_patch.rb — prepend three paths to GEM_PATH at binstub startup:
    1. Package vendor dir (knife's bundled deps — was already present)
    2. Gem.user_dir~/.gem/ruby/VERSION (standard gem install)
    3. ~/.chef/ruby/VERSION/gems via RbConfig::CONFIG['ruby_version'] (chef-cli gem install)
  • habitat/plan.sh — runtime knife wrapper exports expanded GEM_PATH including ${HOME}/.gem/ruby/${ruby_gem_version} and ${HOME}/.chef/ruby/${ruby_gem_version}/gems
  • habitat/aarch64-darwin/plan.sh — same GEM_PATH additions for macOS ARM64
  • habitat/plan.ps1 — two Windows fixes:
    • Pass --ignore-dependencies to gem install knife*.gem to avoid appbundler ambiguous specs errors
    • Inject binstub_patch.rb into generated binstubs after appbundler.bat, mirroring the Linux/macOS sed approach

Evidence

$ chef-cli gem info knife-azure

*** LOCAL GEMS ***

knife-azure (4.0.0)
Installed at: /Users/home/.chef/ruby/3.4.0/gems

With this change, knife resolves plugins from that path at launch.

Files Modified

  • binstub_patch.rb
  • habitat/plan.sh
  • habitat/aarch64-darwin/plan.sh
  • habitat/plan.ps1

…gin loading

- Update binstub_patch.rb to prepend vendor dir, Gem.user_dir, and
  ~/.chef/ruby/VERSION/gems to GEM_PATH at runtime so that plugins
  installed via 'chef gem install knife-<plugin>' are immediately
  available without additional configuration.
  Uses RbConfig::CONFIG['ruby_version'] to resolve the correct API
  version path at runtime.

- Update habitat/plan.sh wrapper script to include
  ${HOME}/.gem/ruby/VERSION and ${HOME}/.chef/ruby/VERSION/gems in
  GEM_PATH so plugins are discoverable when knife runs in a Habitat
  environment on Linux.

- Update habitat/aarch64-darwin/plan.sh wrapper script with same
  GEM_PATH additions for macOS ARM64 Habitat builds.

- Update habitat/plan.ps1 to pass --ignore-dependencies to gem install
  knife*.gem (avoids appbundler ambiguous specs from duplicate dep
  entries) and inject binstub_patch.rb into Windows binstubs after
  appbundler generation, matching the Linux/macOS behavior.

Signed-off-by: nitin sanghi <nsanghi@progress.com>
@sanghinitin
sanghinitin requested review from a team and jaymzh as code owners July 30, 2026 09:44
@sanghinitin sanghinitin added enhancement New feature or request ai-assisted Work completed with AI assistance following Progress AI policies labels Jul 30, 2026
…ub_patch.rb

Remove leading underscore from knife_vendor, chef_gem_dir, and
existing_paths variables — underscore prefix is reserved for intentionally
unused variables in Ruby/RuboCop convention.

Signed-off-by: nitin sanghi <nsanghi@progress.com>
Signed-off-by: nitin sanghi <nsanghi@progress.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted Work completed with AI assistance following Progress AI policies enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant