poise / halite

Write as a gem, release as a cookbook.
https://github.com/poise/halite
Apache License 2.0
42 stars 9 forks source link

gems in metadata.rb #13

Closed eedwards-sk closed 6 years ago

eedwards-sk commented 6 years ago

As it stands, it's unclear what the proper way is to propagate gem dependencies used for the cookbook from the gem itself into the generated cookbook.

e.g. in my gemspec I can require a gem:

spec.add_runtime_dependency 'my_org-my_utils'

and I can force it to a local path in the Gemfile:

gem 'my_org-my_utils', :path => '/Users/username/Documents/dev/local/my-org-util-gem'

However, this doesn't seem to pass that requirement into the cookbook that gets generated.

Chef supports a gem field for metadata.rb which will automatically use chef_gem to load gems.

However, it doesn't appear that I can append gem entries to the generated metadata.rb

So, what is the proper/recommended way of propagating these dependencies?

coderanger commented 6 years ago

The gem metadata field was added far after this project (and in part as a response to it), but I've never needed it so I haven't bothered adding support.

coderanger commented 6 years ago

Also just a general thing, I wouldn't really recommend using this. I've mostly cycled down on Chef stuff in the past year as it is slowly drifting towards being obsolete. If you're going to use my toolchain, assume you need to support it all yourself.

eedwards-sk commented 6 years ago

@coderanger thanks for the update and response!

I love the idea of using gem testing patterns for chef projects so I had been gravitating toward using your pattern, but even when spelunking among your own projects I'm having trouble finding example use cases of how to implement it properly.

I definitely appreciate the candor... I'll have to rethink my approach, but this has been great inspiration. Hope your career is going well :)

coderanger commented 6 years ago

If you do want to make your own fork and add it, you can probably pull the needed dependency info out my existing gem scraping code :) Right now I just raise an exception on any runtime deps that aren't either halite itself (or chef) or a cookbook, instead just take that list an map them to gem metadata lines. If you wanted to make it more bulletproof it should check for a c-ext in the gem since that will almost certainly not work correctly as a cookbook dep.

coderanger commented 6 years ago

Relevant code: https://github.com/poise/halite/blob/master/lib/halite/dependencies.rb#L67-L75