Class: Skewer::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/source.rb

Overview

responsible for moving source to remote nodes

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Source

Returns a new instance of Source.



6
7
8
9
10
# File 'lib/source.rb', line 6

def initialize(path = nil)
  @util = Util.new
  raise "I can't see the path #{path}" unless File.exists?(path)
  @path = path.sub(/\/$/, '')
end

Instance Method Details

#create_destination(node) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/source.rb', line 16

def create_destination(node)
  begin
    node.ssh('mkdir -p infrastructure')
  rescue
    location = @util.get_location(node)
    raise "Couldn't SSH to #{location} with #{node.username}"
  end
end

#excludesObject



12
13
14
# File 'lib/source.rb', line 12

def excludes
  '--exclude Gemfile --exclude Gemfile.lock --exclude ' + ['.git'].join(' ')
end

#mock_rsync(command) ⇒ Object



30
31
32
# File 'lib/source.rb', line 30

def mock_rsync(command)
  Skewer.logger.debug "MOCK: #{command}"
end

#real_rsync(node, command) ⇒ Object



34
35
36
37
# File 'lib/source.rb', line 34

def real_rsync(node, command)
  location = @util.get_location(node)
  raise "Failed to rsync to #{location} with #{node.username}" unless system(command)
end

#rsync(node) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/source.rb', line 39

def rsync(node)
  location = @util.get_location(node)
  Skewer.logger.debug "Copying code to #{location} ..."
  create_destination(node)
  command = self.rsync_command(node)

  if node.class.to_s =~ /StubNode/
    mock_rsync(command)
  else
    real_rsync(node, command)
  end
  Skewer.logger.debug " Done."
end

#rsync_command(node) ⇒ Object



25
26
27
28
# File 'lib/source.rb', line 25

def rsync_command(node)
  location = @util.get_location(node)
  "rsync #{self.excludes} --delete -arpze ssh #{@path}/. #{node.username}@#{location}:infrastructure/."
end