terraspace 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/aws/bin/build.sh +2 -0
  3. data/.cody/azurerm/bin/build.sh +2 -0
  4. data/.cody/google/bin/build.sh +2 -0
  5. data/CHANGELOG.md +39 -0
  6. data/README.md +1 -1
  7. data/lib/templates/base/project/README.md +1 -1
  8. data/lib/terraspace.rb +1 -0
  9. data/lib/terraspace/all/preview.rb +1 -1
  10. data/lib/terraspace/all/runner.rb +1 -0
  11. data/lib/terraspace/all/summary.rb +29 -2
  12. data/lib/terraspace/app.rb +9 -5
  13. data/lib/terraspace/builder.rb +10 -6
  14. data/lib/terraspace/cli.rb +33 -39
  15. data/lib/terraspace/cli/all.rb +15 -9
  16. data/lib/terraspace/cli/bundle.rb +2 -1
  17. data/lib/terraspace/cli/clean.rb +18 -6
  18. data/lib/terraspace/cli/clean/all.rb +18 -0
  19. data/lib/terraspace/cli/clean/base.rb +15 -0
  20. data/lib/terraspace/cli/clean/cache.rb +25 -0
  21. data/lib/terraspace/cli/{logs/tasks.rb → clean/logs.rb} +16 -5
  22. data/lib/terraspace/cli/cloud.rb +3 -9
  23. data/lib/terraspace/cli/cloud/runs.rb +0 -2
  24. data/lib/terraspace/cli/help/all/down.md +32 -0
  25. data/lib/terraspace/cli/help/all/graph.md +21 -0
  26. data/lib/terraspace/cli/help/all/init.md +33 -0
  27. data/lib/terraspace/cli/help/all/output.md +22 -0
  28. data/lib/terraspace/cli/help/all/plan.md +25 -0
  29. data/lib/terraspace/cli/help/all/providers.md +21 -0
  30. data/lib/terraspace/cli/help/all/refresh.md +17 -0
  31. data/lib/terraspace/cli/help/all/show.md +21 -0
  32. data/lib/terraspace/cli/help/all/up.md +27 -0
  33. data/lib/terraspace/cli/help/all/validate.md +21 -0
  34. data/lib/terraspace/cli/help/build.md +6 -0
  35. data/lib/terraspace/cli/help/bundle.md +9 -5
  36. data/lib/terraspace/cli/help/check_setup.md +9 -0
  37. data/lib/terraspace/cli/help/clean/all.md +10 -0
  38. data/lib/terraspace/cli/help/clean/cache.md +12 -0
  39. data/lib/terraspace/cli/help/clean/logs.md +17 -0
  40. data/lib/terraspace/cli/help/cloud/destroy.md +16 -0
  41. data/lib/terraspace/cli/help/cloud/list.md +7 -0
  42. data/lib/terraspace/cli/help/cloud/runs/list.md +3 -3
  43. data/lib/terraspace/cli/help/cloud/runs/prune.md +1 -1
  44. data/lib/terraspace/cli/help/cloud/sync.md +26 -2
  45. data/lib/terraspace/cli/help/console.md +8 -0
  46. data/lib/terraspace/cli/help/down.md +26 -0
  47. data/lib/terraspace/cli/help/info.md +43 -0
  48. data/lib/terraspace/cli/help/init.md +37 -0
  49. data/lib/terraspace/cli/help/list.md +20 -0
  50. data/lib/terraspace/cli/help/logs.md +48 -0
  51. data/lib/terraspace/cli/help/logs/remove.md +5 -0
  52. data/lib/terraspace/cli/help/logs/truncate.md +5 -0
  53. data/lib/terraspace/cli/help/new/bootstrap_test.md +8 -0
  54. data/lib/terraspace/cli/help/new/example.md +8 -0
  55. data/lib/terraspace/cli/help/new/git_hook.md +6 -0
  56. data/lib/terraspace/cli/help/new/module.md +9 -0
  57. data/lib/terraspace/cli/help/new/module_test.md +12 -0
  58. data/lib/terraspace/cli/help/new/plugin.md +49 -0
  59. data/lib/terraspace/cli/help/new/project.md +40 -0
  60. data/lib/terraspace/cli/help/new/project_test.md +8 -0
  61. data/lib/terraspace/cli/help/new/shim.md +21 -0
  62. data/lib/terraspace/cli/help/new/stack.md +9 -0
  63. data/lib/terraspace/cli/help/output.md +6 -0
  64. data/lib/terraspace/cli/help/plan.md +29 -0
  65. data/lib/terraspace/cli/help/providers.md +18 -0
  66. data/lib/terraspace/cli/help/refresh.md +11 -0
  67. data/lib/terraspace/cli/help/seed.md +7 -0
  68. data/lib/terraspace/cli/help/show.md +36 -0
  69. data/lib/terraspace/cli/help/summary.md +11 -0
  70. data/lib/terraspace/cli/help/test.md +35 -0
  71. data/lib/terraspace/cli/help/up.md +30 -0
  72. data/lib/terraspace/cli/help/validate.md +9 -0
  73. data/lib/terraspace/cli/info.rb +4 -16
  74. data/lib/terraspace/cli/init.rb +3 -7
  75. data/lib/terraspace/cli/list.rb +2 -1
  76. data/lib/terraspace/cli/logs.rb +106 -9
  77. data/lib/terraspace/cli/{log → logs}/concern.rb +1 -1
  78. data/lib/terraspace/cli/new.rb +18 -18
  79. data/lib/terraspace/cli/new/git_hook.rb +4 -1
  80. data/lib/terraspace/cli/new/helper.rb +9 -2
  81. data/lib/terraspace/cli/new/project.rb +1 -1
  82. data/lib/terraspace/cli/summary.rb +2 -2
  83. data/lib/terraspace/command.rb +1 -1
  84. data/lib/terraspace/compiler/dependencies/helpers.rb +34 -0
  85. data/lib/terraspace/compiler/dsl/syntax/helpers/common.rb +0 -26
  86. data/lib/terraspace/compiler/dsl/syntax/tfvar.rb +1 -0
  87. data/lib/terraspace/compiler/erb/context.rb +1 -1
  88. data/lib/terraspace/compiler/erb/helpers.rb +6 -0
  89. data/lib/terraspace/dependency/graph.rb +2 -1
  90. data/lib/terraspace/dependency/helper/base.rb +7 -0
  91. data/lib/terraspace/dependency/helper/depends_on.rb +12 -0
  92. data/lib/terraspace/dependency/helper/output.rb +11 -0
  93. data/lib/terraspace/hooks/builder.rb +52 -0
  94. data/lib/terraspace/hooks/concern.rb +9 -0
  95. data/lib/terraspace/{terraform/hooks → hooks}/dsl.rb +3 -2
  96. data/lib/terraspace/hooks/runner.rb +23 -0
  97. data/lib/terraspace/mod.rb +11 -2
  98. data/lib/terraspace/plugin/summary/interface.rb +4 -2
  99. data/lib/terraspace/shell.rb +29 -14
  100. data/lib/terraspace/terraform/args/custom.rb +1 -1
  101. data/lib/terraspace/terraform/cloud/runs/lister.rb +0 -2
  102. data/lib/terraspace/terraform/cloud/syncer.rb +2 -2
  103. data/lib/terraspace/terraform/cloud/workspace.rb +0 -9
  104. data/lib/terraspace/terraform/remote_state/fetcher.rb +13 -4
  105. data/lib/terraspace/terraform/remote_state/marker/output.rb +3 -1
  106. data/lib/terraspace/terraform/remote_state/output_proxy.rb +18 -14
  107. data/lib/terraspace/terraform/remote_state/unresolved.rb +40 -0
  108. data/lib/terraspace/terraform/runner.rb +2 -7
  109. data/lib/terraspace/version.rb +1 -1
  110. data/spec/fixtures/dependencies/app/stacks/a1/tfvars/dev.tfvars +1 -0
  111. data/spec/fixtures/fetcher/c1.json +4 -0
  112. data/spec/terraspace/all/summary_spec.rb +1 -1
  113. data/spec/terraspace/compiler/erb/render_spec.rb +15 -0
  114. data/spec/terraspace/dependency/helper/depends_on_spec.rb +27 -0
  115. data/spec/terraspace/dependency/helper/output_spec.rb +29 -0
  116. data/spec/terraspace/{terraform/hooks → hooks}/builder_spec.rb +4 -5
  117. data/spec/terraspace/terraform/remote_state/fetcher_spec.rb +108 -27
  118. data/spec/terraspace/terraform/remote_state/marker/output_spec.rb +36 -0
  119. data/spec/terraspace/terraform/remote_state/output_proxy_spec.rb +69 -0
  120. data/terraspace.gemspec +1 -1
  121. metadata +78 -13
  122. data/lib/terraspace/cli/help/log.md +0 -46
  123. data/lib/terraspace/cli/help/update.md +0 -5
  124. data/lib/terraspace/cli/log.rb +0 -112
  125. data/lib/terraspace/terraform/hooks/builder.rb +0 -40
@@ -1,15 +1,112 @@
1
+ require "eventmachine"
2
+ require "eventmachine-tail"
3
+
1
4
  class Terraspace::CLI
2
- class Logs < Terraspace::Command
3
- desc "truncate", "Truncates logs. IE: Removes contents and zero bytes the files"
4
- long_desc Help.text("logs/truncate")
5
- def truncate
6
- Tasks.new(options).truncate
5
+ class Logs < Base
6
+ include Concern
7
+
8
+ def initialize(options={})
9
+ super
10
+ @action, @stack = options[:action], options[:stack]
11
+ @action ||= '**'
12
+ @stack ||= '*'
13
+ end
14
+
15
+ def run
16
+ check_logs!
17
+ if @options[:follow]
18
+ follow_logs
19
+ else
20
+ all_log_paths.each { |path| show_log(path) }
21
+ end
22
+ end
23
+
24
+ def follow_logs
25
+ glob_path = "#{Terraspace.log_root}/#{@action}/#{@stack}.log"
26
+ Dir.glob(glob_path).each do |path|
27
+ puts "Following #{pretty(path)}".color(:purple)
28
+ end
29
+ EventMachine.run do
30
+ interval = Integer(ENV['TS_LOG_GLOB_INTERNAL'] || 1)
31
+ EventMachine::FileGlobWatchTail.new(glob_path, nil, interval) do |filetail, line|
32
+ puts line # always show timestamp in follow mode
33
+ end
34
+ end
35
+ end
36
+
37
+ def show_log(path)
38
+ report_log(path)
39
+ lines = readlines(path)
40
+ lines = apply_limit(lines)
41
+ lines.each do |line|
42
+ puts format(line)
43
+ end
44
+ end
45
+
46
+ def report_log(path)
47
+ pretty_path = pretty(path)
48
+ if File.exist?(path)
49
+ puts "Showing: #{pretty_path}".color(:purple)
50
+ end
51
+ end
52
+
53
+ def format(line)
54
+ if timestamps
55
+ line
56
+ else
57
+ line.sub(/.*\]: /,'')
58
+ end
59
+ end
60
+
61
+ def all_log_paths
62
+ Dir.glob("#{Terraspace.log_root}/#{@action}/#{@stack}.log")
7
63
  end
8
64
 
9
- desc "remove", "Removes logs"
10
- long_desc Help.text("logs/remove")
11
- def remove
12
- Tasks.new(options).remove
65
+ def check_logs!
66
+ return unless all_log_paths.empty?
67
+ puts "WARN: No logs found".color(:yellow)
68
+ end
69
+
70
+ # Only need to check if both action and stack are provided. Otherwise the Dir.globs are used to discover the files
71
+ def check_log!
72
+ return unless single_log?
73
+ path = "#{Terraspace.log_root}/#{@action}/#{@stack}.log"
74
+ return if File.exist?(path)
75
+ puts "ERROR: Log file was not found: #{pretty(path)}".color(:red)
76
+ exit 1
77
+ end
78
+
79
+ def single_log?
80
+ @action != '**' && @stack != '*'
81
+ end
82
+
83
+ def apply_limit(lines)
84
+ return lines if all
85
+ left = limit * -1
86
+ lines[left..-1] || []
87
+ end
88
+
89
+ def all
90
+ if single_log?
91
+ @options[:all].nil? ? true : @options[:all]
92
+ else # multiple
93
+ @options[:all].nil? ? false : @options[:all]
94
+ end
95
+ end
96
+
97
+ def limit
98
+ @options[:limit].nil? ? 10 : @options[:limit]
99
+ end
100
+
101
+ def timestamps
102
+ if single_log?
103
+ @options[:timestamps].nil? ? false : @options[:timestamps]
104
+ else
105
+ @options[:timestamps].nil? ? true : @options[:timestamps]
106
+ end
107
+ end
108
+ def pretty(path)
109
+ Terraspace::Util.pretty_path(path)
13
110
  end
14
111
  end
15
112
  end
@@ -1,4 +1,4 @@
1
- class Terraspace::CLI::Log
1
+ class Terraspace::CLI::Logs
2
2
  module Concern
3
3
  # Filters for lines that belong to the last ran process pid
4
4
  def readlines(path)
@@ -1,40 +1,40 @@
1
1
  class Terraspace::CLI
2
2
  class New < Terraspace::Command
3
- long_desc Help.text(:git_hook)
3
+ long_desc Help.text("new/git_hook")
4
4
  GitHook.cli_options.each { |args| option(*args) }
5
- register(GitHook, "git_hook", "git_hook", "Generates new git hook")
5
+ register(GitHook, "git_hook", "git_hook", "Generates new git hook.")
6
6
 
7
- long_desc Help.text(:shim)
7
+ long_desc Help.text("new/shim")
8
8
  Shim.cli_options.each { |args| option(*args) }
9
- register(Shim, "shim", "shim", "Generates terraspace shim")
9
+ register(Shim, "shim", "shim", "Generates terraspace shim.")
10
10
 
11
- long_desc Help.text(:module)
11
+ long_desc Help.text("new/module")
12
12
  Module.base_options.each { |args| option(*args) }
13
13
  Module.component_options.each { |args| option(*args) }
14
- register(Module, "module", "module NAME", "Generates new module")
14
+ register(Module, "module", "module NAME", "Generates new module.")
15
15
 
16
- long_desc Help.text(:stack)
16
+ long_desc Help.text("new/stack")
17
17
  Stack.base_options.each { |args| option(*args) }
18
18
  Stack.component_options.each { |args| option(*args) }
19
- register(Stack, "stack", "stack NAME", "Generates new stack")
19
+ register(Stack, "stack", "stack NAME", "Generates new stack.")
20
20
 
21
- long_desc Help.text(:project)
21
+ long_desc Help.text("new/project")
22
22
  Project.base_options.each { |args| option(*args) }
23
23
  Project.project_options.each { |args| option(*args) }
24
- register(Project, "project", "project NAME", "Generates new project")
24
+ register(Project, "project", "project NAME", "Generates new project.")
25
25
 
26
- long_desc Help.text(:project_test)
27
- register(Test::Project, "project_test", "project_test NAME", "Generates new project test")
26
+ long_desc Help.text("new/project_test")
27
+ register(Test::Project, "project_test", "project_test NAME", "Generates new project test.")
28
28
 
29
- long_desc Help.text(:module_test)
30
- register(Test::Module, "module_test", "module_test NAME", "Generates new module test")
29
+ long_desc Help.text("new/module_test")
30
+ register(Test::Module, "module_test", "module_test NAME", "Generates new module test.")
31
31
 
32
- long_desc Help.text(:bootstrap_test)
32
+ long_desc Help.text("new/bootstrap_test")
33
33
  Test::Bootstrap.options.each { |args| option(*args) }
34
- register(Test::Bootstrap, "bootstrap_test", "bootstrap_test", "Generates bootstrap test setup")
34
+ register(Test::Bootstrap, "bootstrap_test", "bootstrap_test", "Generates bootstrap test setup.")
35
35
 
36
- long_desc Help.text(:plugin)
36
+ long_desc Help.text("new/plugin")
37
37
  Plugin.options.each { |args| option(*args) }
38
- register(Plugin, "plugin", "plugin", "Generates plugin")
38
+ register(Plugin, "plugin", "plugin", "Generates plugin.")
39
39
  end
40
40
  end
@@ -15,7 +15,10 @@ class Terraspace::CLI::New
15
15
  end
16
16
 
17
17
  def create
18
- return unless File.exist?(".git")
18
+ unless File.exist?(".git")
19
+ puts "No .git folder found. Not creating git hook."
20
+ return
21
+ end
19
22
  dest = ".git/hooks/#{options[:type]}"
20
23
  template "hook.sh", dest
21
24
  chmod dest, 0755
@@ -6,10 +6,17 @@ class Terraspace::CLI::New
6
6
  def build_gemfile(*list)
7
7
  lines = []
8
8
  list.each do |name|
9
- line = %Q|gem "#{name}"|
10
- lines << line
9
+ lines << gem_line(name)
11
10
  end
12
11
  lines.join("\n")
13
12
  end
13
+
14
+ def gem_line(name)
15
+ if name == "terraspace"
16
+ %Q|gem "#{name}", '~> #{Terraspace::VERSION}'|
17
+ else
18
+ %Q|gem "#{name}"|
19
+ end
20
+ end
14
21
  end
15
22
  end
@@ -54,7 +54,7 @@ class Terraspace::CLI::New
54
54
  end
55
55
 
56
56
  def create_test
57
- return if @options[:test_structure] == false
57
+ return unless @options[:test_structure]
58
58
  Test::Bootstrap.start(["--dir", name])
59
59
  end
60
60
 
@@ -12,7 +12,7 @@ class Terraspace::CLI
12
12
 
13
13
  def run
14
14
  Terraspace.check_project!
15
- build
15
+ build_placeholder
16
16
  puts "Summary of resources based on backend storage statefiles"
17
17
  backend_expr = '.terraspace-cache/**/backend.*'
18
18
  # Currently summary assumes backend are within the same bucket and key prefix
@@ -22,7 +22,7 @@ class Terraspace::CLI
22
22
 
23
23
  # Grab the last module and build that.
24
24
  # Assume the backend key has the same prefix
25
- def build
25
+ def build_placeholder
26
26
  Build::Placeholder.new(@options).build
27
27
  end
28
28
 
@@ -86,7 +86,7 @@ module Terraspace
86
86
 
87
87
  # meant to be overriden
88
88
  def website
89
- ""
89
+ "https://terraspace.cloud"
90
90
  end
91
91
 
92
92
  # https://github.com/erikhuda/thor/issues/244
@@ -0,0 +1,34 @@
1
+ module Terraspace::Compiler::Dependencies
2
+ # This is a separate module specifically because the DSL also has an output method.
3
+ # The module allows us to include dependency related methods only within tfvars context for the DSL.
4
+ #
5
+ # 1. Only include this module to DSL tfvars context.
6
+ # So the output method works in tfvars .rb files works.
7
+ # At the same time, the DSL usage of output also works for normal main.tf files.
8
+ # Passing specs prove this.
9
+ # 2. For ERB, there's currently only one ERB context. So this module is included in all contexts.
10
+ # The builder only processes dependencies from tfvars, so these helpers are only respected there.
11
+ #
12
+ # Where the module is included in the code:
13
+ #
14
+ # 1. lib/terraspace/compiler/dsl/syntax/tfvar.rb
15
+ # 2. lib/terraspace/compiler/erb/helpers.rb
16
+ #
17
+ module Helpers
18
+ def output(identifier, options={})
19
+ Terraspace::Dependency::Helper::Output.new(@mod, identifier, options).result
20
+ end
21
+ alias_method :terraform_output, :output # backwards compatibility
22
+
23
+ def depends_on(*child_names, **options)
24
+ child_names.flatten!
25
+ child_names.map do |child_name|
26
+ each_depends_on(child_name, options)
27
+ end.join("\n")
28
+ end
29
+
30
+ def each_depends_on(child_name, options={})
31
+ Terraspace::Dependency::Helper::DependsOn.new(@mod, child_name, options).result
32
+ end
33
+ end
34
+ end
@@ -1,8 +1,6 @@
1
1
  module Terraspace::Compiler::Dsl::Syntax::Helpers
2
2
  module Common
3
3
  extend Memoist
4
- Fetcher = Terraspace::Terraform::RemoteState::Fetcher
5
- Marker = Terraspace::Terraform::RemoteState::Marker
6
4
  Meta = Terraspace::Compiler::Dsl::Meta
7
5
 
8
6
  def var
@@ -25,29 +23,5 @@ module Terraspace::Compiler::Dsl::Syntax::Helpers
25
23
  command = ["terraspace"] + args
26
24
  command.join(separator)
27
25
  end
28
-
29
- def terraform_output(identifier, options={})
30
- if @mod.resolved # dependencies have been resolved
31
- Fetcher.new(@mod, identifier, options).output
32
- else
33
- Marker::Output.new(@mod, identifier, options).build
34
- end
35
- end
36
-
37
- def depends_on(*child_names, **options)
38
- child_names.flatten!
39
- child_names.map do |child_name|
40
- each_depends_on(child_name, options)
41
- end.join("\n")
42
- end
43
-
44
- def each_depends_on(child_name, options={})
45
- if @mod.resolved # dependencies have been resolved
46
- # Note: A generated line is not really needed. Dependencies are stored in memory. Added to assist users with debugging
47
- "# #{@mod.name} depends on #{child_name}"
48
- else
49
- Marker::Output.new(@mod, child_name, options).build
50
- end
51
- end
52
26
  end
53
27
  end
@@ -1,5 +1,6 @@
1
1
  module Terraspace::Compiler::Dsl::Syntax
2
2
  module Tfvar
3
3
  include_dir("tfvar")
4
+ include Terraspace::Compiler::Dependencies::Helpers
4
5
  end
5
6
  end
@@ -1,6 +1,6 @@
1
1
  module Terraspace::Compiler::Erb
2
2
  class Context
3
- include Terraspace::Compiler::Dsl::Syntax::Mod
3
+ include Helpers
4
4
 
5
5
  attr_reader :mod, :options
6
6
  def initialize(mod)
@@ -0,0 +1,6 @@
1
+ module Terraspace::Compiler::Erb
2
+ module Helpers
3
+ include Terraspace::Compiler::Dsl::Syntax::Mod
4
+ include Terraspace::Compiler::Dependencies::Helpers
5
+ end
6
+ end
@@ -20,8 +20,9 @@ module Terraspace::Dependency
20
20
  @batches
21
21
  end
22
22
 
23
+ # Only check when stacks option is pass. Edge case: There can be app/modules but no app/stacks yet
23
24
  def check_empty_nodes!
24
- return unless @nodes.empty?
25
+ return unless @nodes.empty? && @options[:stacks]
25
26
  logger.error "ERROR: No stacks were found that match: #{@options[:stacks].join(' ')}".color(:red)
26
27
  exit 1
27
28
  end
@@ -0,0 +1,7 @@
1
+ module Terraspace::Dependency::Helper
2
+ class Base
3
+ def initialize(mod, identifier, options)
4
+ @mod, @identifier, @options = mod, identifier, options
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Terraspace::Dependency::Helper
2
+ class DependsOn < Base
3
+ def result
4
+ if @mod.resolved # dependencies have been resolved
5
+ # Note: A generated line is not really needed. Dependencies are stored in memory. Added to assist users with debugging
6
+ "# #{@mod.name} depends on #{@identifier}" # raw String value
7
+ else
8
+ Terraspace::Terraform::RemoteState::Marker::Output.new(@mod, @identifier, @options).build # Returns OutputProxy which defaults to json
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Terraspace::Dependency::Helper
2
+ class Output < Base
3
+ def result
4
+ if @mod.resolved # dependencies have been resolved
5
+ Terraspace::Terraform::RemoteState::Fetcher.new(@mod, @identifier, @options).output # Returns OutputProxy which defaults to json
6
+ else
7
+ Terraspace::Terraform::RemoteState::Marker::Output.new(@mod, @identifier, @options).build # Returns OutputProxy => Unresolved
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ module Terraspace::Hooks
2
+ class Builder
3
+ extend Memoist
4
+ include Dsl
5
+ include DslEvaluator
6
+ include Terraspace::Util
7
+
8
+ # IE: dsl_file: config/hooks/terraform.rb
9
+ attr_accessor :name
10
+ def initialize(mod, dsl_file, name)
11
+ @mod, @dsl_file, @name = mod, dsl_file, name
12
+ @hooks = {before: {}, after: {}}
13
+ end
14
+
15
+ def build
16
+ return @hooks unless File.exist?(@dsl_file)
17
+ evaluate_file(@dsl_file)
18
+ @hooks.deep_stringify_keys!
19
+ end
20
+ memoize :build
21
+
22
+ def run_hooks
23
+ build
24
+ run_each_hook("before")
25
+ out = yield if block_given?
26
+ run_each_hook("after")
27
+ out
28
+ end
29
+
30
+ def run_each_hook(type)
31
+ hooks = @hooks.dig(type, @name) || []
32
+ hooks.each do |hook|
33
+ run_hook(type, hook)
34
+ end
35
+ end
36
+
37
+ def run_hook(type, hook)
38
+ return unless run?(hook)
39
+
40
+ command = File.basename(@dsl_file).sub('.rb','') # IE: kubes, kubectl, docker
41
+ id = "#{command} #{type} #{@name}"
42
+ label = " label: #{hook["label"]}" if hook["label"]
43
+ logger.info "Running #{id} hook.#{label}"
44
+ logger.debug "Hook options: #{hook}"
45
+ Runner.new(@mod, hook).run
46
+ end
47
+
48
+ def run?(hook)
49
+ !!hook["execute"]
50
+ end
51
+ end
52
+ end