Class: Kitchen::Provisioner::Cinc::Policyfile

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

Overview

Cinc cookbook resolver that uses Policyfiles to calculate dependencies.

Author:

  • Cinc Project

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policyfile, path, logger: Kitchen.logger, always_update: false, policy_group: nil) ⇒ Policyfile

Creates a new cookbook resolver.

Parameters:

  • policyfile (String)

    path to a Policyfile

  • 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`



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

def initialize(policyfile, path, logger: Kitchen.logger, always_update: false, policy_group: nil)
  @policyfile    = policyfile
  @path          = path
  @logger        = logger
  @always_update = always_update
  @policy_group  = policy_group
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`



55
56
57
# File 'lib/kitchen/provisioner/cinc/policyfile.rb', line 55

def self.load!(logger: Kitchen.logger)
  # intentionally left blank
end

Instance Method Details

#compileObject

Runs ‘cinc install` to determine the correct cookbook set and generate the policyfile lock.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/kitchen/provisioner/cinc/policyfile.rb', line 73

def compile
  if File.exist?(lockfile)
    info("Installing cookbooks for Policyfile #{policyfile} using `#{cli_path} install`")
  else
    info("Policy lock file doesn't exist, running `#{cli_path} install` for Policyfile #{policyfile}...")
  end
  run_command("#{cli_path} install #{escape_path(policyfile)}")

  if always_update
    info("Updating policy lock using `#{cli_path} update`")
    run_command("#{cli_path} update #{escape_path(policyfile)}")
  end
end

#lockfileString

Return the path to the lockfile corresponding to this policyfile.

Returns:

  • (String)


90
91
92
# File 'lib/kitchen/provisioner/cinc/policyfile.rb', line 90

def lockfile
  policyfile.gsub(/\.rb\Z/, ".lock.json")
end

#resolveObject

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



61
62
63
64
65
66
67
68
69
# File 'lib/kitchen/provisioner/cinc/policyfile.rb', line 61

def resolve
  if policy_group
    info("Exporting cookbook dependencies from Policyfile #{path} with policy_group #{policy_group} using `#{cli_path} export`...")
    run_command("#{cli_path} export #{escape_path(policyfile)} #{escape_path(path)} --policy_group #{policy_group} --force")
  else
    info("Exporting cookbook dependencies from Policyfile #{path} using `#{cli_path} export`...")
    run_command("#{cli_path} export #{escape_path(policyfile)} #{escape_path(path)} --force")
  end
end