Class: Shipper::Host

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Host

Returns a new instance of Host.



7
8
9
10
11
12
13
14
# File 'lib/shipper/host.rb', line 7

def initialize(options)
  @user, full_host = options['ssh_entry'].split('@')
  @host, @port = full_host.split(':')
  @port = @port || 22

  @location = options['location']
  @executor = nil
end

Instance Attribute Details

#executorObject

Returns the value of attribute executor.



5
6
7
# File 'lib/shipper/host.rb', line 5

def executor
  @executor
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/shipper/host.rb', line 5

def host
  @host
end

#locationObject

Returns the value of attribute location.



5
6
7
# File 'lib/shipper/host.rb', line 5

def location
  @location
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/shipper/host.rb', line 5

def port
  @port
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/shipper/host.rb', line 5

def user
  @user
end

Instance Method Details

#restart!(pull_changes: false) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/shipper/host.rb', line 20

def restart!(pull_changes: false)
  ::Net::SSH.start(host, user, port: port) do |ssh|
    load_executor(ssh)
    executor.cd location
    exec 'docker-compose pull' if pull_changes
    exec 'docker-compose down'
    exec 'docker-compose up -d'
  end
end

#update!Object



16
17
18
# File 'lib/shipper/host.rb', line 16

def update!
  restart!(pull_changes: true)
end