Sha256: c55caed54a6c6ddea513ea51b2f839a16a06059eacd6ed0b3b323744dcc4299f

Contents?: true

Size: 1.52 KB

Versions: 20

Compression:

Stored size: 1.52 KB

Contents

require_relative "base"
require_relative "../shell_out"
require_relative "../logging"

module Kitchen
  class LifecycleHook
    class Local < Base
      include ShellOut
      include Logging

      # Execute a specific local command hook.
      #
      # @return [void]
      def run
        state = state_file.read
        # set up empty user variable
        user = {}
        # Set up some environment variables with instance info.
        environment = {
          "KITCHEN_INSTANCE_NAME" => instance.name,
          "KITCHEN_SUITE_NAME" => instance.suite.name,
          "KITCHEN_PLATFORM_NAME" => instance.platform.name,
          "KITCHEN_INSTANCE_HOSTNAME" => state[:hostname].to_s,
        }
        # If the user specified env vars too, fix them up because symbol keys
        # make mixlib-shellout sad.
        hook[:environment]&.each do |k, v|
          environment[k.to_s] = v.to_s
        end

        # add user to user hash for later merging
        user[:user] = hook[:user] if hook[:user]

        # Default the cwd to the kitchen root and resolve a relative input cwd against that.
        cwd = if hook[:cwd]
                File.expand_path(hook[:cwd], config[:kitchen_root])
              else
                config[:kitchen_root]
              end
        # Build the options for mixlib-shellout.
        opts = {}.merge(user).merge(cwd: cwd, environment: environment)
        run_command(command, opts)
      end

      private

      # @return [String]
      def command
        hook.fetch(:local)
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
test-kitchen-3.5.1 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.5.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.4.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.3.2 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.3.1 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.3.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.2.2 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.2.1 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.2.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.1.1 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.1.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-rsync-3.0.0.pre.3 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-rsync-3.0.0.pre.2 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-rsync-3.0.0.pre.1 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-3.0.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-2.12.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-2.11.2 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-2.11.1 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-2.11.0 lib/kitchen/lifecycle_hook/local.rb
test-kitchen-2.10.0 lib/kitchen/lifecycle_hook/local.rb