module Armada::DeployDSL

Public Instance Methods

any?(key) click to toggle source
# 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_env() click to toggle source
# File lib/armada/deploy_dsl.rb, line 66
def clear_env
  env.clear
end
container_config(cfg) click to toggle source
# File lib/armada/deploy_dsl.rb, line 145
def container_config(cfg)
  set(:container_config, cfg)
end
container_name(name) click to toggle source
# File lib/armada/deploy_dsl.rb, line 70
def container_name(name)
  set(:container_name, name)
end
current_environment() click to toggle source
# 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) click to toggle source
# File lib/armada/deploy_dsl.rb, line 51
def delete(key)
  env[current_environment].delete(key)
end
env() click to toggle source
# File lib/armada/deploy_dsl.rb, line 30
def env
  Store.instance
end
env_vars(new_vars) click to toggle source
# 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) click to toggle source
# File lib/armada/deploy_dsl.rb, line 34
def fetch(key, default=nil, &block)
  env[current_environment][key] || default
end
host(hostname) click to toggle source
# 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) click to toggle source
# File lib/armada/deploy_dsl.rb, line 154
def host_config(cfg)
  set(:host_config, cfg)
end
host_port(port, options) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/armada/deploy_dsl.rb, line 97
def hostname(hostname)
  set(:hostname, hostname)
end
localhost() click to toggle source
# 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
privileged() click to toggle source
# File lib/armada/deploy_dsl.rb, line 158
def privileged
  set(:privileged, true)
end
public_port_for(port_bindings) click to toggle source
# 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) click to toggle source
# File lib/armada/deploy_dsl.rb, line 120
def restart_policy(opts)
  set(:restart_policy, opts)
end
secret_value(key) click to toggle source
# File lib/armada/deploy_dsl.rb, line 124
def secret_value(key)
  `conjur variable value #{key}`
end
set(key, value) click to toggle source
# File lib/armada/deploy_dsl.rb, line 47
def set(key, value)
  env[current_environment][key] = value
end
set_current_environment(environment) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

add_to_bindings(host_ip, container_port, port, type='tcp') click to toggle source
# File lib/armada/deploy_dsl.rb, line 164
def add_to_bindings(host_ip, container_port, port, type='tcp')
  ports = fetch(:port_bindings, {})
  ports["#{container_port.to_s}/#{type}"] = [{'HostIp' => host_ip, 'HostPort' => port.to_s}]
  set(:port_bindings, ports)
end
require_options_keys(options, required_keys) click to toggle source
# File lib/armada/deploy_dsl.rb, line 176
def require_options_keys(options, required_keys)
  missing = required_keys.reject { |k| options.keys.include?(k) }

  unless missing.empty?
    raise ArgumentError.new("Options must contain #{missing.inspect}")
  end
end
validate_options_keys(options, valid_keys) click to toggle source
# File lib/armada/deploy_dsl.rb, line 170
def validate_options_keys(options, valid_keys)
  unless options.keys.all? { |k| valid_keys.include?(k) }
    raise ArgumentError.new('Options passed with invalid key!')
  end
end