kitchen-docker: How to run a shell command before kitchen converge

919 views Asked by At

When using vagrant machines with test-kitchen the pre_create_command allows you to specify a command which is run locally before the vagrant machine is being created. With kitchen-docker no such configuration option seems to exist, and bending chef_omnibus_url as suggested here isn't an option.

The script specified as pre_create_command for the testing vagrants generates a local chef data bag.

Is there a solution around which I've overlooked?

3

There are 3 answers

0
trish On

I sketched a patch for kitchen-docker here. However, as the discussion on this pull request shows, there are arguments against an appropriate functionality in kitchen-docker, namely the one that such functionality (if ever) should go in the kitchen core.

So for the time being we have to live with this inconsistency between docker and vagrant, and this is where thun's answer comes into play.

3
thun On

Best practices include Rakefile and Thor.

In essence you control your tests from a Rakefile. For example:

rake style

This will run all commands under your style task (maybe lint/syntax/unit and kitchen tests). Of course you can modify your tasks to perform whatever you like. Here are some good resources:

https://blog.chef.io/2015/04/21/overview-of-test-driven-infrastructure-with-chef/

See the Supporting Tools and Dependencies section.

Here is an example Rakefile:

https://github.com/chef-cookbooks/chef-server/blob/master/Rakefile

0
Rshad Zhran On

This can be done using

driver_config:
  provision_command: <command>

in kitchen.yml

Check more here

Kr,

Rshad