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

CHEF-14475-Hab path changes for chef-cli #238

Merged
merged 9 commits into from
Nov 11, 2024
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
1 change: 0 additions & 1 deletion chef-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ Gem::Specification.new do |gem|
gem.add_dependency "diff-lcs", ">= 1.0", "< 1.4" # 1.4 changes the output
gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ
gem.add_dependency "license-acceptance", ">= 1.0.11", "< 3"
gem.add_dependency "chef-licensing", "~> 1.0"
end
92 changes: 0 additions & 92 deletions habitat/plan.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion habitat/plan.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
_chef_client_ruby="core/ruby31"
pkg_name="chef-cli"
pkg_origin="chef"
pkg_origin="ngupta26"
pkg_maintainer="The Chef Maintainers <[email protected]>"
pkg_description="The Chef CLI"
pkg_license=('Apache-2.0')
Expand Down
14 changes: 7 additions & 7 deletions lib/chef-cli/command/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ def ruby_info

def gem_environment
h = {}
h["GEM ROOT"] = omnibus_env["GEM_ROOT"]
h["GEM HOME"] = omnibus_env["GEM_HOME"]
h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR)
rescue OmnibusInstallNotFound
# h["GEM ROOT"] = omnibus_env["GEM_ROOT"]
# h["GEM HOME"] = omnibus_env["GEM_HOME"]
# h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR)
# rescue OmnibusInstallNotFound
h["GEM_ROOT"] = ENV["GEM_ROOT"] if ENV.key?("GEM_ROOT")
h["GEM_HOME"] = ENV["GEM_HOME"] if ENV.key?("GEM_HOME")
h["GEM PATHS"] = ENV["GEM_PATH"].split(File::PATH_SEPARATOR) if ENV.key?("GEM_PATH") && !ENV.key?("GEM_PATH").nil?
ensure
h
# ensure
# h
end

def paths
omnibus_env["PATH"].split(File::PATH_SEPARATOR)
habitat_env["PATH"].split(File::PATH_SEPARATOR)
rescue OmnibusInstallNotFound
ENV["PATH"].split(File::PATH_SEPARATOR)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-cli/command/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Exec < ChefCLI::Command::Base
def run(params)
# Set ENV directly on the "parent" process (us) before running #exec to
# ensure the custom PATH is honored when finding the command to exec
omnibus_env.each { |var, value| ENV[var] = value }
habitat_env.each { |var, value| ENV[var] = value }
exec(*params)
raise "Exec failed without an exception, your ruby is buggy" # should never get here
end
Expand Down
47 changes: 32 additions & 15 deletions lib/chef-cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,39 @@ def git_windows_bin_dir
end

#
# environment vars for omnibus
# environment vars for habitat
#
def omnibus_env
@omnibus_env ||=
begin
user_bin_dir = File.expand_path(File.join(Gem.user_dir, "bin"))
path = [ omnibus_bin_dir, user_bin_dir, omnibus_embedded_bin_dir, ENV["PATH"].split(File::PATH_SEPARATOR) ]
path << git_bin_dir if Dir.exist?(git_bin_dir)
path << git_windows_bin_dir if Dir.exist?(git_windows_bin_dir)
{
"PATH" => path.flatten.uniq.join(File::PATH_SEPARATOR),
"GEM_ROOT" => Gem.default_dir,
"GEM_HOME" => Gem.user_dir,
"GEM_PATH" => Gem.path.join(File::PATH_SEPARATOR),
}
end
def habitat_env
@habitat_env ||=
begin
# Define the necessary paths for the Habitat environment
# Custom GEM_HOME within Habitat
pkg_prefix = get_pkg_prefix
vendor_dir = File.join(pkg_prefix, "vendor")
path = [
File.join(pkg_prefix, "bin"),
ENV["PATH"].split(File::PATH_SEPARATOR) # Preserve existing PATH
].flatten.uniq

{
"PATH" => path.join(File::PATH_SEPARATOR),
"GEM_ROOT" => Gem.default_dir, # Default directory for gems
"GEM_HOME" => vendor_dir, # GEM_HOME pointing to the vendor directory
"GEM_PATH" => vendor_dir, # GEM_PATH also pointing to the vendor directory
}
end
end

def get_pkg_prefix
pkg_origin = "ngupta26"
pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name
path = `hab pkg path #{pkg_name}`.strip

if $?.success? && !path.empty?
path
else
raise "Failed to get pkg_prefix for #{pkg_name}: #{path}"
end
end

def omnibus_expand_path(*paths)
Expand Down
Loading