Class: Commands::ChefBake

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/chef_bake.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject

holds the options that were passed you can set any initial defaults here



6
7
8
9
# File 'lib/commands/chef_bake.rb', line 6

def options
  @options ||= {
  }
end

#register(opts, global_options) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/commands/chef_bake.rb', line 18

def register(opts, global_options)
  opts.banner = "Usage: chef_bake [options]"
  opts.description = "Apply the chef scripts"

  opts.on('-g', "--group name", "Required - Name of this deploy group.") do |v|
    options[:group] = v
  end

  opts.on('-f', "--force", "Force a deploy even if the current status says we are deploying.  You should only do this if you are certain the previous deploy is stuck.") do |v|
    options[:force] = v
  end
end

#required_optionsObject

required options



12
13
14
15
16
# File 'lib/commands/chef_bake.rb', line 12

def required_options
  @required_options ||= Set.new [
      :group,
  ]
end

#run(global_options, amazon) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/commands/chef_bake.rb', line 32

def run(global_options, amazon)
  ec2 = amazon.ec2
  utils = ZZSharedLib::Utils.new(amazon)

  group_name = options[:group]

  # first see if already exists
  deploy_group = amazon.find_deploy_group(group_name)

  recipes_deploy_tag = deploy_group.recipes_deploy_tag

  instances = amazon.find_and_sort_named_instances(group_name)

  # see if already deploying
  if !options[:force]
    # raises an exception if not all in the none state
    utils.check_deploy_state(instances, [:deploy_chef, :deploy_app])
  end

  # verify that the chef deploy tag exists
  cmd = "git ls-remote --tags [email protected]:zangzing/zz-chef-repo.git refs/tags/#{recipes_deploy_tag}^{} refs/tags/#{recipes_deploy_tag} | egrep refs/tags/#{recipes_deploy_tag}"
  if ZZSharedLib::CL.do_cmd_result(cmd) != 0
    raise "Could not find the remote tag: #{recipes_deploy_tag} in the remote zz-chef-repo repository.  Make sure you check in and tag your code, and run chef_upload."
  end

  # tag is good, go ahead and deploy to all the machines in the group
  BuildDeployConfig.do_config_deploy(utils, amazon, instances, group_name, deploy_group, options[:result_path])
end