Class: Kitchen::Provisioner::Chef::Berkshelf

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/kitchen/provisioner/chef/berkshelf.rb

Overview

Chef cookbook resolver that uses Berkshelf and a Berksfile to calculate dependencies.

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#banner, #debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(berksfile, path, logger: Kitchen.logger, always_update: false) ⇒ Berkshelf

Creates a new cookbook resolver.

Parameters:

  • berksfile (String)

    path to a Berksfile

  • path (String)

    path in which to vendor the resulting cookbooks

  • logger (Kitchen::Logger) (defaults to: Kitchen.logger)

    a logger to use for output, defaults to `Kitchen.logger`


38
39
40
41
42
43
# File 'lib/kitchen/provisioner/chef/berkshelf.rb', line 38

def initialize(berksfile, path, logger: Kitchen.logger, always_update: false)
  @berksfile  = berksfile
  @path       = path
  @logger     = logger
  @always_update = always_update
end

Class Method Details

.load!(logger: Kitchen.logger) ⇒ Object

Loads the library code required to use the resolver.

Parameters:

  • logger (Kitchen::Logger) (defaults to: Kitchen.logger)

    a logger to use for output, defaults to `Kitchen.logger`


49
50
51
# File 'lib/kitchen/provisioner/chef/berkshelf.rb', line 49

def self.load!(logger: Kitchen.logger)
  load_berkshelf!(logger)
end

Instance Method Details

#resolveObject

Performs the cookbook resolution and vendors the resulting cookbooks in the desired path.


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen/provisioner/chef/berkshelf.rb', line 55

def resolve
  version = ::Berkshelf::VERSION
  info("Resolving cookbook dependencies with Berkshelf #{version}...")
  debug("Using Berksfile from #{berksfile}")

  ::Berkshelf.ui.mute do
    berksfile_obj = ::Berkshelf::Berksfile.from_file(berksfile)
    berksfile_obj.update if always_update && berksfile_obj.lockfile.present?
    # Berkshelf requires the directory to not exist
    FileUtils.rm_rf(path)
    berksfile_obj.vendor(path)
  end
end