Sha256: 0e4c9073bc8cadbb6e4d302e832372864b4935f7c5f1e0f874b7d8c2ddcdbe27

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

require 'vagabond/uploader/knife'

module Vagabond
  class Uploader
    class Berkshelf < Knife

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

      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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vagabond-0.2.8 lib/vagabond/uploader/berkshelf.rb
vagabond-0.2.6 lib/vagabond/uploader/berkshelf.rb