class AmoebaDeployTools::Command

Public Class Methods

new(args=[], options={}, config={}) click to toggle source

Note that all subcommands will inherit this class. This means any setup done in here will be duplicated if it runs at initialization (since the main command and subcommand are both evaluated at runtime). Thus, it’s important not to put anything in the constructor. If you wish to setup any global state, do so in the Amoeba class initializer.

Calls superclass method
# File lib/amoeba_deploy_tools/command.rb, line 17
def initialize(args=[], options={}, config={})
  super
end

Public Instance Methods

config() click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 22
def config
  return @amoebaConfig if @amoebaConfig

  @amoebaConfig = Config.load('.amoeba.yml')
end
data_bag(name) click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 76
def data_bag(name)
  DataBag.new(name, kitchen_path)
end
deployment() click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 80
def deployment
  @deployment = Hashie::Mash.new
  @deployment.deep_merge!(node.deployment) if node.deployment

  provider = data_bag(:providers)[node.deployment.provider] if node.deployment_.provider
  @deployment.deep_merge!(provider) if provider

  # Remove ident if we have a remote node, as host keys should be managed by us
  @deployment.delete('ident') if remote_node.deployment

  @deployment.deep_merge!(remote_node.deployment) if remote_node.deployment
  @deployment.deep_merge!(node.deployment)

  return @deployment
end
inside_kitchen(&block) click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 43
def inside_kitchen(&block)
  if defined?(Bundler)
    Bundler.with_clean_env do
      Dir.chdir(kitchen_path) { block.call }
    end
  else
    Dir.chdir(kitchen_path) { block.call }
  end
end
kitchen_path() click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 28
def kitchen_path
  return @kitchen if @kitchen

  if config.kitchen_.path
    @kitchen = config.kitchen.path
  else
    @kitchen = '.'
    logger.warn 'Using local dir as kitchen path, no `.amoeba.yml` config found. Consider running `amoeba init`'
  end

  say_fatal "ERROR: Could not find amoeba kitchen: #{@kitchen}" unless Dir.exists? @kitchen

  @kitchen
end
logger() click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 96
def logger
  Logger.instance
end
node() click to toggle source

The node must be specified unless you set a default one. You can specify it with the ‘–node [name]` option, or by setting `[:node]` in your `.amoeba.yml“

# File lib/amoeba_deploy_tools/command.rb, line 55
def node
  return @node if @node

  node_name = options[:node] || config.node_.default_
  say_fatal 'ERROR: must specify --node or have a default node in your config file' unless node_name

  inside_kitchen do
    node_filename = File.expand_path(File.join('nodes', "#{node_name}.json"))
    if node_name.nil? || !File.exists?(node_filename)
      say_fatal "ERROR: Could not find node JSON file: #{node_filename}"
    end

    @node = Config.load(node_filename, format: :json)
    @node.tap {|n| n.filename = node_filename } if @node
  end
end
remote_node() click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 72
def remote_node
  data_bag(:nodes)[node.name]
end
validate_chef_id!(name) click to toggle source
# File lib/amoeba_deploy_tools/command.rb, line 100
def validate_chef_id!(name)
  say_fatal "You must specify a key name for your data bag id." unless name
  unless name =~ /^[a-zA-Z0-9\_\-]+$/
    say_fatal "Your data bag name must only contain alphanums, dashes, and underscores. `#{name}` is invalid!"
  end
  return true
end