Class: Commands::ChefUpload

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_upload_command(recipes_deploy_tag) ⇒ Object



58
59
60
# File 'lib/commands/chef_upload.rb', line 58

def self.get_upload_command(recipes_deploy_tag)
  "cd #{::ZZDeploy::RECIPES_DIR} && git fetch && git checkout -f #{recipes_deploy_tag} && bundle install --path #{::ZZDeploy::RECIPES_BUNDLE_DIR} --deployment"
end

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_upload.rb', line 6

def options
  @options ||= {
  }
end

#register(opts, global_options) ⇒ Object



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

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

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

  opts.on('-t', "--tag tag", "Required - Git tag to use for pulling chef code.") do |v|
    options[:tag] = v
  end
end

#required_optionsObject

required options



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

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

#run(global_options, amazon) ⇒ Object



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

def run(global_options, amazon)
  ec2 = amazon.ec2

  group_name = options[:group]
  recipes_deploy_tag = options[:tag]

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

  # verify that the tag given is on the remote repo
  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 tag specified in the remote zz-chef-repo repository.  Make sure you check in and tag your code."
  end

  # tag is good, go ahead and upload to simple db
  deploy_group.recipes_deploy_tag = recipes_deploy_tag
  deploy_group.save
  deploy_group.reload # save corrupts the in memory state so must reload, kinda lame

  remote_cmd = ChefUpload.get_upload_command(recipes_deploy_tag)
  multi = MultiSSH.new(amazon, group_name, deploy_group)
  multi.run(remote_cmd)
end