Class: Itamae::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/itamae/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend, options) ⇒ Runner

Returns a new instance of Runner.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/itamae/runner.rb', line 30

def initialize(backend, options)
  @backend = backend
  @options = options

  prepare_handler

  @node = create_node
  @tmpdir = options[:tmp_dir] || '/tmp/itamae_tmp'
  @children = RecipeChildren.new
  @diff = false

  @backend.run_command(["mkdir", "-p", @tmpdir])
  @backend.run_command(["chmod", "777", @tmpdir])
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



23
24
25
# File 'lib/itamae/runner.rb', line 23

def backend
  @backend
end

#childrenObject (readonly)

Returns the value of attribute children.



27
28
29
# File 'lib/itamae/runner.rb', line 27

def children
  @children
end

#handlerObject (readonly)

Returns the value of attribute handler.



28
29
30
# File 'lib/itamae/runner.rb', line 28

def handler
  @handler
end

#nodeObject (readonly)

Returns the value of attribute node.



25
26
27
# File 'lib/itamae/runner.rb', line 25

def node
  @node
end

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/itamae/runner.rb', line 24

def options
  @options
end

#tmpdirObject (readonly)

Returns the value of attribute tmpdir.



26
27
28
# File 'lib/itamae/runner.rb', line 26

def tmpdir
  @tmpdir
end

Class Method Details

.run(recipe_files, backend_type, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/itamae/runner.rb', line 7

def run(recipe_files, backend_type, options)
  unless recipe_files.is_a? Array
    raise ArgumentError, 'recipe_files must be an Array'
  end

  Itamae.logger.info "Starting Itamae... #{options[:dry_run] ? '(dry-run)' : ''}"

  backend = Backend.create(backend_type, options)
  runner = self.new(backend, options)
  runner.load_recipes(recipe_files)
  runner.run

  runner
end

Instance Method Details

#diff?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/itamae/runner.rb', line 89

def diff?
  @diff
end

#diff_found!Object



93
94
95
# File 'lib/itamae/runner.rb', line 93

def diff_found!
  @diff = true
end

#dry_run?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/itamae/runner.rb', line 72

def dry_run?
  @options[:dry_run]
end

#load_recipes(paths) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/itamae/runner.rb', line 45

def load_recipes(paths)
  paths.each do |path|
    expanded_path = File.expand_path(path)
    if path.include?('::')
      gem_path = Recipe.find_recipe_in_gem(path)
      expanded_path = gem_path if gem_path
    end

    recipe = Recipe.new(self, expanded_path)
    children << recipe
    recipe.load
  end
end

#runObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/itamae/runner.rb', line 59

def run
  if recipe_graph_file = options[:recipe_graph]
    save_dependency_graph(recipe_graph_file)
  end

  children.run
  @backend.finalize

  if profile = options[:profile]
    save_profile(profile)
  end
end

#save_dependency_graph(path) ⇒ Object



76
77
78
79
80
81
# File 'lib/itamae/runner.rb', line 76

def save_dependency_graph(path)
  Itamae.logger.info "Writing recipe dependency graph to #{path}..."
  open(path, 'w') do |f|
    f.write(children.dependency_in_dot)
  end
end

#save_profile(path) ⇒ Object



83
84
85
86
87
# File 'lib/itamae/runner.rb', line 83

def save_profile(path)
  open(path, 'w', 0600) do |f|
    f.write(@backend.executed_commands.to_json)
  end
end