Module: Elzar::Assistant

Defined in:
lib/elzar/assistant.rb

Defined Under Namespace

Classes: InvalidDnaError

Constant Summary collapse

ELZAR_DIR =
'elzar'
CHEF_SOLO_DIR =
'/tmp/chef-solo'

Class Method Summary collapse

Class Method Details

.create_user_provision_dir(dest, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/elzar/assistant.rb', line 29

def create_user_provision_dir(dest, options={})
  dna = options[:dna] || 'rails' # TODO be better than this

  FileUtils.mkdir_p dest
  cp "#{Elzar.templates_dir}/gitignore", "#{dest}/.gitignore"
  cp "#{Elzar.templates_dir}/.rvmrc", dest
  cp "#{Elzar.templates_dir}/aws_config.yml", dest
  cp "#{Elzar.templates_dir}/aws_config.private.yml", dest
  cp "#{Elzar.templates_dir}/dna/#{dna}.json", "#{dest}/dna.json"
  cp "#{Elzar.templates_dir}/Gemfile", dest
  cp "#{Elzar.templates_dir}/README.md", dest
  cp "#{Elzar.templates_dir}/upgrade-chef.sh", dest
  cp_r "#{Elzar.templates_dir}/data_bags", dest
  cp_r "#{Elzar.templates_dir}/script", dest
  cp_r "#{Elzar.templates_dir}/.chef", dest
end

.generate_files(dest, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/elzar/assistant.rb', line 16

def generate_files(dest, options={})
  vm_host_name = options[:app_name] ?
    "#{options[:app_name].gsub('_','-')}.local" : "elzar.thinkrelevance.com"
  Template.generate 'Vagrantfile', dest, :vm_host_name => vm_host_name,
    :cookbooks_path => Elzar::COOKBOOK_DIRS, :local => options[:local]
  if options[:local]
    generate_local_files dest
  else
    require 'multi_json'
    generate_user_files dest, options
  end
end

.merge_and_create_temp_directory(user_dir) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/elzar/assistant.rb', line 46

def merge_and_create_temp_directory(user_dir)
  validate_dna! "#{user_dir}/dna.json"

  dest = Dir.mktmpdir
  elzar_dir = "#{dest}/#{ELZAR_DIR}"
  FileUtils.mkdir_p elzar_dir

  generate_solo_rb dest, Elzar::COOKBOOK_DIRS.map {|dir| "#{CHEF_SOLO_DIR}/#{ELZAR_DIR}/#{dir}" }
  cp_r Elzar::ROLES_DIR, dest
  cp_r "#{Elzar::CHEF_DIR}/cookbooks", elzar_dir
  cp_r "#{Elzar::CHEF_DIR}/site-cookbooks", elzar_dir
  # merges user provision with elzar's provision
  cp_r "#{user_dir}/.", dest
  dest
end

.validate_dna!(dna_file_path) ⇒ Object



62
63
64
65
66
67
# File 'lib/elzar/assistant.rb', line 62

def validate_dna!(dna_file_path)
  lines = File.readlines(dna_file_path)
  lines.each_with_index do |line, line_number|
    raise InvalidDnaError.new(line, line_number + 1) if line.match(/TODO/)
  end
end