Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ wrap_ruby_bin() {
set -e

# Set binary path that allows InSpec to use non-Hab pkg binaries
export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH"
# Include Ruby bin directory so chef-cli exec can find gem, etc.
export PATH="$(pkg_path_for ${ruby_pkg})/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH"

# Set Ruby paths defined from 'do_setup_environment()'
export GEM_HOME="$pkg_prefix/vendor"
Expand Down
4 changes: 3 additions & 1 deletion lib/chef-cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ def habitat_env(show_warning: false)
raise "Error: Could not determine the vendor package prefix. Ensure #{ChefCLI::Dist::HAB_PKG_NAME} is installed and CHEF_CLI_VERSION is set correctly." unless vendor_pkg_prefix

vendor_dir = File.join(vendor_pkg_prefix, "vendor")
# Construct PATH
# Construct PATH including Ruby bin directory for chef-cli exec command
ruby_bin_dir = File.dirname(RbConfig.ruby)
path = [
File.join(bin_pkg_prefix, "bin"),
File.join(vendor_dir, "bin"),
ruby_bin_dir, # Add Ruby bin directory so exec can find gem etc.
ENV["PATH"].split(File::PATH_SEPARATOR), # Preserve existing PATH
].flatten.uniq

Expand Down
3 changes: 2 additions & 1 deletion spec/unit/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@
context "when installed with habitat" do
let(:chef_dke_path) { "/hab/pkgs/chef/chef-workstation/1.0.0/123" }
let(:cli_hab_path) { "/hab/pkgs/chef/chef-cli/1.0.0/123" }
let(:ruby_bin_dir) { File.dirname(RbConfig.ruby) }
let(:expected_gem_root) { Gem.default_dir }
let(:expected_path) { [File.join(chef_dke_path, "bin"), File.join(cli_hab_path, "vendor", "bin"), "/usr/bin:/bin"].flatten }
let(:expected_path) { [File.join(chef_dke_path, "bin"), File.join(cli_hab_path, "vendor", "bin"), ruby_bin_dir, "/usr/bin:/bin"].flatten }
let(:expected_env) do
{
"PATH" => expected_path.join(File::PATH_SEPARATOR),
Expand Down
Loading