itamae-mitsurin 0.4 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +2 -1
- data/Rakefile +17 -15
- data/bin/itamae +2 -3
- data/bin/manaita +5 -0
- data/itamae-mitsurin.gemspec +4 -4
- data/lib/itamae-mitsurin.rb +17 -0
- data/lib/{itamae → itamae-mitsurin}/backend.rb +13 -13
- data/lib/{itamae → itamae-mitsurin}/cli.rb +5 -5
- data/lib/{itamae → itamae-mitsurin}/definition.rb +2 -2
- data/lib/itamae-mitsurin/ext.rb +1 -0
- data/lib/{itamae → itamae-mitsurin}/ext/specinfra.rb +0 -0
- data/lib/{itamae → itamae-mitsurin}/handler.rb +3 -3
- data/lib/{itamae → itamae-mitsurin}/handler/base.rb +1 -1
- data/lib/{itamae → itamae-mitsurin}/handler/debug.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/handler/fluentd.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/handler/json.rb +1 -1
- data/lib/{itamae → itamae-mitsurin}/handler_proxy.rb +1 -1
- data/lib/{itamae → itamae-mitsurin}/logger.rb +5 -5
- data/lib/itamae-mitsurin/mitsurin.rb +14 -0
- data/lib/{itamae → itamae-mitsurin}/mitsurin/cli.rb +5 -5
- data/lib/{itamae → itamae-mitsurin}/mitsurin/creators.rb +3 -3
- data/lib/itamae-mitsurin/mitsurin/creators/cookbook.rb +24 -0
- data/lib/itamae-mitsurin/mitsurin/creators/project.rb +24 -0
- data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/.rspec +0 -0
- data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/Gemfile +0 -1
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +2 -0
- data/lib/{itamae/generators/templates/cookbook/files → itamae-mitsurin/mitsurin/creators/templates/project/environments}/.keep +0 -0
- data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/environments/sample.json +0 -0
- data/lib/{itamae/generators/templates/cookbook/templates → itamae-mitsurin/mitsurin/creators/templates/project/keys}/.keep +0 -0
- data/lib/{itamae/generators/templates/project/cookbooks → itamae-mitsurin/mitsurin/creators/templates/project/nodes}/.keep +0 -0
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +10 -0
- data/lib/{itamae/generators → itamae-mitsurin/mitsurin/creators}/templates/project/roles/.keep +0 -0
- data/lib/{itamae/generators/templates/role/files → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes}/.keep +0 -0
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +1 -0
- data/lib/{itamae/generators/templates/role/templates → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/directories}/.keep +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/environments → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/files}/.keep +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/keys → itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/templates}/.keep +0 -0
- data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -0
- data/lib/{itamae → itamae-mitsurin}/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/nodes → itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes}/.keep +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/roles → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes}/.keep +0 -0
- data/lib/{itamae/generators/templates/cookbook → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes}/default.rb +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/directories}/.keep +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes}/files/.keep +0 -0
- data/lib/{itamae/mitsurin/creators/templates/project/site-cookbooks/_base/_base → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes}/templates/.keep +0 -0
- data/lib/{itamae/generators/templates/role/default.rb → itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/default_spec.rb} +0 -0
- data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +197 -0
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +213 -0
- data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +123 -0
- data/lib/{itamae → itamae-mitsurin}/node.rb +3 -3
- data/lib/{itamae → itamae-mitsurin}/notification.rb +3 -3
- data/lib/{itamae → itamae-mitsurin}/recipe.rb +6 -6
- data/lib/{itamae → itamae-mitsurin}/recipe_children.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource.rb +23 -23
- data/lib/{itamae → itamae-mitsurin}/resource/aws_ebs_volume.rb +3 -3
- data/lib/{itamae → itamae-mitsurin}/resource/base.rb +23 -23
- data/lib/{itamae → itamae-mitsurin}/resource/directory.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/execute.rb +2 -2
- data/lib/itamae-mitsurin/resource/file.rb +180 -0
- data/lib/{itamae → itamae-mitsurin}/resource/gem_package.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/git.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/group.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/http_request.rb +3 -3
- data/lib/{itamae → itamae-mitsurin}/resource/link.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/local_ruby_block.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/package.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/remote_directory.rb +5 -5
- data/lib/{itamae → itamae-mitsurin}/resource/remote_file.rb +3 -3
- data/lib/{itamae → itamae-mitsurin}/resource/service.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/template.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/resource/user.rb +2 -2
- data/lib/{itamae → itamae-mitsurin}/runner.rb +8 -8
- data/lib/{itamae/mitsurin → itamae-mitsurin}/version.rb +1 -3
- data/lib/itamae-mitsurin/version.txt +1 -0
- data/test/test_itamae-mitsurin.rb +18 -0
- data/test/test_itamae-mitsurin/ext/test_specinfra.rb +39 -0
- data/test/test_itamae-mitsurin/handler/test_base.rb +40 -0
- data/test/test_itamae-mitsurin/handler/test_debug.rb +10 -0
- data/test/test_itamae-mitsurin/handler/test_fluentd.rb +44 -0
- data/test/test_itamae-mitsurin/handler/test_json.rb +22 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +2 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +3 -0
- data/{lib/itamae → test/test_itamae-mitsurin}/mitsurin/creators/templates/project/Rakefile +0 -0
- data/{lib/itamae/mitsurin/creators/templates/project/tmp-nodes → test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments}/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +7 -0
- data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/attributes → test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys}/.keep +0 -0
- data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/files → test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes}/.keep +0 -0
- data/{lib/itamae → test/test_itamae-mitsurin}/mitsurin/creators/templates/project/nodes/sample01.json +0 -0
- data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/spec → test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles}/.keep +0 -0
- data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/templates → test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes}/.keep +0 -0
- data/{lib/itamae/mitsurin/creators/templates/site-cookbooks/recipes/default.rb → test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep} +0 -0
- data/{lib/itamae → test/test_itamae-mitsurin}/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +1 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +33 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
- data/{lib/itamae/mitsurin/creators/cookbook.rb → test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb} +0 -0
- data/{lib/itamae/mitsurin/creators/project.rb → test/test_itamae-mitsurin/mitsurin/creators/test_project.rb} +0 -0
- data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +56 -0
- data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +19 -0
- data/{lib/itamae/mitsurin/itamae_task.rb → test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb} +0 -1
- data/{lib/itamae/mitsurin/itamae_with_git_task.rb → test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb} +0 -1
- data/{lib/itamae/mitsurin/serverspec_task.rb → test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb} +1 -1
- data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +84 -0
- data/test/test_itamae-mitsurin/resource/test_base.rb +374 -0
- data/test/test_itamae-mitsurin/resource/test_directory.rb +63 -0
- data/test/test_itamae-mitsurin/resource/test_execute.rb +26 -0
- data/{lib/itamae/resource/file.rb → test/test_itamae-mitsurin/resource/test_file.rb} +6 -6
- data/test/test_itamae-mitsurin/resource/test_gem_package.rb +81 -0
- data/test/test_itamae-mitsurin/resource/test_git.rb +94 -0
- data/test/test_itamae-mitsurin/resource/test_group.rb +42 -0
- data/test/test_itamae-mitsurin/resource/test_http_request.rb +71 -0
- data/test/test_itamae-mitsurin/resource/test_link.rb +33 -0
- data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +15 -0
- data/test/test_itamae-mitsurin/resource/test_package.rb +44 -0
- data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +84 -0
- data/test/test_itamae-mitsurin/resource/test_remote_file.rb +54 -0
- data/test/test_itamae-mitsurin/resource/test_service.rb +69 -0
- data/test/test_itamae-mitsurin/resource/test_template.rb +53 -0
- data/test/test_itamae-mitsurin/resource/test_user.rb +93 -0
- data/test/test_itamae-mitsurin/test_backend.rb +297 -0
- data/test/test_itamae-mitsurin/test_cli.rb +88 -0
- data/test/test_itamae-mitsurin/test_definition.rb +40 -0
- data/test/test_itamae-mitsurin/test_ext.rb +1 -0
- data/test/test_itamae-mitsurin/test_handler.rb +21 -0
- data/test/test_itamae-mitsurin/test_handler_proxy.rb +38 -0
- data/test/test_itamae-mitsurin/test_logger.rb +124 -0
- data/test/test_itamae-mitsurin/test_mitsurin.rb +14 -0
- data/test/test_itamae-mitsurin/test_node.rb +74 -0
- data/test/test_itamae-mitsurin/test_notification.rb +46 -0
- data/test/test_itamae-mitsurin/test_recipe.rb +171 -0
- data/test/test_itamae-mitsurin/test_recipe_children.rb +86 -0
- data/test/test_itamae-mitsurin/test_resource.rb +73 -0
- data/test/test_itamae-mitsurin/test_runner.rb +124 -0
- data/test/test_itamae-mitsurin/test_version.rb +3 -0
- data/{lib/itamae/mitsurin → test/test_itamae-mitsurin}/version.txt +0 -0
- data/test_project/.rspec +2 -0
- data/test_project/Gemfile +4 -0
- data/test_project/Rakefile +3 -0
- data/test_project/environments/.keep +0 -0
- data/test_project/keys/.keep +0 -0
- data/test_project/nodes/.keep +0 -0
- data/test_project/nodes/test.json +9 -0
- data/test_project/roles/.keep +0 -0
- data/test_project/roles/test.json +14 -0
- data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/test_project/site-cookbooks/_base/_base/recipes/default.rb +1 -0
- data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +1 -0
- data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +8 -0
- data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +4 -0
- data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/recipes/default.rb +2 -0
- data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +4 -0
- data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/recipes/default.rb +5 -0
- data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +6 -0
- data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/recipes/default.rb +5 -0
- data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +5 -0
- data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/recipes/default.rb +5 -0
- data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +5 -0
- data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +1 -0
- data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +9 -0
- data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +7 -0
- data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/recipes/default.rb +5 -0
- data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +7 -0
- data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/templates/template.erb +2 -0
- data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +6 -0
- data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +6 -0
- data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +10 -0
- data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +20 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
- data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
- data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
- data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
- data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
- data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
- data/test_project/spec/spec_helper.rb +33 -0
- data/test_project/tmp-nodes/.keep +0 -0
- data/test_project/tmp-nodes/test.json +12 -0
- metadata +337 -138
- data/bin/itamae-mitsurin +0 -5
- data/lib/itamae.rb +0 -18
- data/lib/itamae/ext.rb +0 -1
- data/lib/itamae/generators.rb +0 -20
- data/lib/itamae/generators/cookbook.rb +0 -22
- data/lib/itamae/generators/project.rb +0 -22
- data/lib/itamae/generators/role.rb +0 -22
- data/lib/itamae/generators/templates/project/Gemfile +0 -4
- data/lib/itamae/mitsurin.rb +0 -14
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'itamae-mitsurin'
|
2
|
+
|
3
|
+
module ItamaeMitsurin
|
4
|
+
class Recipe
|
5
|
+
NotFoundError = Class.new(StandardError)
|
6
|
+
|
7
|
+
attr_reader :path
|
8
|
+
attr_reader :runner
|
9
|
+
attr_reader :children
|
10
|
+
attr_reader :delayed_notifications
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def find_recipe_in_gem(recipe)
|
14
|
+
plugin_name, recipe_file = recipe.split('::', 2)
|
15
|
+
recipe_file = recipe_file.gsub("::", "/") if recipe_file
|
16
|
+
|
17
|
+
gem_name = "itamae-plugin-recipe-#{plugin_name}"
|
18
|
+
begin
|
19
|
+
gem gem_name
|
20
|
+
rescue LoadError
|
21
|
+
end
|
22
|
+
spec = Gem.loaded_specs.values.find do |spec|
|
23
|
+
spec.name == gem_name
|
24
|
+
end
|
25
|
+
|
26
|
+
return nil unless spec
|
27
|
+
|
28
|
+
candidate_files = []
|
29
|
+
if recipe_file
|
30
|
+
recipe_file += '.rb' unless recipe_file.end_with?('.rb')
|
31
|
+
candidate_files << "#{plugin_name}/#{recipe_file}"
|
32
|
+
else
|
33
|
+
candidate_files << "#{plugin_name}/default.rb"
|
34
|
+
candidate_files << "#{plugin_name}.rb"
|
35
|
+
end
|
36
|
+
|
37
|
+
candidate_files.map do |file|
|
38
|
+
File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', file)
|
39
|
+
end.find do |path|
|
40
|
+
File.exist?(path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def initialize(runner, path)
|
46
|
+
@runner = runner
|
47
|
+
@path = path
|
48
|
+
@delayed_notifications = []
|
49
|
+
@children = RecipeChildren.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def dir
|
53
|
+
::File.dirname(@path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def load(vars = {})
|
57
|
+
context = EvalContext.new(self, vars)
|
58
|
+
context.instance_eval(File.read(path), path, 1)
|
59
|
+
end
|
60
|
+
|
61
|
+
def run
|
62
|
+
show_banner
|
63
|
+
|
64
|
+
@runner.handler.event(:recipe, path: @path) do
|
65
|
+
ItamaeMitsurin.logger.with_indent do
|
66
|
+
@children.run
|
67
|
+
run_delayed_notifications
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def run_delayed_notifications
|
75
|
+
@delayed_notifications.uniq! do |notification|
|
76
|
+
[notification.action, notification.action_resource]
|
77
|
+
end
|
78
|
+
|
79
|
+
while notification = @delayed_notifications.shift
|
80
|
+
notification.run
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def show_banner
|
85
|
+
ItamaeMitsurin.logger.info "Recipe: #{@path}"
|
86
|
+
end
|
87
|
+
|
88
|
+
class EvalContext
|
89
|
+
def initialize(recipe, vars)
|
90
|
+
@recipe = recipe
|
91
|
+
|
92
|
+
vars.each do |k, v|
|
93
|
+
define_singleton_method(k) { v }
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def respond_to_missing?(method, include_private = false)
|
98
|
+
Resource.get_resource_class(method)
|
99
|
+
true
|
100
|
+
rescue NameError
|
101
|
+
false
|
102
|
+
end
|
103
|
+
|
104
|
+
def method_missing(*args, &block)
|
105
|
+
super unless args.size == 2
|
106
|
+
|
107
|
+
method, name = args
|
108
|
+
begin
|
109
|
+
klass = Resource.get_resource_class(method)
|
110
|
+
rescue NameError
|
111
|
+
super
|
112
|
+
end
|
113
|
+
|
114
|
+
resource = klass.new(@recipe, name, &block)
|
115
|
+
@recipe.children << resource
|
116
|
+
end
|
117
|
+
|
118
|
+
def define(name, params = {}, &block)
|
119
|
+
Resource.define_resource(name, Definition.create_class(name, params, @recipe, &block))
|
120
|
+
end
|
121
|
+
|
122
|
+
def include_recipe(target)
|
123
|
+
expanded_path = ::File.expand_path(target, File.dirname(@recipe.path))
|
124
|
+
expanded_path = ::File.join(expanded_path, 'default.rb') if ::Dir.exists?(expanded_path)
|
125
|
+
expanded_path.concat('.rb') unless expanded_path.end_with?('.rb')
|
126
|
+
candidate_paths = [expanded_path, Recipe.find_recipe_in_gem(target)].compact
|
127
|
+
path = candidate_paths.find {|path| File.exist?(path) }
|
128
|
+
|
129
|
+
unless path
|
130
|
+
raise NotFoundError, "Recipe not found. (#{target})"
|
131
|
+
end
|
132
|
+
|
133
|
+
if runner.children.find_recipe_by_path(path)
|
134
|
+
ItamaeMitsurin.logger.debug "Recipe, #{path}, is skipped because it is already included"
|
135
|
+
return
|
136
|
+
end
|
137
|
+
|
138
|
+
recipe = Recipe.new(runner, path)
|
139
|
+
@recipe.children << recipe
|
140
|
+
recipe.load
|
141
|
+
end
|
142
|
+
|
143
|
+
def node
|
144
|
+
runner.node
|
145
|
+
end
|
146
|
+
|
147
|
+
def runner
|
148
|
+
@recipe.runner
|
149
|
+
end
|
150
|
+
|
151
|
+
def run_command(*args)
|
152
|
+
runner.backend.run_command(*args)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class RecipeFromDefinition < Recipe
|
157
|
+
attr_accessor :definition
|
158
|
+
|
159
|
+
def load(vars = {})
|
160
|
+
context = EvalContext.new(self, vars)
|
161
|
+
context.instance_eval(&@definition.class.definition_block)
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def show_banner
|
167
|
+
ItamaeMitsurin.logger.debug "#{@definition.resource_type}[#{@definition.resource_name}]"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module ItamaeMitsurin
|
2
|
+
class RecipeChildren < Array
|
3
|
+
NotFoundError = Class.new(StandardError)
|
4
|
+
|
5
|
+
def find_resource_by_description(desc)
|
6
|
+
# desc is like 'resource_type[name]'
|
7
|
+
resources.find do |resource|
|
8
|
+
type, name = ItamaeMitsurin::Resource.parse_description(desc)
|
9
|
+
resource.resource_type == type && resource.resource_name == name
|
10
|
+
end.tap do |resource|
|
11
|
+
unless resource
|
12
|
+
raise NotFoundError, "'#{desc}' resource is not found."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def subscribing(target)
|
18
|
+
resources.map do |resource|
|
19
|
+
resource.subscriptions.select do |subscription|
|
20
|
+
subscription.resource == target
|
21
|
+
end
|
22
|
+
end.flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_recipe_by_path(path)
|
26
|
+
recipes.find do |recipe|
|
27
|
+
recipe.path == path
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def resources
|
32
|
+
self.map do |item|
|
33
|
+
case item
|
34
|
+
when Resource::Base
|
35
|
+
item
|
36
|
+
when Recipe
|
37
|
+
item.children.resources
|
38
|
+
end
|
39
|
+
end.flatten
|
40
|
+
end
|
41
|
+
|
42
|
+
def recipes(options = {})
|
43
|
+
options = {recursive: true}.merge(options)
|
44
|
+
|
45
|
+
self.select do |item|
|
46
|
+
item.is_a?(Recipe)
|
47
|
+
end.map do |recipe|
|
48
|
+
if options[:recursive]
|
49
|
+
[recipe] + recipe.children.recipes
|
50
|
+
else
|
51
|
+
recipe
|
52
|
+
end
|
53
|
+
end.flatten
|
54
|
+
end
|
55
|
+
|
56
|
+
def run
|
57
|
+
self.each do |resource|
|
58
|
+
resource.run
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# returns dependencies graph in DOT
|
63
|
+
def dependency_in_dot
|
64
|
+
result = ""
|
65
|
+
result << "digraph recipes {\n"
|
66
|
+
result << " rankdir=LR;\n"
|
67
|
+
result << _dependency_in_dot
|
68
|
+
result << "}"
|
69
|
+
|
70
|
+
result
|
71
|
+
end
|
72
|
+
|
73
|
+
def _dependency_in_dot
|
74
|
+
result = ""
|
75
|
+
|
76
|
+
recipes(recursive: false).each do |recipe|
|
77
|
+
recipe.children.recipes(recursive: false).each do |child_recipe|
|
78
|
+
result << %{ "#{recipe.path}" -> "#{child_recipe.path}";\n}
|
79
|
+
end
|
80
|
+
result << recipe.children._dependency_in_dot
|
81
|
+
end
|
82
|
+
|
83
|
+
result
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'itamae-mitsurin'
|
2
|
+
require 'itamae-mitsurin/mitsurin'
|
3
|
+
require 'itamae-mitsurin/resource/base'
|
4
|
+
require 'itamae-mitsurin/resource/file'
|
5
|
+
require 'itamae-mitsurin/resource/package'
|
6
|
+
require 'itamae-mitsurin/resource/remote_directory'
|
7
|
+
require 'itamae-mitsurin/resource/remote_file'
|
8
|
+
require 'itamae-mitsurin/resource/directory'
|
9
|
+
require 'itamae-mitsurin/resource/template'
|
10
|
+
require 'itamae-mitsurin/resource/http_request'
|
11
|
+
require 'itamae-mitsurin/resource/execute'
|
12
|
+
require 'itamae-mitsurin/resource/service'
|
13
|
+
require 'itamae-mitsurin/resource/link'
|
14
|
+
require 'itamae-mitsurin/resource/local_ruby_block'
|
15
|
+
require 'itamae-mitsurin/resource/git'
|
16
|
+
require 'itamae-mitsurin/resource/user'
|
17
|
+
require 'itamae-mitsurin/resource/group'
|
18
|
+
require 'itamae-mitsurin/resource/gem_package'
|
19
|
+
require 'itamae-mitsurin/resource/aws_ebs_volume'
|
20
|
+
|
21
|
+
module ItamaeMitsurin
|
22
|
+
module Resource
|
23
|
+
Error = Class.new(StandardError)
|
24
|
+
AttributeMissingError = Class.new(StandardError)
|
25
|
+
InvalidTypeError = Class.new(StandardError)
|
26
|
+
ParseError = Class.new(StandardError)
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def to_camel_case(str)
|
30
|
+
str.split('_').map {|part| part.capitalize}.join
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_resource_class(method)
|
34
|
+
begin
|
35
|
+
self.const_get(to_camel_case(method.to_s))
|
36
|
+
rescue NameError
|
37
|
+
begin
|
38
|
+
::ItamaeMitsurin::Plugin::Resource.const_get(to_camel_case(method.to_s))
|
39
|
+
rescue NameError
|
40
|
+
autoload_plugin_resource(method)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def autoload_plugin_resource(method)
|
46
|
+
begin
|
47
|
+
require "itamae/plugin/resource/#{method}"
|
48
|
+
::ItamaeMitsurin::Plugin::Resource.const_get(to_camel_case(method.to_s))
|
49
|
+
rescue LoadError, NameError
|
50
|
+
raise Error, "#{method} resource is missing."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def define_resource(name, klass)
|
55
|
+
class_name = to_camel_case(name.to_s)
|
56
|
+
if Resource.const_defined?(class_name)
|
57
|
+
ItamaeMitsurin.logger.warn "Redefine class. (#{class_name})"
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
Resource.const_set(class_name, klass)
|
62
|
+
end
|
63
|
+
|
64
|
+
def parse_description(desc)
|
65
|
+
if /\A([^\[]+)\[([^\]]+)\]\z/ =~ desc
|
66
|
+
[$1, $2]
|
67
|
+
else
|
68
|
+
raise ParseError, "'#{desc}' doesn't represent a resource."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'itamae-mitsurin'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module ItamaeMitsurin
|
6
|
+
class Runner
|
7
|
+
class << self
|
8
|
+
def run(recipe_files, backend_type, options)
|
9
|
+
ItamaeMitsurin.logger.info "Starting Itamae..."
|
10
|
+
|
11
|
+
backend = Backend.create(backend_type, options)
|
12
|
+
runner = self.new(backend, options)
|
13
|
+
runner.load_recipes(recipe_files)
|
14
|
+
runner.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :backend
|
19
|
+
attr_reader :options
|
20
|
+
attr_reader :node
|
21
|
+
attr_reader :tmpdir
|
22
|
+
attr_reader :children
|
23
|
+
attr_reader :handler
|
24
|
+
|
25
|
+
def initialize(backend, options)
|
26
|
+
@backend = backend
|
27
|
+
@options = options
|
28
|
+
|
29
|
+
prepare_handler
|
30
|
+
|
31
|
+
@node = create_node
|
32
|
+
@tmpdir = "/tmp/itamae_tmp"
|
33
|
+
@children = RecipeChildren.new
|
34
|
+
|
35
|
+
@backend.run_command(["mkdir", "-p", @tmpdir])
|
36
|
+
@backend.run_command(["chmod", "777", @tmpdir])
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_recipes(paths)
|
40
|
+
paths.each do |path|
|
41
|
+
expanded_path = File.expand_path(path)
|
42
|
+
if path.include?('::')
|
43
|
+
gem_path = Recipe.find_recipe_in_gem(path)
|
44
|
+
expanded_path = gem_path if gem_path
|
45
|
+
end
|
46
|
+
|
47
|
+
recipe = Recipe.new(self, expanded_path)
|
48
|
+
children << recipe
|
49
|
+
recipe.load
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def run
|
54
|
+
if recipe_graph_file = options[:recipe_graph]
|
55
|
+
save_dependency_graph(recipe_graph_file)
|
56
|
+
end
|
57
|
+
|
58
|
+
children.run
|
59
|
+
@backend.finalize
|
60
|
+
|
61
|
+
if profile = options[:profile]
|
62
|
+
save_profile(profile)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def dry_run?
|
67
|
+
@options[:dry_run]
|
68
|
+
end
|
69
|
+
|
70
|
+
def save_dependency_graph(path)
|
71
|
+
ItamaeMitsurin.logger.info "Writing recipe dependency graph to #{path}..."
|
72
|
+
open(path, 'w') do |f|
|
73
|
+
f.write(children.dependency_in_dot)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def save_profile(path)
|
78
|
+
open(path, 'w', 0600) do |f|
|
79
|
+
f.write(@backend.executed_commands.to_json)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
def create_node
|
85
|
+
hash = {}
|
86
|
+
|
87
|
+
if @options[:ohai]
|
88
|
+
unless @backend.run_command("which ohai", error: false).exit_status == 0
|
89
|
+
# install Ohai
|
90
|
+
ItamaeMitsurin.logger.info "Installing Chef package... (to use Ohai)"
|
91
|
+
@backend.run_command("curl -L https://www.opscode.com/chef/install.sh | bash")
|
92
|
+
end
|
93
|
+
|
94
|
+
ItamaeMitsurin.logger.info "Loading node data via ohai..."
|
95
|
+
hash.merge!(JSON.parse(@backend.run_command("ohai").stdout))
|
96
|
+
end
|
97
|
+
|
98
|
+
if @options[:node_json]
|
99
|
+
path = File.expand_path(@options[:node_json])
|
100
|
+
ItamaeMitsurin.logger.info "Loading node data from #{path}..."
|
101
|
+
hash.merge!(JSON.load(open(path)))
|
102
|
+
end
|
103
|
+
|
104
|
+
if @options[:node_yaml]
|
105
|
+
path = File.expand_path(@options[:node_yaml])
|
106
|
+
ItamaeMitsurin.logger.info "Loading node data from #{path}..."
|
107
|
+
hash.merge!(YAML.load(open(path)) || {})
|
108
|
+
end
|
109
|
+
|
110
|
+
Node.new(hash, @backend)
|
111
|
+
end
|
112
|
+
|
113
|
+
def prepare_handler
|
114
|
+
@handler = HandlerProxy.new
|
115
|
+
(@options[:handlers] || []).each do |handler|
|
116
|
+
type = handler.delete('type')
|
117
|
+
unless type
|
118
|
+
raise "#{type} field is not set"
|
119
|
+
end
|
120
|
+
@handler.register_instance(Handler.from_type(type).new(handler))
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|