Module: Armada::DeployDSL

Defined in:
lib/armada/deploy_dsl.rb

Defined Under Namespace

Classes: CurrentEnvironmentNotSetError, Store

Instance Method Summary collapse

Instance Method Details

#any?(key) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/armada/deploy_dsl.rb', line 38

def any?(key)
  value = fetch(key)
  if value && value.respond_to?(:any?)
    value.any?
  else
    !fetch(key).nil?
  end
end

#clear_envObject



66
67
68
# File 'lib/armada/deploy_dsl.rb', line 66

def clear_env
  env.clear
end

#container_config(cfg) ⇒ Object



145
146
147
# File 'lib/armada/deploy_dsl.rb', line 145

def container_config(cfg)
  set(:container_config, cfg)
end

#container_name(name) ⇒ Object



70
71
72
# File 'lib/armada/deploy_dsl.rb', line 70

def container_name(name)
  set(:container_name, name)
end

#current_environmentObject



61
62
63
64
# File 'lib/armada/deploy_dsl.rb', line 61

def current_environment
  raise CurrentEnvironmentNotSetError.new('Must set current environment') unless env[:current_environment]
  env[:current_environment]
end

#delete(key) ⇒ Object



51
52
53
# File 'lib/armada/deploy_dsl.rb', line 51

def delete(key)
  env[current_environment].delete(key)
end

#envObject



30
31
32
# File 'lib/armada/deploy_dsl.rb', line 30

def env
  Store.instance
end

#env_vars(new_vars) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/armada/deploy_dsl.rb', line 74

def env_vars(new_vars)
  current = fetch(:env_vars, {})
  new_vars.each_pair do |new_key, new_value|
    current[new_key.to_s] = new_value
  end
  set(:env_vars, current)
end

#fetch(key, default = nil, &block) ⇒ Object



34
35
36
# File 'lib/armada/deploy_dsl.rb', line 34

def fetch(key, default=nil, &block)
  env[current_environment][key] || default
end

#host(hostname) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/armada/deploy_dsl.rb', line 82

def host(hostname)
  current = fetch(:hosts, [])

  if hostname.is_a? Hash
    if not hostname.has_key? :docker_host or not hostname.has_key? :health_check_host
      raise ArgumentError.new("Host must contain :docker_host and :health_check_host if supplied as a hash")
    end
  elsif not hostname.is_a? String
      raise ArgumentError.new("Host must be a String or a Hash containing the :docker_host and :health_check_host keys")
  end

  current << hostname
  set(:hosts, current)
end

#host_config(cfg) ⇒ Object



154
155
156
# File 'lib/armada/deploy_dsl.rb', line 154

def host_config(cfg)
  set(:host_config, cfg)
end

#host_port(port, options) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/armada/deploy_dsl.rb', line 108

def host_port(port, options)
  validate_options_keys(options, [ :host_ip, :container_port, :type ])
  require_options_keys(options,  [ :container_port ])

  add_to_bindings(
    options[:host_ip] || '0.0.0.0',
    options[:container_port],
    port,
    options[:type] || 'tcp'
  )
end

#host_volume(volume, options) ⇒ Object



134
135
136
137
138
139
140
141
142
143
# File 'lib/armada/deploy_dsl.rb', line 134

def host_volume(volume, options)
  validate_options_keys(options, [ :container_volume ])
  require_options_keys(options,  [ :container_volume ])

  binds            = fetch(:binds, [])
  container_volume = options[:container_volume]

  binds << "#{volume}:#{container_volume}"
  set(:binds, binds)
end

#hostname(hostname) ⇒ Object



97
98
99
# File 'lib/armada/deploy_dsl.rb', line 97

def hostname(hostname)
  set(:hostname, hostname)
end

#localhostObject



101
102
103
104
105
106
# File 'lib/armada/deploy_dsl.rb', line 101

def localhost
  # DOCKER_HOST is like 'tcp://127.0.0.1:4243'
  docker_host_uri = URI.parse(ENV['DOCKER_HOST'] || "tcp://127.0.0.1")
  host_and_port = [docker_host_uri.host, docker_host_uri.port].compact.join(':')
  host(host_and_port)
end

#privilegedObject



158
159
160
# File 'lib/armada/deploy_dsl.rb', line 158

def privileged
  set(:privileged, true)
end

#public_port_for(port_bindings) ⇒ Object



128
129
130
131
132
# File 'lib/armada/deploy_dsl.rb', line 128

def public_port_for(port_bindings)
  # {'80/tcp'=>[{'HostIp'=>'0.0.0.0', 'HostPort'=>'80'}]}
  first_port_binding = port_bindings.values.first
  first_port_binding.first['HostPort']
end

#restart_policy(opts) ⇒ Object



120
121
122
# File 'lib/armada/deploy_dsl.rb', line 120

def restart_policy(opts)
  set(:restart_policy, opts)
end

#secret_value(key) ⇒ Object



124
125
126
# File 'lib/armada/deploy_dsl.rb', line 124

def secret_value(key)
  `conjur variable value #{key}`
end

#set(key, value) ⇒ Object



47
48
49
# File 'lib/armada/deploy_dsl.rb', line 47

def set(key, value)
  env[current_environment][key] = value
end

#set_current_environment(environment) ⇒ Object



55
56
57
58
59
# File 'lib/armada/deploy_dsl.rb', line 55

def set_current_environment(environment)
  env[:current_environment] = environment
  env[environment] ||= {}
  env_vars ENV: environment.to_s.downcase
end

#start_config(cfg) ⇒ Object



149
150
151
152
# File 'lib/armada/deploy_dsl.rb', line 149

def start_config(cfg)
  Armada.ui.warn "This option will be deprecated soon. Use host_config instead."
  set(:host_config, cfg)
end