Sha256: e9995a72ebc229b6aadf68e474c3e81b9a74cb3d122a5d7889c35d8aa296e7dd

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

require 'tempfile'

module Berkshelf
  module Vagrant
    module Action
      class Upload
        include Berkshelf::Vagrant::EnvHelpers

        def initialize(app, env)
          @app = app
        end

        def call(env)
          if provision_disabled?(env)
            return @app.call(env)
          end

          unless berkshelf_enabled?(env)
            return @app.call(env)
          end

          if chef_client?(env)
            upload(env)
          end

          @app.call(env)
        end

        private

          def upload(env)
            provisioners(:chef_client, env).each do |provisioner|
              begin
                # Temporarily generate a berkshelf configuration to pass to the CLI since not all versions
                # of the CLI allow overriding all options needed for upload.
                tmp_config = Tempfile.new("berks-config")
                config     = BerksConfig.instance.dup
                config[:chef][:chef_server_url] = provisioner.config.chef_server_url
                tmp_config.write(config.to_json)
                tmp_config.flush

                env[:berkshelf].ui.info "Uploading cookbooks to '#{provisioner.config.chef_server_url}'"
                berks("upload", config: tmp_config.path, berksfile: berksfile_path(env), force: true,
                  freeze: false)
              ensure
                tmp_config.close! unless tmp_config.nil?
              end
            end
          end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-berkshelf-3.0.1 lib/berkshelf/vagrant/action/upload.rb
vagrant-berkshelf-3.0.0 lib/berkshelf/vagrant/action/upload.rb
vagrant-berkshelf-3.0.0.rc2 lib/berkshelf/vagrant/action/upload.rb
vagrant-berkshelf-3.0.0.rc1 lib/berkshelf/vagrant/action/upload.rb