Class: Jack::Create

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/jack/create.rb

Instance Method Summary collapse

Methods included from Util

#app_name_convention, #do_cmd, #eb

Constructor Details

#initialize(options = {}) ⇒ Create

Returns a new instance of Create.



7
8
9
10
11
12
13
# File 'lib/jack/create.rb', line 7

def initialize(options={})
  @options = options
  @root = options[:root] || '.'
  @env_name = options[:env_name]
  @app_name = options[:app_name] || app_name_convention(@env_name)
  @upload = Config::Upload.new(@options)
end

Instance Method Details

#app_name_mismatchObject



26
27
28
29
30
31
32
33
# File 'lib/jack/create.rb', line 26

def app_name_mismatch
  return true unless File.exist?("#{@root}/.elasticbeanstalk/config.yml")
  return if @options[:noop]
  eb_config_path = @upload.eb_config_path
  data = YAML.load_file(eb_config_path)
  application_name = data['global']['application_name']
  application_name != @app_name
end

#build_commandObject



54
55
56
57
58
# File 'lib/jack/create.rb', line 54

def build_command
  @cfg = upload_cfg
  flags = create_yaml.inject("") {|s,(k,v)| s << %{--#{k} "#{v}" } ; s }.strip
  "eb create --nohang #{flags} #{@cfg}#{cname}#{@env_name}"
end

#cnameObject



82
83
84
# File 'lib/jack/create.rb', line 82

def cname
  "--cname #{@env_name} "
end

#create_envObject



49
50
51
52
# File 'lib/jack/create.rb', line 49

def create_env
  command = build_command
  do_cmd(command, @options)
end

#create_yamlObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jack/create.rb', line 60

def create_yaml
  return @create_yaml if @create_yaml

  project_file = "#{@root}/jack/create.yml"
  project = File.exist?(project_file) ? YAML.load_file(project_file) : {}

  user_file = "#{ENV['HOME']}/.jack/create.yml"
  user = File.exist?(user_file) ? YAML.load_file(user_file) : {}

  default_file = File.expand_path("../default/create.yml", __FILE__)
  default = YAML.load_file(default_file)

  @create_yaml = default.merge(project.merge(user))
end

#ensure_eb_initObject



20
21
22
23
24
# File 'lib/jack/create.rb', line 20

def ensure_eb_init
  if app_name_mismatch
    do_cmd(%Q|eb init -p "#{platform}" "#{@app_name}"|, @options)
  end
end

#latest_docker_platformObject



39
40
41
42
# File 'lib/jack/create.rb', line 39

def latest_docker_platform
  return if @options[:noop] # for cli spec
  solution_stacks.grep(/Docker/).reject {|x| x =~ /Preconfigured/}.sort.last
end

#platformObject



35
36
37
# File 'lib/jack/create.rb', line 35

def platform
  create_yaml['platform'] || latest_docker_platform
end

#runObject



15
16
17
18
# File 'lib/jack/create.rb', line 15

def run
  ensure_eb_init
  create_env
end

#solution_stacksObject

for specs



45
46
47
# File 'lib/jack/create.rb', line 45

def solution_stacks
  eb.list_available_solution_stacks.solution_stacks
end

#upload_cfgObject



75
76
77
78
79
80
# File 'lib/jack/create.rb', line 75

def upload_cfg
  if @upload.local_cfg_exist?
    @upload.upload 
    cfg = "--cfg #{@upload.upload_name} "
  end
end