Sha256: 1f8b50801f35e5a43fb3edcb48815ce8ca5342a148506b91499b44d378d4b193

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

require 'railway'
require 'runner'

module EY
  module Serverside
    module Slug
      class Distributor
        include Railway
        include Runner

        step :find_remotes
        step :distribute_to_remotes

        def self.distribute(data = {})
          new(data[:config], data[:shell], data[:servers]).call(data)
        end

        attr_reader :config, :shell, :servers

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

        private
        def find_remotes(input = {})
          remotes = servers.
            to_a.
            reject {|server| server.role.to_sym == :app_master}

          Success(input.merge(:remotes => remotes))
        end

        def distribute_to_remotes(input = {})
          remotes = input[:remotes]
          releases_path = "/data/#{input[:app_name]}/releases"
          package = "#{releases_path}/#{input[:release_name]}.tgz"
          internal_key = config.paths.internal_key

          remotes.each do |remote|
            cmd = "scp -i #{internal_key} #{package} #{remote.user}@#{remote.hostname}:#{releases_path}"

            unless run_and_success?(cmd)
              return Failure(
                input.merge(
                  :error => "Could not copy #{package} to #{remote.hostname}"
                )
              )
            end
          end

          Success(input)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
engineyard-serverside-3.0.4 lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-3.0.3 lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.8.0 lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.8.0.pre4 lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.8.0.pre3 lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.8.0.pre2 lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.8.0.pre lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.7.0.pre lib/engineyard-serverside/slug/distributor.rb
engineyard-serverside-2.6.19 lib/engineyard-serverside/slug/distributor.rb