From 0a8b962e9ce85443566e7f74e80bd78e61ab9397 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Tue, 12 Nov 2024 02:47:05 +0530 Subject: [PATCH 1/2] Adding chef-cli as a gem in the habitat plan file Signed-off-by: Ashique Saidalavi --- habitat/plan.sh | 23 +++++++++++++++++++---- lib/kitchen/provisioner/chef_infra.rb | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/habitat/plan.sh b/habitat/plan.sh index 6288b3a3c..ab5828e11 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -47,6 +47,7 @@ do_build() { bundle install ruby ./post-bundle-install.rb gem build chef-test-kitchen-enterprise.gemspec + gem install chef-cli } do_install() { @@ -55,13 +56,27 @@ do_install() { build_line "Setting GEM_PATH=$GEM_HOME" export GEM_PATH="$GEM_HOME" gem install chef-test-kitchen-enterprise-*.gem --no-document - wrap_ruby_bin + gem install chef-cli + wrap_ruby_kitchen + wrap_ruby_chef_cli_bin set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor/gems" } -wrap_ruby_bin() { +wrap_ruby_kitchen() { local bin="$pkg_prefix/bin/kitchen" local real_bin="$GEM_HOME/gems/chef-test-kitchen-enterprise-${pkg_version}/bin/kitchen" + wrap_bin_with_ruby "$bin" "$real_bin" +} + +wrap_ruby_chef_cli_bin() { + local bin="$pkg_prefix/bin/chef-cli" + local real_bin="$GEM_HOME/bin/chef-cli" + wrap_bin_with_ruby "$bin" "$real_bin" +} + +wrap_bin_with_ruby() { + local bin="$1" + local real_bin="$2" build_line "Adding wrapper $bin to $real_bin" cat < "$bin" #!$(pkg_path_for core/bash)/bin/bash @@ -71,9 +86,9 @@ set -e export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:\$PATH" # Set Ruby paths defined from 'do_setup_environment()' - export GEM_HOME="$pkg_prefix/vendor/gems" +export GEM_HOME="$pkg_prefix/vendor/gems" +export GEM_PATH="\$GEM_HOME" - export GEM_PATH="$GEM_HOME" exec $(pkg_path_for $_chef_client_ruby)/bin/ruby $real_bin \$@ EOF chmod -v 755 "$bin" diff --git a/lib/kitchen/provisioner/chef_infra.rb b/lib/kitchen/provisioner/chef_infra.rb index 54615bf09..83bb44338 100644 --- a/lib/kitchen/provisioner/chef_infra.rb +++ b/lib/kitchen/provisioner/chef_infra.rb @@ -66,7 +66,7 @@ def prepare_command file_content = "nonce:#{nonce}\ntimestamp:#{timestamp}\nsignature:#{signature}" file_location = config[:root_path] + "/#{context_key}" - sudo("echo '#{file_content}' > #{file_location}") + "echo '#{file_content}' > #{file_location}" end def run_command From c980e2fa61fd8c330b1b7347588dc4fbda444148 Mon Sep 17 00:00:00 2001 From: Ashique Saidalavi Date: Wed, 13 Nov 2024 12:00:04 +0530 Subject: [PATCH 2/2] Plan file updates Signed-off-by: Ashique Saidalavi --- habitat/plan.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/habitat/plan.sh b/habitat/plan.sh index ab5828e11..f6e395a6f 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -47,7 +47,6 @@ do_build() { bundle install ruby ./post-bundle-install.rb gem build chef-test-kitchen-enterprise.gemspec - gem install chef-cli } do_install() { @@ -58,7 +57,7 @@ do_install() { gem install chef-test-kitchen-enterprise-*.gem --no-document gem install chef-cli wrap_ruby_kitchen - wrap_ruby_chef_cli_bin + wrap_ruby_chef_cli set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor/gems" } @@ -68,7 +67,7 @@ wrap_ruby_kitchen() { wrap_bin_with_ruby "$bin" "$real_bin" } -wrap_ruby_chef_cli_bin() { +wrap_ruby_chef_cli() { local bin="$pkg_prefix/bin/chef-cli" local real_bin="$GEM_HOME/bin/chef-cli" wrap_bin_with_ruby "$bin" "$real_bin" @@ -96,4 +95,4 @@ EOF do_strip() { return 0 -} \ No newline at end of file +}