Skip to content

Commit

Permalink
Adding chef-cli as a gem in the habitat plan file
Browse files Browse the repository at this point in the history
Signed-off-by: Ashique Saidalavi <[email protected]>
  • Loading branch information
ashiqueps committed Nov 11, 2024
1 parent ec59b06 commit 0a8b962
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 <<EOF > "$bin"
#!$(pkg_path_for core/bash)/bin/bash
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/provisioner/chef_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a8b962

Please sign in to comment.