Class: Kitchen::Provisioner::Chef::Policyfile

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

Overview

Chef cookbook resolver that uses Policyfiles to calculate dependencies.

Author:

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ShellOut

#run_command

Methods included from Logging

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

Constructor Details

#initialize(policyfile, path, logger = Kitchen.logger) ⇒ Policyfile

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



44
45
46
47
48
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 44

def initialize(policyfile, path, logger = Kitchen.logger)
  @policyfile = policyfile
  @path       = path
  @logger     = logger
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



54
55
56
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 54

def self.load!(logger = Kitchen.logger)
  detect_chef_command!(logger)
end

Instance Method Details

#compileObject

Runs chef install to determine the correct cookbook set and generate the policyfile lock.



67
68
69
70
71
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 67

def compile
  info("Policy lock file doesn't exist, running `chef install` for "\
       "Policyfile #{policyfile}...")
  run_command("chef install #{policyfile}")
end

#resolveObject

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



60
61
62
63
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 60

def resolve
  info("Exporting cookbook dependencies from Policyfile #{path}...")
  run_command("chef export #{policyfile} #{path} --force")
end