Module: Ey::Core::Cli::Helpers::Chef

Included in:
Recipes::Apply, Recipes::Upload
Defined in:
lib/ey-core/cli/helpers/chef.rb

Instance Method Summary collapse

Instance Method Details

#run_chef(type, environment, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ey-core/cli/helpers/chef.rb', line 8

def run_chef(type, environment, options = {})
  no_wait = options.delete(:no_wait)
  options[:streaming] = true unless no_wait
  request = environment.apply(type, options)
  puts "Started #{type} chef run".green
  if no_wait
    return
  end
  streamable_instance_update = nil
  if request.read_channel
    request.subscribe do |m|
      print m["message"] if m.is_a?(Hash)
    end
    puts "" # fix console output from stream
  else
    request.wait_for { |r| r.ready? }
  end
  if request.successful
    puts "#{type.capitalize} chef run completed".green
  else
    puts "#{type.capitalize} chef run failed".red
    ap request
    if server = environment.servers.first
      puts "For logs try `ey logs --server #{server.provisioned_id}` --environment #{environment.name}"
    end
  end
end

#upload_recipes(environment, path = "cookbooks/") ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ey-core/cli/helpers/chef.rb', line 36

def upload_recipes(environment, path="cookbooks/")
  recipes_path = Pathname.new(path)

  if recipes_path.exist? && recipes_path.to_s.match(/\.(tgz|tar\.gz)/)
    environment.upload_recipes(recipes_path)
  elsif recipes_path.exist?
    environment.upload_recipes(archive_directory(path))
  else
    raise RecipesNotFound, "Recipes not found, expected to find chef recipes in: #{File.expand_path(recipes_path)}, use --file to specify a different path"
  end
end