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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/itamae/runner.rb', line 27

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

  prepare_handler

  @node = create_node
  @tmpdir = "/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.



20
21
22
# File 'lib/itamae/runner.rb', line 20

def backend
  @backend
end

#childrenObject (readonly)

Returns the value of attribute children.



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

def children
  @children
end

#handlerObject (readonly)

Returns the value of attribute handler.



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

def handler
  @handler
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/itamae/runner.rb', line 21

def options
  @options
end

#tmpdirObject (readonly)

Returns the value of attribute tmpdir.



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

def tmpdir
  @tmpdir
end

Class Method Details

.run(recipe_files, backend_type, options) ⇒ Object



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

def run(recipe_files, backend_type, options)
  Itamae.logger.info "Starting Itamae..."

  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)


86
87
88
# File 'lib/itamae/runner.rb', line 86

def diff?
  @diff
end

#diff_found!Object



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

def diff_found!
  @diff = true
end

#dry_run?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/itamae/runner.rb', line 69

def dry_run?
  @options[:dry_run]
end

#load_recipes(paths) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/itamae/runner.rb', line 42

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



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/itamae/runner.rb', line 56

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



73
74
75
76
77
78
# File 'lib/itamae/runner.rb', line 73

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



80
81
82
83
84
# File 'lib/itamae/runner.rb', line 80

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