Class: EbDeployer::EbEnvironment

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/eb_deployer/eb_environment.rb

Constant Summary

Constants included from Utils

Utils::BACKOFF_INITIAL_SLEEP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#backoff, #reject_nil, #symbolize_keys

Constructor Details

#initialize(app, name, eb_driver, creation_opts = {}) ⇒ EbEnvironment

Returns a new instance of EbEnvironment.



14
15
16
17
18
19
20
21
# File 'lib/eb_deployer/eb_environment.rb', line 14

def initialize(app, name, eb_driver, creation_opts={})
  @app = app
  @name = self.class.unique_ebenv_name(name, app)
  @bs = eb_driver
  @creation_opts = default_create_options.merge(reject_nil(creation_opts))
  @accepted_healthy_states = @creation_opts[:accepted_healthy_states]
  @event_poller = nil
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/eb_deployer/eb_environment.rb', line 5

def app
  @app
end

#event_poller=(value) ⇒ Object

Sets the attribute event_poller

Parameters:

  • value

    the value to set the attribute event_poller to.



6
7
8
# File 'lib/eb_deployer/eb_environment.rb', line 6

def event_poller=(value)
  @event_poller = value
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/eb_deployer/eb_environment.rb', line 5

def name
  @name
end

Class Method Details

.unique_ebenv_name(env_name, app_name) ⇒ Object



8
9
10
11
12
# File 'lib/eb_deployer/eb_environment.rb', line 8

def self.unique_ebenv_name(env_name, app_name)
  raise "Environment name #{env_name} is too long, it must be under 15 chars" if env_name.size > 15
  digest = Digest::SHA1.hexdigest(app_name + '-' + env_name)[0..6]
  "#{env_name}-#{digest}"
end

Instance Method Details

#apply_settings(settings) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/eb_deployer/eb_environment.rb', line 36

def apply_settings(settings)
  raise "Env #{self.name} not exists for applying settings" unless @bs.environment_exists?(@app, @name)
  wait_for_env_status_to_be_ready
  with_polling_events(/Successfully deployed new configuration to environment/i) do
    @bs.update_environment_settings(@app, @name, settings)
  end
end

#cname_prefixObject



44
45
46
# File 'lib/eb_deployer/eb_environment.rb', line 44

def cname_prefix
  @bs.environment_cname_prefix(@app, @name)
end

#deploy(version_label, settings = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/eb_deployer/eb_environment.rb', line 23

def deploy(version_label, settings={})
  terminate if @creation_opts[:phoenix_mode]

  if @bs.environment_exists?(@app, @name)
    update_eb_env(settings, version_label)
  else
    create_eb_env(settings, version_label)
  end

  smoke_test
  wait_for_env_become_healthy
end

#health_stateObject



67
68
69
# File 'lib/eb_deployer/eb_environment.rb', line 67

def health_state
  @bs.environment_health_state(@app, @name)
end

#log(msg) ⇒ Object



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

def log(msg)
  puts "[#{Time.now.utc}][environment:#{@name}] #{msg}"
end

#swap_cname_with(another) ⇒ Object



48
49
50
51
52
53
# File 'lib/eb_deployer/eb_environment.rb', line 48

def swap_cname_with(another)
  log("Swap CNAME with env #{another.name}")
  with_polling_events(/Completed swapping CNAMEs for environments/i) do
    @bs.environment_swap_cname(self.app, self.name, another.name)
  end
end

#terminateObject



59
60
61
62
63
64
65
# File 'lib/eb_deployer/eb_environment.rb', line 59

def terminate
  if @bs.environment_exists?(@app, @name)
    with_polling_events(/terminateEnvironment completed successfully/i) do
      @bs.delete_environment(@app, @name)
    end
  end
end