Multiple rubies / rbenv is painful (Chefdk inside Docker for Mac?)

I do ruby development on my Mac, as well as deploy Chef code.

https :// states:

Using the Chef development kit-provided Ruby as your system Ruby is optional. This just depends on how you are using Ruby on your system. For many users, Ruby is primarily used for authoring Chef cookbooks and recipes. If that’s true for you, then using the Chef development kit-provided Ruby as your system Ruby is recommended. But for other users who are already using tools like rbenv to manage Ruby versions, then that’s OK too.

It would be more helpful if there was a documented way on the site as exactly how to do this. https :// doesn’t shed light on it.

In the past I’ve tried adding chefdk as a rbenv version, which worked until, well, until it didn’t at which point it just utterly confused my teammate.

We’ve once worked with ChefDK in a VM, which is all a bit heavy.

Docker for Mac now exists (in Beta)

How about an officially maintained, documented and supported ChefDK-in-Docker & Dockerfile in which all configuration is set, to isolate us from Ruby version hell?

Sure… they are out there (21 and counting)…✓

Let’s not have everyone choose. Let’s do this together.


PS. I had to break 2 of the URLs to pass the “new user” filter.

I’m on a trip with minima internet access, but when I get back to
civilization next Wed, I’ll document my setup, which does indeed mix rbenv
with ChefDK (and doesn’t set ChefDK as an rbenv “version”).

Jeff Byrnes

1 Like

Thanks, Jeff.

I look forward to your input!

Regards, M.

Looks like is much the same set of problems.

It’s also remiss of me to not mention

So chef/chef-dk#313 lays the issue out in great detail. Let’s hope an official solution comes of that.

I have not used rbenv-chefdk, but I did come across it some time ago.

My solution is thus:

  1. Set up all the other things I need in my path
  2. Run the rbenv init
  3. Add the ChefDK paths to my $PATH

Looks kinda like this:

export PATH=/other/bins:$PATH

# Enable rbenv shims and autocompletion
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

# ChefDK binaries
# Added after rbenv to avoid path issues
export PATH="/opt/chefdk/bin:$PATH"

# chef gem-installed binaries
export PATH="$HOME/.chefdk/gem/ruby/2.1.0/bin:$PATH"

I end up with (line breaks added for easier reading):

♠ echo $PATH

It’s rather non-standard, and I don’t get the ChefDK bash completion, but it’s worked well for a long time.

Thanks Jeff, I appreciate it.

I’ll try your solution today (I’m at ChefConf, BTW).

I’ve also posted

You’re welcome. I’m not at ChefConf, or I’d offer to get together & help you out in-person. Best of luck!

Jeff Byrnes

1 Like

Some intense work has gone on over the last few days, culminating in a new release of rbenv-chefdk.

Hopefully the changes will be sufficient to cover the issues! It solved my problems. (The other of which was Bundle exec was failing because there was a undeclared dependency on rb-readline in the ChefDK). Luckily @jkeiser was at ChefChef2016, was a nice enough to spend time to hack through the issue.

Maybe you’d like to try it?

I’ll be setting up a new Mac on Aug 1, I’ll take this for a spin then! Thanks so much to both of you for improving this whole thing; it’ll be awesome to use Chef’s Ruby in this fashion.

Hmm, no dice on using rbenv-chefdk; it just spits out:

♠ rbenv shell chefdk
rbenv: version `chefdk' not installed

after I’ve cloned the repo into the specified path. Oh well!