Class: DeisInteractive::Rails::Exec

Inherits:
Base
  • Object
show all
Defined in:
lib/deis-interactive/rails/exec.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app, #process

Instance Method Summary collapse

Methods inherited from Base

#deis_remote, #git_remote_response, #inferred_app, #pod_ids, #processes_pattern

Constructor Details

#initialize(app, cmd, params) ⇒ Exec

Returns a new instance of Exec.



11
12
13
14
15
# File 'lib/deis-interactive/rails/exec.rb', line 11

def initialize(app, cmd, params)
  super(app, ENV['DEIS_CONSOLE_PROCESS'] || "web")
  @cmd = cmd
  @params = params
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



8
9
10
# File 'lib/deis-interactive/rails/exec.rb', line 8

def cmd
  @cmd
end

#paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/deis-interactive/rails/exec.rb', line 9

def params
  @params
end

Instance Method Details

#argsObject



17
18
19
20
21
22
23
# File 'lib/deis-interactive/rails/exec.rb', line 17

def args
  result = [cmd]
  if params
    result += params
  end
  result
end

#bashObject



46
47
48
# File 'lib/deis-interactive/rails/exec.rb', line 46

def bash
  Shellwords.escape(". /app/.profile.d/ruby.sh && PATH=/app/.heroku/node/bin:$PATH && #{escaped_args}")
end

#escaped_argsObject



25
26
27
28
29
# File 'lib/deis-interactive/rails/exec.rb', line 25

def escaped_args
  args.map do |arg|
    Shellwords.escape(arg)
  end.join(" ")
end

#performObject



31
32
33
34
# File 'lib/deis-interactive/rails/exec.rb', line 31

def perform
  puts "Execute #{args} on #{pod_id}"
  exec "kubectl exec -it --namespace #{app} #{pod_id} -- bash -c #{bash}"
end

#pod_idObject



36
37
38
39
40
41
42
43
44
# File 'lib/deis-interactive/rails/exec.rb', line 36

def pod_id
  @pod_id ||= (
    sample_pod_id = pod_ids.sample
    if (sample_pod_id.nil?)
      raise "Error. No pod of #{process} is found. kubectl won't be able to attach to run a console session"
    end
    sample_pod_id
  )
end