Sha256: e8a78ca926e890c04a0549332c0c8d744236ee540f04807240082e0e2d5205da

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

#encoding: utf-8
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} #{Array(options[:berks_opts]).compact.flatten.join(' ')}"
        debug(com)
        cmd = Mixlib::ShellOut.new(com, :live_stream => options[:debug])
        cmd.run_command
        cmd.error!
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagabond-0.2.10 lib/vagabond/uploader/berkshelf.rb