Module: PoiseBoiler::Kitchen

Extended by:
Kitchen
Included in:
Kitchen
Defined in:
lib/poise_boiler/kitchen.rb

Overview

Helpers for Test-Kitchen and .kitchen.yml configuration.

Since:

  • 1.0.0

Constant Summary collapse

PLATFORM_ALIASES =

Shorthand names for kitchen platforms.

See Also:

  • kitchen

Since:

  • 1.0.0

{
  'ubuntu' => %w{ubuntu-12.04 ubuntu-14.04},
  'rhel' => %w{centos-6 centos-7},
  'centos' => %w{rhel},
  'linux' => %w{ubuntu rhel},
}

Instance Method Summary collapse

Instance Method Details

#kitchen(platforms: 'ubuntu-14.04') ⇒ Object

Return a YAML string suitable for inclusion in a .kitchen.yml config. This will include the standard Poise/Halite boilerplate and some default values.

Examples:

.kitchen.yml

#<% require 'poise_boiler' %>
<%= PoiseBoiler.kitchen %>

Parameters:

  • platforms (String, Array<String>) (defaults to: 'ubuntu-14.04')

    Name(s) of platforms to use by default.

See Also:

Since:

  • 1.0.0



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/poise_boiler/kitchen.rb', line 45

def kitchen(platforms: 'ubuntu-14.04')
  # SPEC_BLOCK_CI is used to force non-locking behavior inside tests.
  chef_version = ENV['CHEF_VERSION'] || if ENV['SPEC_BLOCK_CI'] != 'true'
    # If there isn't a specific override, lock TK to use the same version of Chef as the Gemfile.
    require 'chef/version'
    Chef::VERSION
  end
  install_arguments = if ENV['POISE_MASTER_BUILD']
    # Use today's date as an ignored param to force the layer to rebuild.
    " -n -- #{Date.today}"
  elsif chef_version
    " -v #{chef_version}"
  else
    ''
  end
  {
    'chef_versions' => %w{12},
    'driver' => {
      'name' => (ENV['TRAVIS'] == 'true' ? 'dummy' : 'vagrant'),
      'require_chef_omnibus' => chef_version || true,
      'provision_command' => [
        # Run some installs at provision so they are cached in the image.
        # Install Chef (with the correct verison).
        "curl -L https://chef.io/chef/install.sh | bash -s --#{install_arguments}",
        # Install some kitchen-related gems. Normally installed during the verify step but that is idempotent.
        "env GEM_HOME=/tmp/verifier/gems GEM_PATH=/tmp/verifier/gems GEM_CACHE=/tmp/verifier/gems/cache /opt/chef/embedded/bin/gem install thor busser busser-serverspec serverspec bundler",
        # Fix directory permissions.
        "chown -R kitchen /tmp/verifier",
      ],
    },
    'transport' => {
      'name' => 'sftp',
    },
    'platforms' => expand_kitchen_platforms(platforms).map {|p| {'name' => p, 'run_list' => platform_run_list(p)} },
  }.to_yaml.gsub(/---[ \n]/, '')
end