Class: KumoDockerCloud::EnvironmentConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/kumo_dockercloud/environment_config.rb

Constant Summary collapse

LOGGER =
Logger.new(STDOUT)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, logger = LOGGER) ⇒ EnvironmentConfig

Returns a new instance of EnvironmentConfig.



10
11
12
13
14
15
# File 'lib/kumo_dockercloud/environment_config.rb', line 10

def initialize(options, logger = LOGGER)
  @env_name    = options.fetch(:env_name)
  @config_path = options.fetch(:config_path)
  @log         = logger
  @app_name    = options.fetch(:app_name)
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



8
9
10
# File 'lib/kumo_dockercloud/environment_config.rb', line 8

def app_name
  @app_name
end

#env_nameObject (readonly)

Returns the value of attribute env_name.



8
9
10
# File 'lib/kumo_dockercloud/environment_config.rb', line 8

def env_name
  @env_name
end

Instance Method Details

#deploy_tagObject



25
26
27
# File 'lib/kumo_dockercloud/environment_config.rb', line 25

def deploy_tag
  production? ? 'production' : 'non-production'
end

#development?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/kumo_dockercloud/environment_config.rb', line 33

def development?
  !(%w(production staging).include?(env_name))
end

#error_queue_urlObject



89
90
91
# File 'lib/kumo_dockercloud/environment_config.rb', line 89

def error_queue_url
  @error_queue_url ||= AssetWala::SqsQueue.get_error_queue_url
end

#get_bindingObject



17
18
19
# File 'lib/kumo_dockercloud/environment_config.rb', line 17

def get_binding
  binding
end

#image_nameObject



42
43
44
45
46
47
48
# File 'lib/kumo_dockercloud/environment_config.rb', line 42

def image_name
  if existing_image_name?
    existing_image_name
  else
    "redbubble/#{app_name}:master"
  end
end

#image_tagObject



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

def image_tag
  image_name.split(':').last
end

#plain_text_secretsObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kumo_dockercloud/environment_config.rb', line 67

def plain_text_secrets
  @plain_text_secrets ||= Hash[
    encrypted_secrets.map do |name, cipher_text|
      @log.info "Decrypting '#{name}'"
      if cipher_text.start_with? '[ENC,'
        begin
          [name, "#{kms.decrypt cipher_text[5, cipher_text.size]}"]
        rescue
          @log.error "Error decrypting secret '#{name}' from '#{encrypted_secrets_filename}'"
          raise
        end
      else
        [name, cipher_text]
      end
    end
  ]
end

#production?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/kumo_dockercloud/environment_config.rb', line 29

def production?
  env_name == 'production'
end

#rails_env(name) ⇒ Object



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

def rails_env(name)
  if %w(development test cucumber demo staging production).include?(name)
    name
  else
    'demo'
  end
end

#ruby_envObject



37
38
39
40
# File 'lib/kumo_dockercloud/environment_config.rb', line 37

def ruby_env
  return 'development' if development?
  env_name
end

#stack_nameObject



21
22
23
# File 'lib/kumo_dockercloud/environment_config.rb', line 21

def stack_name
  "#{app_name}-#{env_name}"
end

#tagged_app_image(service_name) ⇒ Object



50
51
52
53
# File 'lib/kumo_dockercloud/environment_config.rb', line 50

def tagged_app_image(service_name)
  service = docker_cloud_api.service_by_stack_and_service_name(stack_name, service_name)
  service ? service.image_name : "redbubble/#{app_name}:master"
end

#tagsObject



85
86
87
# File 'lib/kumo_dockercloud/environment_config.rb', line 85

def tags
  [deploy_tag]
end