Class: Stackato::Commands

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

Constant Summary collapse

@@executable =
"stackato-3.1.1"
@@token_file =
File.join(Dir.tmpdir(), "token_#{Time.now.to_i}")

Instance Method Summary collapse

Constructor Details

#initialize(target, dry_run = false) ⇒ Commands

Returns a new instance of Commands.



11
12
13
14
15
16
17
# File 'lib/conan/stackato.rb', line 11

def initialize(target, dry_run=false)
  @target = target
  @dry_run = dry_run
  v = get_version
  puts(v)
  raise "Stackato 3.1.* required. Found #{v}" unless v =~ /\(3\.1\.[0-9]+\)/
end

Instance Method Details

#delete(app_name) ⇒ Object



61
62
63
# File 'lib/conan/stackato.rb', line 61

def delete(app_name)
  shell_cmd("delete", "--no-prompt #{app_name}", true)
end

#get_versionObject



43
44
45
46
47
48
49
50
51
# File 'lib/conan/stackato.rb', line 43

def get_version    
  begin
    v, err, status = Open3.capture3("#{@@executable} version")
    abort "Stackato error: #{err}" unless status.success?        
    v
  rescue Exception => e
    abort "Failed to invoke Stackato client: #{e}"
  end    
end

#login(username, password, space) ⇒ Object



53
54
55
# File 'lib/conan/stackato.rb', line 53

def (username, password, space)
  shell_cmd("login", "--space #{space} --password '#{password}' #{username}")
end

#map(app_name, url) ⇒ Object



65
66
67
# File 'lib/conan/stackato.rb', line 65

def map(app_name, url)
  shell_cmd("map", "#{app_name} #{url}")
end

#push(manifest) ⇒ Object



57
58
59
# File 'lib/conan/stackato.rb', line 57

def push(manifest)
  shell_cmd("push", "--manifest #{manifest} --no-prompt --reset --timeout 15m")
end

#shell_cmd(stackato_cmd, args, ignoreErrs = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/conan/stackato.rb', line 19

def shell_cmd(stackato_cmd, args, ignoreErrs=false)
  base_args = "--target #{@target} --token-file #{@@token_file}"

  cmd = "#{@@executable} #{stackato_cmd} #{base_args} #{args}"

  if @dry_run
    puts "Dry-run, skipping execution of command: #{cmd}"
  else
    # output, err, status = Open3.capture3(cmd)
    #  raise "Stackato error: #{err}" unless (ignoreErrs||status.success?)
    #  output
    Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
      while line = stdout_err.gets
        puts line
      end

      exit_status = wait_thr.value
      unless ignoreErrs || exit_status.success?
        abort "Stackato #{stackato_cmd} failed: #{stdout_err.read}"
      end
    end
  end
end