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

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

https ://docs.chef.io/install_dk.html 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 ://github.com/chef/chef-dk#using-chefdk-as-your-primary-development-environment 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) Sign in to Docker Desktop | Docker Docs

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)... https://github.com/search?o=desc&q=docker-chefdk&s=updated&type=Repositories&utf8=✓

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

Thanks,
Martin.

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
thejeffbyrnes.com
@thejeffbyrnes https://twitter.com/thejeffbyrnes

1 Like

Thanks, Jeff.

I look forward to your input!

Regards, M.

Looks like https://github.com/chef/chef-dk/issues/313 is much the same set of problems.

It’s also remiss of me to not mention https://github.com/docwhat/rbenv-chefdk

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
# github.com/sstephenson/rbenv/
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
/Users/jeffbyrnes/.chefdk/gem/ruby/2.1.0/bin:
/opt/chefdk/bin:
/usr/local/var/rbenv/shims:
/Users/jeffbyrnes/dev/devops/evertools/scripts:
/usr/local/heroku/bin:
/Users/jeffbyrnes/.cabal/bin:
/Users/jeffbyrnes/.go/bin:
/usr/local/opt/coreutils/libexec/gnubin:
/Users/jeffbyrnes/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin:
/opt/X11/bin:
/usr/local/MacGPG2/bin

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 https://feedback.chef.io/forums/301644-chef-product-feedback/suggestions/15152973-chefdk-needs-to-be-rbenv-aware

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
@thejeffbyrnes
thejeffbyrnes.com

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. https://github.com/docwhat/rbenv-chefdk/issues/13#issuecomment-232841828

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!