Class: ChefDK::PolicyfileServices::Install
- Inherits:
-
Object
- Object
- ChefDK::PolicyfileServices::Install
- Defined in:
- lib/chef-dk/policyfile_services/install.rb
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Instance Method Summary collapse
- #expanded_run_list ⇒ Object
- #generate_lock_and_install ⇒ Object
-
#initialize(policyfile: nil, ui: nil, root_dir: nil) ⇒ Install
constructor
A new instance of Install.
- #install_from_lock ⇒ Object
- #lockfile_path ⇒ Object
- #lockfile_relative_path ⇒ Object
- #policyfile_compiler ⇒ Object
- #policyfile_content ⇒ Object
- #policyfile_lock ⇒ Object
- #policyfile_lock_content ⇒ Object
- #policyfile_path ⇒ Object
- #policyfile_relative_path ⇒ Object
- #run ⇒ Object
- #storage_config ⇒ Object
Constructor Details
#initialize(policyfile: nil, ui: nil, root_dir: nil) ⇒ Install
Returns a new instance of Install.
31 32 33 34 35 36 37 38 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 31 def initialize(policyfile: nil, ui: nil, root_dir: nil) @policyfile_relative_path = policyfile @ui = ui @root_dir = root_dir @policyfile_content = nil @policyfile_compiler = nil end |
Instance Attribute Details
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
28 29 30 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 28 def root_dir @root_dir end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
29 30 31 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 29 def ui @ui end |
Instance Method Details
#expanded_run_list ⇒ Object
78 79 80 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 78 def policyfile_compiler..to_s end |
#generate_lock_and_install ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 98 def generate_lock_and_install policyfile_compiler.error! ui.msg "Building policy #{policyfile_compiler.name}" ui.msg "Expanded run list: " + + "\n" ui.msg "Caching Cookbooks..." policyfile_compiler.install lock_data = policyfile_compiler.lock.to_lock File.open(lockfile_path, "w+") do |f| f.print(FFI_Yajl::Encoder.encode(lock_data, pretty: true )) end ui.msg "" ui.msg "Lockfile written to #{lockfile_path}" rescue => error raise PolicyfileInstallError.new("Failed to generate Policyfile.lock", error) end |
#install_from_lock ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 121 def install_from_lock ui.msg "Installing cookbooks from lock" policyfile_lock.install_cookbooks rescue => error raise PolicyfileInstallError.new("Failed to install cookbooks from lockfile", error) end |
#lockfile_path ⇒ Object
66 67 68 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 66 def lockfile_path File.(lockfile_relative_path, root_dir) end |
#lockfile_relative_path ⇒ Object
62 63 64 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 62 def lockfile_relative_path policyfile_relative_path.gsub(/\.rb\Z/, '') + ".lock.json" end |
#policyfile_compiler ⇒ Object
74 75 76 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 74 def policyfile_compiler @policyfile_compiler ||= ChefDK::PolicyfileCompiler.evaluate(policyfile_content, policyfile_path, ui: ui) end |
#policyfile_content ⇒ Object
70 71 72 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 70 def policyfile_content @policyfile_content ||= IO.read(policyfile_path) end |
#policyfile_lock ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 86 def policyfile_lock return nil if policyfile_lock_content.nil? @policyfile_lock ||= begin lock_data = FFI_Yajl::Parser.new.parse(policyfile_lock_content) PolicyfileLock.new(storage_config, ui: ui).build_from_lock_data(lock_data) end end |
#policyfile_lock_content ⇒ Object
82 83 84 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 82 def policyfile_lock_content @policyfile_lock_content ||= IO.read(lockfile_path) if File.exist?(lockfile_path) end |
#policyfile_path ⇒ Object
58 59 60 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 58 def policyfile_path File.(policyfile_relative_path, root_dir) end |
#policyfile_relative_path ⇒ Object
54 55 56 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 54 def policyfile_relative_path @policyfile_relative_path || "Policyfile.rb" end |
#run ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 40 def run unless File.exist?(policyfile_path) # TODO: suggest next step. Add a generator/init command? Specify path to Policyfile.rb? # See card CC-232 raise PolicyfileNotFound, "Policyfile not found at path #{policyfile_path}" end if File.exist?(lockfile_path) install_from_lock else generate_lock_and_install end end |
#storage_config ⇒ Object
94 95 96 |
# File 'lib/chef-dk/policyfile_services/install.rb', line 94 def storage_config @storage_config ||= Policyfile::StorageConfig.new(relative_paths_root: root_dir) end |