From 0905d96e89ef02bb39aba8454b76380f7176819e Mon Sep 17 00:00:00 2001 From: Prajakta Purohit Date: Thu, 19 Dec 2024 09:43:55 -0800 Subject: [PATCH 1/2] - Point GEM_HOME to the package/vendor directory. This will resolve to pkg/vendor/gems instead of package/vendor/gems/gems as done in the current hab install. - Create and add the /hab/kitchen directory to the GEM_PATH. With this change the GEM_PATHS will look like - GEM PATHS: - /hab/pkgs/core/ruby3_1/3.1.6/20241017135756/lib/ruby/gems/3.1.0 - /hab/pkgs/chef/chef-infra-client/19.0.60/20241216200649/vendor - /hab/kitchen Signed-off-by: Prajakta Purohit --- habitat/plan.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/habitat/plan.sh b/habitat/plan.sh index d74f0cc15..29239fb3a 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -36,7 +36,7 @@ do_unpack() { do_build() { echo $(pkg_path_for $_chef_client_ruby) - export GEM_HOME="$pkg_prefix/vendor/gems" + export GEM_HOME="$pkg_prefix/vendor" build_line "Setting GEM_PATH=$GEM_HOME" export GEM_PATH="$GEM_HOME" @@ -50,6 +50,7 @@ do_build() { } do_install() { + mkdir -p /hab/kitchen export GEM_HOME="$pkg_prefix/vendor/gems" build_line "Setting GEM_PATH=$GEM_HOME" @@ -58,7 +59,7 @@ do_install() { gem install chef-cli wrap_ruby_kitchen wrap_ruby_chef_cli - set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor/gems" + set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor/gems;/hab/kitchen" } wrap_ruby_kitchen() { @@ -95,4 +96,4 @@ EOF do_strip() { return 0 -} +} \ No newline at end of file From b7b0faee9cfa008921165eca381688810e64d99c Mon Sep 17 00:00:00 2001 From: Prajakta Purohit Date: Thu, 19 Dec 2024 09:46:31 -0800 Subject: [PATCH 2/2] Added the kitchen_gem script into the bin for test kitchen, any other component that will need to install a custom gem will also need a similar _gem script. This script will install kitchen related plugins in the /hab/kitchen directory and execute the install command will the appropriate arguments, in the context of the appropriate version for kitchen as set by the user. Signed-off-by: Prajakta Purohit --- bin/kitchen_gem | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 bin/kitchen_gem diff --git a/bin/kitchen_gem b/bin/kitchen_gem new file mode 100644 index 000000000..7bd3d4592 --- /dev/null +++ b/bin/kitchen_gem @@ -0,0 +1,12 @@ +#!/bin/bash + +# expected to be invoked as kitchen install-gem +export GEM_HOME="/hab/kitchen" +env_version=$KITCHEN_VERSION + +if [[ -z "$env_version" ]]; then +# it will install the latest version if a new version installed unless the version env variable was set + hab pkg exec $origin/$package gem install -- $@ +else + hab pkg exec $origin/$package/$env_version gem install -- $@ +fi \ No newline at end of file