Class: Vagabond::Uploader::Berkshelf

Inherits:
Knife show all
Defined in:
lib/vagabond/uploader/berkshelf.rb

Instance Attribute Summary

Attributes inherited from Vagabond::Uploader

#options, #store, #ui, #vagabondfile

Instance Method Summary collapse

Methods inherited from Knife

#upload

Methods inherited from Vagabond::Uploader

#upload

Methods included from Helpers

included

Constructor Details

#initialize(*args) ⇒ Berkshelf

Returns a new instance of Berkshelf.



8
9
10
11
12
13
14
15
# File 'lib/vagabond/uploader/berkshelf.rb', line 8

def initialize(*args)
  super
  %w(berksfile).each do |k|
    unless(options[k])
      raise ArgumentError.new "Option '#{k}' must be provided!"
    end
  end
end

Instance Method Details

#prepareObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagabond/uploader/berkshelf.rb', line 17

def prepare
  path = File.join(store, 'berks.json')
  if(File.exists?(path))
    cur = Mash.new(JSON.load(File.read(path)))
  else
    cur = Mash.new
  end
  url = options[:chef_server_url] || 'http://127.0.0.1'
  if(cur[:chef].nil? || cur[:chef][:chef_server_url] != url)
    cur[:chef] = Mash.new(:chef_server_url => url)
    cur[:ssl] = Mash.new(:verify => false)
    File.open(path, 'w') do |file|
      file.write(JSON.dump(cur))
    end
  end
  vendor
  options[:cookbook_paths] = [File.join(store, 'cookbooks')]
end

#vendor(*args) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/vagabond/uploader/berkshelf.rb', line 36

def vendor(*args)
  FileUtils.mkdir_p(ckbk_store = File.join(store, 'cookbooks'))
  com = "berks install -b #{options[:berksfile]} -p #{ckbk_store} #{Array(options[:berks_opts]).compact.flatten.join(' ')}"
  debug(com)
  cmd = Mixlib::ShellOut.new(com, :live_stream => options[:debug])
  cmd.run_command
  cmd.error!
end