Sha256: beac46a169618e72752a74ab0a8b18f4dfdeb413b6958dac05e6fd122bace26d

Contents?: true

Size: 1.61 KB

Versions: 13

Compression:

Stored size: 1.61 KB

Contents

require 'forwardable'
require 'engineyard-serverside/about'

module EY
  module Serverside

    # Propagator ensures that a proper version of the engineyard-serverside
    # gem is installed on a given set of servers
    class Propagator
      def self.propagate(servers, shell)
        new(servers, shell).propagate
      end

      extend Forwardable

      def_delegators About, :gem_binary, :gem_file, :gem_filename, :gem_name,
        :name_with_version, :version

      attr_reader :servers, :shell

      def initialize(servers, shell)
        @servers = servers
        @shell = shell
      end

      def propagate
        shell.status "Verifying and propagating #{name_with_version} to all servers."

        servers.remote.run_for_each! do |server|
          propagation_command_for(server)
        end
      end

      private
      def propagation_command_for(server)
        check = server.command_on_server('sh -l -c', check_command)
        scp = server.scp_command(About.gem_file, remote_gem_file)
        install = server.command_on_server('sudo sh -l -c', install_command)

        "(#{check}) || ((#{scp}) && (#{install}))"
      end

      def remote_gem_file
        @remote_gem_file ||= File.join(Dir.tmpdir, gem_filename)
      end

      def check_command
        # the [,)] is to stop us from looking for e.g. 0.5.1, seeing
        # 0.5.11, and mistakenly thinking 0.5.1 is there

         %{#{gem_binary} list #{gem_name} | grep "#{gem_name}" | egrep -q "#{version.gsub(/\./, '\.')}[,)]"}
      end

      def install_command
        "#{gem_binary} install --no-rdoc --no-ri '#{remote_gem_file}'"
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
engineyard-serverside-3.0.3 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.8.0 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.8.0.pre4 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.8.0.pre3 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.8.0.pre2 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.8.0.pre lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.7.0.pre lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.6.19 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.6.17 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.6.16 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.6.15.alpha1 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.6.15.cf2 lib/engineyard-serverside/propagator.rb
engineyard-serverside-2.6.15.pre lib/engineyard-serverside/propagator.rb