Module: Ebfly::Command

Included in:
App, Config, ElasticBeanstalk, Environment
Defined in:
lib/ebfly/ebfly.rb

Constant Summary collapse

PREDEFINED_SOLUTION_STACKS =
{
  "php54"    => "64bit Amazon Linux 2014.09 v1.0.9 running PHP 5.4",
  "php55"    => "64bit Amazon Linux 2014.09 v1.0.9 running PHP 5.5",
  "nodejs"   => "64bit Amazon Linux 2014.09 v1.0.9 running Node.js",
  "python26" => "64bit Amazon Linux 2014.09 v1.0.9 running Python",
  "python27" => "64bit Amazon Linux 2014.09 v1.0.9 running Python 2.7",
  "ruby19"   => "64bit Amazon Linux 2014.09 v1.0.9 running Ruby 1.9.3",
  "ruby20"   => "64bit Amazon Linux 2014.09 v1.0.9 running Ruby 2.0 (Passenger Standalone)",
  "ruby20-puma" => "64bit Amazon Linux 2014.09 v1.0.9 running Ruby 2.0 (Puma)",
  "ruby21"   => "64bit Amazon Linux 2014.09 v1.0.9 running Ruby 2.1 (Passenger Standalone)",
  "ruby21-puma" => "64bit Amazon Linux 2014.09 v1.0.9 running Ruby 2.1 (Puma)",
  "docker0.9" => "64bit Amazon Linux 2014.03 v1.0.5 running Docker 0.9.0",
  "docker09" => "64bit Amazon Linux 2014.03 v1.0.5 running Docker 0.9.0",
  "docker10" => "64bit Amazon Linux 2014.03 v1.0.9 running Docker 1.0.0",
  "docker13" => "64bit Amazon Linux 2014.09 v1.0.11 running Docker 1.3.3",
}
SUPPORTED_SOLUTION_STACKS =
['Docker', 'Node.js', 'PHP', 'Python', 'Ruby']

Instance Method Summary collapse

Instance Method Details

#debug(obj) ⇒ Object



55
56
57
# File 'lib/ebfly/ebfly.rb', line 55

def debug(obj)
  pp obj if ENV["DEBUG"]
end

#ebObject



27
28
29
30
# File 'lib/ebfly/ebfly.rb', line 27

def eb
  @eb ||= AWS::ElasticBeanstalk.new
  @eb.client
end

#env_name(app, env) ⇒ Object



70
71
72
# File 'lib/ebfly/ebfly.rb', line 70

def env_name(app, env)
  "#{app}-#{env}"
end

#exist_command?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
# File 'lib/ebfly/ebfly.rb', line 59

def exist_command?(cmd)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
  exts.each { |ext|
    exe = File.join(path, "#{cmd}#{ext}")
    return exe if File.executable? exe
  }
  end
  return nil
end

#run(&block) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/ebfly/ebfly.rb', line 36

def run(&block)
  begin
    res = yield
    raise res.error unless res.successful?
    res
  rescue => err
    style_err(err)
    exit 1
  end
end

#s3Object



32
33
34
# File 'lib/ebfly/ebfly.rb', line 32

def s3
  @s3 ||= AWS::S3.new
end

#s3_bucketObject



47
48
49
# File 'lib/ebfly/ebfly.rb', line 47

def s3_bucket
  @s3_bucket ||= (run { eb.create_storage_location }[:s3_bucket])
end

#solution_stack(name) ⇒ Object



86
87
88
89
# File 'lib/ebfly/ebfly.rb', line 86

def solution_stack(name)
  return PREDEFINED_SOLUTION_STACKS[name] if PREDEFINED_SOLUTION_STACKS.key?(name)
  return name
end

#style_err(err) ⇒ Object



51
52
53
# File 'lib/ebfly/ebfly.rb', line 51

def style_err(err)
  puts "ERR! #{err.message}" 
end

#tier(type) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ebfly/ebfly.rb', line 74

def tier(type)
  if type == "web"
    return { name: "WebServer", type: "Standard", version: "1.0" }
  elsif type == "worker"
    return { name: "Worker", type: "SQS/HTTP", version: "1.1" }
  elsif type == "worker1.0"
    return { name: "Worker", type: "SQS/HTTP", version: "1.0" }
  else
    raise "Environment tier definition not found"
  end
end