Class: EbDeployer::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/eb_deployer/environment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env_name, eb_driver, creation_opts = {}) ⇒ Environment

Returns a new instance of Environment.



12
13
14
15
16
17
# File 'lib/eb_deployer/environment.rb', line 12

def initialize(app, env_name, eb_driver, creation_opts={})
  @app = app
  @name = self.class.unique_ebenv_name(app, env_name)
  @bs = eb_driver
  @creation_opts = creation_opts
end

Instance Attribute Details

#app ⇒ Object (readonly)

Returns the value of attribute app.



3
4
5
# File 'lib/eb_deployer/environment.rb', line 3

def app
  @app
end

#event_poller=(value) ⇒ Object

Sets the attribute event_poller

Parameters:

  • value —

    the value to set the attribute event_poller to.



4
5
6
# File 'lib/eb_deployer/environment.rb', line 4

def event_poller=(value)
  @event_poller = value
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/eb_deployer/environment.rb', line 3

def name
  @name
end

Class Method Details

.unique_ebenv_name(app_name, env_name) ⇒ Object



6
7
8
9
10
# File 'lib/eb_deployer/environment.rb', line 6

def self.unique_ebenv_name(app_name, env_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

#==(another) ⇒ Object



30
31
32
# File 'lib/eb_deployer/environment.rb', line 30

def ==(another)
  self.app == another.app && self.name == another.name
end

#cname_prefix ⇒ Object



26
27
28
# File 'lib/eb_deployer/environment.rb', line 26

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

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



19
20
21
22
23
24
# File 'lib/eb_deployer/environment.rb', line 19

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

#log(msg) ⇒ Object



39
40
41
# File 'lib/eb_deployer/environment.rb', line 39

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

#swap_cname_with(another) ⇒ Object



34
35
36
37
# File 'lib/eb_deployer/environment.rb', line 34

def swap_cname_with(another)
  log("Swap CNAME with env #{another.name}")
  @bs.environment_swap_cname(self.app, self.name, another.name)
end

#terminate ⇒ Object



43
44
45
46
47
48
49
# File 'lib/eb_deployer/environment.rb', line 43

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