Class: Jack::Config::Apply

Inherits:
Transmit show all
Includes:
Util
Defined in:
lib/jack/config/apply.rb

Instance Attribute Summary collapse

Attributes inherited from Transmit

#local_config_path

Instance Method Summary collapse

Methods included from Util

#app_name_convention, #aws_bin, #check_aws_setup, #confirm, #eb, #eb_base_flags, #eb_bin, #ensure_folder_exist, #get_answer, #get_region, #prerequisites, #settings, #sh

Methods inherited from Transmit

#extract_name, #timestamp

Constructor Details

#initialize(options = {}) ⇒ Apply

Returns a new instance of Apply.



10
11
12
13
14
# File 'lib/jack/config/apply.rb', line 10

def initialize(options={})
  super
  @upload_path = "#{@saved_configs}/#{@env_name}-#{timestamp}.cfg.yml"
  @upload_name = extract_name(@upload_path)
end

Instance Attribute Details

#upload_nameObject (readonly)

Returns the value of attribute upload_name.



8
9
10
# File 'lib/jack/config/apply.rb', line 8

def upload_name
  @upload_name
end

#upload_pathObject (readonly)

Returns the value of attribute upload_path.



8
9
10
# File 'lib/jack/config/apply.rb', line 8

def upload_path
  @upload_path
end

Instance Method Details

#clean_upObject



90
91
92
93
# File 'lib/jack/config/apply.rb', line 90

def clean_up
  return if @options[:dirty]
  FileUtils.rm_f(@upload_path)
end

#compareObject



46
47
48
# File 'lib/jack/config/apply.rb', line 46

def compare
  Diff.new(@options).run
end

#confirmation_messageObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/jack/config/apply.rb', line 34

def confirmation_message
  message = "Are you sure you want to update the environment with your the new config #{@local_config_path}?\n".colorize(:yellow)
  message += <<-EOL
If the difference is not what you expected, you should say no.
If you want to download the config from the environment and get #{@local_config_path}
back in sync, you can use this command:
  $ jack get #{@env_name}
  $ jack get -h # for more info
EOL
  message
end

#cp_to_save_configsObject



76
77
78
79
# File 'lib/jack/config/apply.rb', line 76

def cp_to_save_configs
  ensure_folder_exist(@saved_configs)
  FileUtils.cp("#{@root}/#{@local_config_path}", @upload_path)
end

#eb_config_putObject

for specs



86
87
88
# File 'lib/jack/config/apply.rb', line 86

def eb_config_put
  sh("#{eb_bin} config put#{eb_base_flags} #{upload_name}", @options)
end

#local_cfg_exist?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/jack/config/apply.rb', line 72

def local_cfg_exist?
  File.exist?("#{@root}/#{@local_config_path}")
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jack/config/apply.rb', line 16

def run
  unless local_cfg_exist?
    UI.say "#{local_config_path} does not exist, nothing to upload"
    exit 0
  end
  difference = compare
  if difference
    if confirm(confirmation_message)
      upload
      update_env
    else
      UI.say("Whew, that was close. EB Configuration was not updated.")
    end
  else
    UI.say("There was no difference detected from your #{@local_config_path} and what exists on the EB environment")
  end
end

#update_envObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/jack/config/apply.rb', line 58

def update_env
  UI.say("Updating environment #{@env_name} with template #{upload_name}")
  begin
    eb.update_environment(
      environment_name: @env_name,
      template_name: upload_name
    ) unless @options[:noop]
  rescue Aws::ElasticBeanstalk::Errors::InvalidParameterValue => e
    puts "ERROR: Unable to update the environment: #{@env_name}".colorize(:red)
    puts e.message.colorize(:red)
    exit 1
  end
end

#uploadObject



50
51
52
53
54
55
56
# File 'lib/jack/config/apply.rb', line 50

def upload
  return false unless local_cfg_exist?
  UI.say("Copying #{@local_config_path} to #{@upload_path} for the upload")
  cp_to_save_configs
  upload_to_eb
  clean_up
end

#upload_to_ebObject



81
82
83
# File 'lib/jack/config/apply.rb', line 81

def upload_to_eb
  eb_config_put
end