chef-partners/azure-chef-extension

Install fails with CC17 due to dependency on knife libraries

Closed this issue · 3 comments

Issue

When installing CC17, the install scripts try to require chef/knife/core/bootstrap_context

Since knife was removed from CC17 this results in a stack trace that looks like this:-

:\Packages\Plugins\Chef.Bootstrap.WindowsAzure.ChefClient\1210.13.5.1>ruby C:\Packages\Plugins\Chef.Bootstrap.WindowsAzure.ChefClient\1210.13.5.1\bin\chef-enable.rb
<internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require': cannot load such file -- chef/knife/core/bootstrap_context (LoadError)
        from <internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from C:/opscode/chef/embedded/lib/ruby/gems/3.0.0/gems/azure-chef-extension-0.0.1/lib/chef/azure/core/windows_bootstrap_context.rb:19:in `<top (required)>'
        from <internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from C:/opscode/chef/embedded/lib/ruby/gems/3.0.0/gems/azure-chef-extension-0.0.1/lib/chef/azure/commands/enable.rb:11:in `<top (required)>'
        from <internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `require'
        from <internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:160:in `rescue in require'
        from <internal:C:/opscode/chef/embedded/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:149:in `require'

Possible fix

Refactor the bootstrap code to rely on more traditional bootstrap/registration methods such as:-

  • Lay down a client.rb
  • Lay down a validator.pem
  • Run the chef-client to auto-register
  • Remove the validator.pem after 1st successful chef run.
btm commented

@ayushbhatt29 is there a limit on the size of the extension? The linux zip is 128K when built on my workstation. If I add knife to the dependencies for the gem, bundle cache, and then add the gems in vendor/cache to the build, it is 13M.

Would that work?

btm commented

@ayushbhatt29 long ago, we shipped the entire Chef Infra Client in the extension. We stopped doing that, which was good. That was pretty big, so I don't think we'll have any issues if the extension wass 13M.

In this case, I think we can get by with shipping only the Ruby libraries necessary (knife, chef, some other dependencies) in the extension as well. This doesn't replace the Infra Client install but would give us the dependencies we need for this project without rewriting or duplicating code.

I'm thinking something like:
add knife as a non-dev dep to the gemspec or Gemfile
add bundle cache --cache-path= "#{CHEF_BUILD_DIR}/gems" somewhere in the Rakefile
modify chef-install.sh to install all the gems shipped with the extension like chef-install.psm1 currently does.

Thanks @btm , i tried this by adding gems in vendor/cache after bundle cache in internally published extension and size of 13 M is not giving any errors while publishing, i think which can be reduced if required by only adding required gems on vendor/cache.
Knife was not getting installed due to dev dependencies.