Class: Shuttle::Session

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, target) ⇒ Session

Initialize a new session

Parameters:

  • deploy (Hashr)

    config

  • deploy (String)

    target



8
9
10
11
# File 'lib/shuttle/session.rb', line 8

def initialize(config, target)
  @config = config
  @target = target
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/shuttle/session.rb', line 3

def config
  @config
end

#targetObject (readonly)

Returns the value of attribute target.



3
4
5
# File 'lib/shuttle/session.rb', line 3

def target
  @target
end

Instance Method Details

#run(command) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/shuttle/session.rb', line 23

def run(command)
  strategy = config.app.strategy
  server = config.targets[target]

  ssh = Net::SSH::Session.new(server.host, server.user, server.password)
  ssh.open

  klass = Shuttle.const_get(strategy.capitalize)
  integration = klass.new(config, ssh, server, target)

  if integration.deploy_running?
    raise DeployError, "Another deployment is running"
  end

  begin
    integration.write_lock
    integration.send(command.to_sym)
    integration.write_revision
  rescue DeployError => err
    integration.cleanup_release
  rescue Exception => err
    integration.cleanup_release
  ensure
    integration.release_lock
  end

  ssh.close
end

#validateObject



13
14
15
16
17
18
19
20
21
# File 'lib/shuttle/session.rb', line 13

def validate
  if config.app.strategy.nil?
    raise ConfigError, "Deployment strategy is required"
  end

  if config.targets[target].nil?
    raise ConfigError, "Target does not exist"
  end
end