Class: Kitchen::Provisioner::Cinc::Berkshelf

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

Overview

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

Author:

  • Cinc Project

Class Method Summary collapse

Instance Method Summary collapse

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`



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

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`



48
49
50
# File 'lib/kitchen/provisioner/cinc/berkshelf.rb', line 48

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.



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

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