Class: Kitchen::Provisioner::Chef::Policyfile
- Inherits:
-
Object
- Object
- Kitchen::Provisioner::Chef::Policyfile
- Defined in:
- lib/kitchen/provisioner/chef/policyfile.rb
Overview
Chef cookbook resolver that uses Policyfiles to calculate dependencies.
Class Method Summary collapse
-
.detect_chef_command!(logger) ⇒ Object
private
Ensure the
chefcommand is in the path. -
.load!(logger: Kitchen.logger) ⇒ Object
Loads the library code required to use the resolver.
Instance Method Summary collapse
-
#compile ⇒ Object
Runs
chef installto determine the correct cookbook set and generate the policyfile lock. -
#initialize(policyfile, path, logger: Kitchen.logger, always_update: false) ⇒ Policyfile
constructor
Creates a new cookbook resolver.
-
#lockfile ⇒ String
Return the path to the lockfile corresponding to this policyfile.
-
#resolve ⇒ Object
Performs the cookbook resolution and vendors the resulting cookbooks in the desired path.
Methods included from ShellOut
Methods included from Logging
#banner, #debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(policyfile, path, logger: Kitchen.logger, always_update: false) ⇒ Policyfile
Creates a new cookbook resolver.
43 44 45 46 47 48 |
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 43 def initialize(policyfile, path, logger: Kitchen.logger, always_update: false) @policyfile = policyfile @path = path @logger = logger @always_update = always_update end |
Class Method Details
.detect_chef_command!(logger) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ensure the chef command is in the path.
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 111 def self.detect_chef_command!(logger) unless ENV["PATH"].split(File::PATH_SEPARATOR).any? do |p| File.exist?(File.join(p, "chef")) end logger.fatal("The `chef` executable cannot be found in your " \ "PATH. Ensure you have installed ChefDK from " \ "https://downloads.chef.io and that your PATH " \ "setting includes the path to the `chef` comand.") raise UserError, "Could not find the chef executable in your PATH." end end |
.load!(logger: Kitchen.logger) ⇒ Object
Loads the library code required to use the resolver.
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
#compile ⇒ Object
Runs chef install to determine the correct cookbook set and
generate the policyfile lock.
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 67 def compile if always_update info("Updating policy lock using `chef update`") run_command("chef update #{escape_path(policyfile)}") end if File.exist?(lockfile) info("Installing cookbooks for Policyfile #{policyfile} using `chef install`") else info("Policy lock file doesn't exist, running `chef install` for "\ "Policyfile #{policyfile}...") end run_command("chef install #{escape_path(policyfile)}") end |
#lockfile ⇒ String
Return the path to the lockfile corresponding to this policyfile.
84 85 86 |
# File 'lib/kitchen/provisioner/chef/policyfile.rb', line 84 def lockfile policyfile.gsub(/\.rb\Z/, ".lock.json") end |
#resolve ⇒ Object
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 #{escape_path(policyfile)} #{escape_path(path)} --force") end |