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,123 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'highline'
|
3
|
+
include Rake::DSL if defined? Rake::DSL
|
4
|
+
|
5
|
+
module Itamae
|
6
|
+
module Mitsurin
|
7
|
+
class ServerspecTask
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
task :spec => 'spec:all'
|
12
|
+
task :default => :spec
|
13
|
+
|
14
|
+
def self.get_roles(node_file)
|
15
|
+
roles = []
|
16
|
+
JSON.parse(File.read(node_file))['run_list'].each do |role|
|
17
|
+
roles << role.gsub(/role\[(.+)\]/, '\1') if /role\[(.+)\]/ === role
|
18
|
+
end
|
19
|
+
roles
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_recipes(role)
|
23
|
+
recipes = []
|
24
|
+
JSON.parse(File.read("roles/#{role}.json"))['run_list'].each do |recipe|
|
25
|
+
if /recipe\[(.+)::(.+)\]/ === recipe
|
26
|
+
recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')}
|
27
|
+
else
|
28
|
+
recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
recipes
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_node_recipes(node_file)
|
35
|
+
recipes = []
|
36
|
+
JSON.parse(File.read(node_file))['run_list'].each do |recipe|
|
37
|
+
if /recipe\[(.+)::(.+)\]/ === recipe
|
38
|
+
recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')}
|
39
|
+
else
|
40
|
+
recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil} unless /role\[(.+)\]/ === recipe
|
41
|
+
end
|
42
|
+
end
|
43
|
+
recipes
|
44
|
+
end
|
45
|
+
|
46
|
+
hl = HighLine.new
|
47
|
+
|
48
|
+
namespace :spec do
|
49
|
+
all = []
|
50
|
+
Dir.glob("tmp-nodes/**/*.json").each do |node_file|
|
51
|
+
|
52
|
+
file_name = File.basename(node_file, '.json')
|
53
|
+
node_attr = JSON.parse(File.read(node_file), symbolize_names: true)
|
54
|
+
|
55
|
+
desc "Spec to #{file_name}"
|
56
|
+
task node_attr[:environments][:hostname].split(".")[0] do
|
57
|
+
|
58
|
+
begin
|
59
|
+
recipes = []
|
60
|
+
get_roles(node_file).each do |role|
|
61
|
+
recipes << get_recipes(role)
|
62
|
+
end
|
63
|
+
get_node_recipes(node_file).each do |recipe|
|
64
|
+
recipes << recipe
|
65
|
+
end
|
66
|
+
rescue Exception => e
|
67
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
68
|
+
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
69
|
+
exit 1
|
70
|
+
else
|
71
|
+
recipes << {'_base' => nil}
|
72
|
+
recipes.flatten!
|
73
|
+
end
|
74
|
+
|
75
|
+
node_name = node_attr[:environments][:hostname]
|
76
|
+
ssh_user = node_attr[:environments][:ssh_user]
|
77
|
+
ssh_password = node_attr[:environments][:ssh_password]
|
78
|
+
sudo_password = node_attr[:environments][:sudo_password]
|
79
|
+
ssh_port = node_attr[:environments][:ssh_port]
|
80
|
+
ssh_key = node_attr[:environments][:ssh_key]
|
81
|
+
|
82
|
+
node_short = node_name.split(".")[0]
|
83
|
+
all << node_short
|
84
|
+
|
85
|
+
desc "Run spec to #{file_name}"
|
86
|
+
ENV['TARGET_HOST'] = node_name
|
87
|
+
ENV['NODE_FILE'] = node_file
|
88
|
+
ENV['SSH_PASSWORD'] = ssh_password
|
89
|
+
ENV['SUDO_PASSWORD'] = sudo_password
|
90
|
+
ENV['SSH_KEY'] = "keys/#{ssh_key}"
|
91
|
+
ENV['SSH_PORT'] = ssh_port
|
92
|
+
ENV['SSH_USER'] = ssh_user
|
93
|
+
|
94
|
+
specs = "bundle exec rspec"
|
95
|
+
|
96
|
+
# recipe load to_spec
|
97
|
+
spec_pattern = []
|
98
|
+
recipes.each do |spec_h|
|
99
|
+
if spec_h["#{spec_h.keys.join}"].nil?
|
100
|
+
spec_pattern <<
|
101
|
+
" #{Dir.glob("site-cookbooks/**/#{spec_h.keys.join}/spec/default_spec.rb").join}"
|
102
|
+
else
|
103
|
+
spec_pattern <<
|
104
|
+
" #{Dir.glob("site-cookbooks/**/#{spec_h.keys.join}/spec/#{spec_h["#{spec_h.keys.join}"]}_spec.rb").join}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
spec_pattern.sort_by! {|item| File.dirname(item)}
|
108
|
+
specs << spec_pattern.join
|
109
|
+
run_list_noti = []
|
110
|
+
spec_pattern.each {|c_spec| run_list_noti << c_spec.split("/") [2]}
|
111
|
+
puts hl.color(%!Run Serverspec to \"#{node_name}\"!, :red)
|
112
|
+
puts hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
|
113
|
+
st = system specs
|
114
|
+
exit 1 unless st
|
115
|
+
end
|
116
|
+
task :all => all
|
117
|
+
task :default => :all
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require 'itamae'
|
1
|
+
require 'itamae-mitsurin'
|
2
2
|
require 'hashie'
|
3
3
|
require 'json'
|
4
4
|
require 'schash'
|
5
5
|
|
6
|
-
module
|
6
|
+
module ItamaeMitsurin
|
7
7
|
class Node
|
8
8
|
ValidationError = Class.new(StandardError)
|
9
9
|
|
@@ -34,7 +34,7 @@ module Itamae
|
|
34
34
|
errors = Schash::Validator.new(&block).validate(@mash)
|
35
35
|
unless errors.empty?
|
36
36
|
errors.each do |error|
|
37
|
-
|
37
|
+
ItamaeMitsurin.logger.error "'#{error.position.join('->')}' #{error.message}"
|
38
38
|
end
|
39
39
|
raise ValidationError
|
40
40
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'itamae'
|
1
|
+
require 'itamae-mitsurin'
|
2
2
|
|
3
|
-
module
|
3
|
+
module ItamaeMitsurin
|
4
4
|
class Notification < Struct.new(:defined_in_resource, :action, :target_resource_desc, :timing)
|
5
5
|
def self.create(*args)
|
6
6
|
self.new(*args).tap(&:validate!)
|
@@ -32,7 +32,7 @@ module Itamae
|
|
32
32
|
|
33
33
|
def validate!
|
34
34
|
unless [:delay, :delayed, :immediately].include?(timing)
|
35
|
-
|
35
|
+
ItamaeMitsurin.logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
|
36
36
|
abort
|
37
37
|
end
|
38
38
|
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'itamae'
|
1
|
+
require 'itamae-mitsurin'
|
2
2
|
|
3
|
-
module
|
3
|
+
module ItamaeMitsurin
|
4
4
|
class Recipe
|
5
5
|
NotFoundError = Class.new(StandardError)
|
6
6
|
|
@@ -62,7 +62,7 @@ module Itamae
|
|
62
62
|
show_banner
|
63
63
|
|
64
64
|
@runner.handler.event(:recipe, path: @path) do
|
65
|
-
|
65
|
+
ItamaeMitsurin.logger.with_indent do
|
66
66
|
@children.run
|
67
67
|
run_delayed_notifications
|
68
68
|
end
|
@@ -82,7 +82,7 @@ module Itamae
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def show_banner
|
85
|
-
|
85
|
+
ItamaeMitsurin.logger.info "Recipe: #{@path}"
|
86
86
|
end
|
87
87
|
|
88
88
|
class EvalContext
|
@@ -131,7 +131,7 @@ module Itamae
|
|
131
131
|
end
|
132
132
|
|
133
133
|
if runner.children.find_recipe_by_path(path)
|
134
|
-
|
134
|
+
ItamaeMitsurin.logger.debug "Recipe, #{path}, is skipped because it is already included"
|
135
135
|
return
|
136
136
|
end
|
137
137
|
|
@@ -164,7 +164,7 @@ module Itamae
|
|
164
164
|
private
|
165
165
|
|
166
166
|
def show_banner
|
167
|
-
|
167
|
+
ItamaeMitsurin.logger.debug "#{@definition.resource_type}[#{@definition.resource_name}]"
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module ItamaeMitsurin
|
2
2
|
class RecipeChildren < Array
|
3
3
|
NotFoundError = Class.new(StandardError)
|
4
4
|
|
5
5
|
def find_resource_by_description(desc)
|
6
6
|
# desc is like 'resource_type[name]'
|
7
7
|
resources.find do |resource|
|
8
|
-
type, name =
|
8
|
+
type, name = ItamaeMitsurin::Resource.parse_description(desc)
|
9
9
|
resource.resource_type == type && resource.resource_name == name
|
10
10
|
end.tap do |resource|
|
11
11
|
unless resource
|
@@ -1,24 +1,24 @@
|
|
1
|
-
require 'itamae'
|
2
|
-
require 'itamae/mitsurin'
|
3
|
-
require 'itamae/resource/base'
|
4
|
-
require 'itamae/resource/file'
|
5
|
-
require 'itamae/resource/package'
|
6
|
-
require 'itamae/resource/remote_directory'
|
7
|
-
require 'itamae/resource/remote_file'
|
8
|
-
require 'itamae/resource/directory'
|
9
|
-
require 'itamae/resource/template'
|
10
|
-
require 'itamae/resource/http_request'
|
11
|
-
require 'itamae/resource/execute'
|
12
|
-
require 'itamae/resource/service'
|
13
|
-
require 'itamae/resource/link'
|
14
|
-
require 'itamae/resource/local_ruby_block'
|
15
|
-
require 'itamae/resource/git'
|
16
|
-
require 'itamae/resource/user'
|
17
|
-
require 'itamae/resource/group'
|
18
|
-
require 'itamae/resource/gem_package'
|
19
|
-
require 'itamae/resource/aws_ebs_volume'
|
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
20
|
|
21
|
-
module
|
21
|
+
module ItamaeMitsurin
|
22
22
|
module Resource
|
23
23
|
Error = Class.new(StandardError)
|
24
24
|
AttributeMissingError = Class.new(StandardError)
|
@@ -35,7 +35,7 @@ module Itamae
|
|
35
35
|
self.const_get(to_camel_case(method.to_s))
|
36
36
|
rescue NameError
|
37
37
|
begin
|
38
|
-
::
|
38
|
+
::ItamaeMitsurin::Plugin::Resource.const_get(to_camel_case(method.to_s))
|
39
39
|
rescue NameError
|
40
40
|
autoload_plugin_resource(method)
|
41
41
|
end
|
@@ -45,7 +45,7 @@ module Itamae
|
|
45
45
|
def autoload_plugin_resource(method)
|
46
46
|
begin
|
47
47
|
require "itamae/plugin/resource/#{method}"
|
48
|
-
::
|
48
|
+
::ItamaeMitsurin::Plugin::Resource.const_get(to_camel_case(method.to_s))
|
49
49
|
rescue LoadError, NameError
|
50
50
|
raise Error, "#{method} resource is missing."
|
51
51
|
end
|
@@ -54,7 +54,7 @@ module Itamae
|
|
54
54
|
def define_resource(name, klass)
|
55
55
|
class_name = to_camel_case(name.to_s)
|
56
56
|
if Resource.const_defined?(class_name)
|
57
|
-
|
57
|
+
ItamaeMitsurin.logger.warn "Redefine class. (#{class_name})"
|
58
58
|
return
|
59
59
|
end
|
60
60
|
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'itamae'
|
1
|
+
require 'itamae-mitsurin'
|
2
2
|
require 'shellwords'
|
3
3
|
require 'hashie'
|
4
4
|
|
5
|
-
module
|
5
|
+
module ItamaeMitsurin
|
6
6
|
module Resource
|
7
7
|
class Base
|
8
8
|
class EvalContext
|
@@ -122,14 +122,14 @@ module Itamae
|
|
122
122
|
|
123
123
|
def run(specific_action = nil)
|
124
124
|
runner.handler.event(:resource, resource_type: resource_type, resource_name: resource_name) do
|
125
|
-
|
125
|
+
ItamaeMitsurin.logger.debug "#{resource_type}[#{resource_name}]"
|
126
126
|
|
127
|
-
|
127
|
+
ItamaeMitsurin.logger.with_indent_if(ItamaeMitsurin.logger.debug?) do
|
128
128
|
if do_not_run_because_of_only_if?
|
129
|
-
|
129
|
+
ItamaeMitsurin.logger.debug "#{resource_type}[#{resource_name}] Execution skipped because of only_if attribute"
|
130
130
|
return
|
131
131
|
elsif do_not_run_because_of_not_if?
|
132
|
-
|
132
|
+
ItamaeMitsurin.logger.debug "#{resource_type}[#{resource_name}] Execution skipped because of not_if attribute"
|
133
133
|
return
|
134
134
|
end
|
135
135
|
|
@@ -147,7 +147,7 @@ module Itamae
|
|
147
147
|
@updated = false
|
148
148
|
end
|
149
149
|
rescue Backend::CommandExecutionError
|
150
|
-
|
150
|
+
ItamaeMitsurin.logger.error "#{resource_type}[#{resource_name}] Failed."
|
151
151
|
exit 2
|
152
152
|
end
|
153
153
|
|
@@ -170,24 +170,24 @@ module Itamae
|
|
170
170
|
|
171
171
|
clear_current_attributes
|
172
172
|
|
173
|
-
|
173
|
+
ItamaeMitsurin.logger.debug "#{resource_type}[#{resource_name}] action: #{action}"
|
174
174
|
|
175
175
|
return if action == :nothing
|
176
176
|
|
177
|
-
|
178
|
-
|
177
|
+
ItamaeMitsurin.logger.with_indent_if(ItamaeMitsurin.logger.debug?) do
|
178
|
+
ItamaeMitsurin.logger.debug "(in pre_action)"
|
179
179
|
pre_action
|
180
180
|
|
181
|
-
|
181
|
+
ItamaeMitsurin.logger.debug "(in set_current_attributes)"
|
182
182
|
set_current_attributes
|
183
183
|
|
184
|
-
|
184
|
+
ItamaeMitsurin.logger.debug "(in show_differences)"
|
185
185
|
show_differences
|
186
186
|
|
187
187
|
method_name = "action_#{action}"
|
188
188
|
if runner.dry_run?
|
189
189
|
unless respond_to?(method_name)
|
190
|
-
|
190
|
+
ItamaeMitsurin.logger.error "action #{action.inspect} is unavailable"
|
191
191
|
end
|
192
192
|
else
|
193
193
|
args = [method_name]
|
@@ -236,14 +236,14 @@ module Itamae
|
|
236
236
|
if current_value.nil? && value.nil?
|
237
237
|
# ignore
|
238
238
|
elsif current_value.nil? && !value.nil?
|
239
|
-
|
240
|
-
|
239
|
+
ItamaeMitsurin.logger.color :green do
|
240
|
+
ItamaeMitsurin.logger.info "#{resource_type}[#{resource_name}] #{key} will be '#{value}'"
|
241
241
|
end
|
242
242
|
elsif current_value == value || value.nil?
|
243
|
-
|
243
|
+
ItamaeMitsurin.logger.debug "#{resource_type}[#{resource_name}] #{key} will not change (current value is '#{current_value}')"
|
244
244
|
else
|
245
|
-
|
246
|
-
|
245
|
+
ItamaeMitsurin.logger.color :green do
|
246
|
+
ItamaeMitsurin.logger.info "#{resource_type}[#{resource_name}] #{key} will change from '#{current_value}' to '#{value}'"
|
247
247
|
end
|
248
248
|
end
|
249
249
|
end
|
@@ -327,7 +327,7 @@ module Itamae
|
|
327
327
|
end
|
328
328
|
|
329
329
|
def updated!
|
330
|
-
|
330
|
+
ItamaeMitsurin.logger.debug "This resource is updated."
|
331
331
|
@updated = true
|
332
332
|
end
|
333
333
|
|
@@ -345,10 +345,10 @@ module Itamae
|
|
345
345
|
message << " (immediately)"
|
346
346
|
end
|
347
347
|
|
348
|
-
|
348
|
+
ItamaeMitsurin.logger.info message
|
349
349
|
|
350
350
|
if notification.instance_of?(Subscription)
|
351
|
-
|
351
|
+
ItamaeMitsurin.logger.info "(because it subscribes this resource)"
|
352
352
|
end
|
353
353
|
|
354
354
|
if notification.delayed?
|
@@ -362,8 +362,8 @@ module Itamae
|
|
362
362
|
def verify
|
363
363
|
return if @verify_commands.empty?
|
364
364
|
|
365
|
-
|
366
|
-
|
365
|
+
ItamaeMitsurin.logger.info "Verifying..."
|
366
|
+
ItamaeMitsurin.logger.with_indent do
|
367
367
|
@verify_commands.each do |command|
|
368
368
|
run_command(command)
|
369
369
|
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'itamae-mitsurin'
|
2
|
+
|
3
|
+
module ItamaeMitsurin
|
4
|
+
module Resource
|
5
|
+
class File < Base
|
6
|
+
define_attribute :action, default: :create
|
7
|
+
define_attribute :path, type: String, default_name: true
|
8
|
+
define_attribute :content, type: String, default: nil
|
9
|
+
define_attribute :mode, type: String
|
10
|
+
define_attribute :owner, type: String
|
11
|
+
define_attribute :group, type: String
|
12
|
+
define_attribute :block, type: Proc, default: proc {}
|
13
|
+
|
14
|
+
def pre_action
|
15
|
+
case @current_action
|
16
|
+
when :create
|
17
|
+
attributes.exist = true
|
18
|
+
when :delete
|
19
|
+
attributes.exist = false
|
20
|
+
when :edit
|
21
|
+
attributes.exist = true
|
22
|
+
|
23
|
+
unless runner.dry_run?
|
24
|
+
content = backend.receive_file(attributes.path)
|
25
|
+
attributes.block.call(content)
|
26
|
+
attributes.content = content
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
send_tempfile
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_current_attributes
|
34
|
+
current.exist = run_specinfra(:check_file_is_file, attributes.path)
|
35
|
+
|
36
|
+
if current.exist
|
37
|
+
current.mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
|
38
|
+
current.owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
|
39
|
+
current.group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
|
40
|
+
else
|
41
|
+
current.mode = nil
|
42
|
+
current.owner = nil
|
43
|
+
current.group = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def show_differences
|
48
|
+
current.mode = current.mode.rjust(4, '0') if current.mode
|
49
|
+
attributes.mode = attributes.mode.rjust(4, '0') if attributes.mode
|
50
|
+
|
51
|
+
super
|
52
|
+
|
53
|
+
if @temppath && @current_action != :delete
|
54
|
+
compare_file
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def action_create(options)
|
59
|
+
if !current.exist && !@temppath
|
60
|
+
run_command(["touch", attributes.path])
|
61
|
+
end
|
62
|
+
|
63
|
+
change_target = @temppath || attributes.path
|
64
|
+
|
65
|
+
if attributes.mode
|
66
|
+
run_specinfra(:change_file_mode, change_target, attributes.mode)
|
67
|
+
end
|
68
|
+
if attributes.owner || attributes.group
|
69
|
+
run_specinfra(:change_file_owner, change_target, attributes.owner, attributes.group)
|
70
|
+
end
|
71
|
+
|
72
|
+
if @temppath
|
73
|
+
if run_specinfra(:check_file_is_file, attributes.path)
|
74
|
+
unless check_command(["diff", "-q", @temppath, attributes.path])
|
75
|
+
# the file is modified
|
76
|
+
updated!
|
77
|
+
end
|
78
|
+
else
|
79
|
+
# new file
|
80
|
+
updated!
|
81
|
+
end
|
82
|
+
|
83
|
+
if updated?
|
84
|
+
run_specinfra(:move_file, @temppath, attributes.path)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def action_delete(options)
|
90
|
+
if run_specinfra(:check_file_is_file, attributes.path)
|
91
|
+
run_specinfra(:remove_file, attributes.path)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def action_edit(options)
|
96
|
+
if attributes.mode
|
97
|
+
run_specinfra(:change_file_mode, @temppath, attributes.mode)
|
98
|
+
else
|
99
|
+
mode = run_specinfra(:get_file_mode, attributes.path).stdout.chomp
|
100
|
+
run_specinfra(:change_file_mode, @temppath, mode)
|
101
|
+
end
|
102
|
+
|
103
|
+
if attributes.owner || attributes.group
|
104
|
+
run_specinfra(:change_file_owner, @temppath, attributes.owner, attributes.group)
|
105
|
+
else
|
106
|
+
owner = run_specinfra(:get_file_owner_user, attributes.path).stdout.chomp
|
107
|
+
group = run_specinfra(:get_file_owner_group, attributes.path).stdout.chomp
|
108
|
+
run_specinfra(:change_file_owner, @temppath, owner)
|
109
|
+
run_specinfra(:change_file_group, @temppath, group)
|
110
|
+
end
|
111
|
+
|
112
|
+
unless check_command(["diff", "-q", @temppath, attributes.path])
|
113
|
+
# the file is modified
|
114
|
+
updated!
|
115
|
+
end
|
116
|
+
|
117
|
+
run_specinfra(:move_file, @temppath, attributes.path)
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def compare_file
|
123
|
+
compare_to = if current.exist
|
124
|
+
attributes.path
|
125
|
+
else
|
126
|
+
'/dev/null'
|
127
|
+
end
|
128
|
+
|
129
|
+
diff = run_command(["diff", "-u", compare_to, @temppath], error: false)
|
130
|
+
if diff.exit_status == 0
|
131
|
+
# no change
|
132
|
+
ItamaeMitsurin.logger.debug "file content will not change"
|
133
|
+
else
|
134
|
+
ItamaeMitsurin.logger.info "diff:"
|
135
|
+
diff.stdout.each_line do |line|
|
136
|
+
color = if line.start_with?('+')
|
137
|
+
:green
|
138
|
+
elsif line.start_with?('-')
|
139
|
+
:red
|
140
|
+
else
|
141
|
+
:clear
|
142
|
+
end
|
143
|
+
ItamaeMitsurin.logger.color(color) do
|
144
|
+
ItamaeMitsurin.logger.info line.chomp
|
145
|
+
end
|
146
|
+
end
|
147
|
+
runner.handler.event(:file_content_changed, diff: diff.stdout)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# will be overridden
|
152
|
+
def content_file
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
|
156
|
+
def send_tempfile
|
157
|
+
if !attributes.content && !content_file
|
158
|
+
@temppath = nil
|
159
|
+
return
|
160
|
+
end
|
161
|
+
|
162
|
+
begin
|
163
|
+
src = if content_file
|
164
|
+
content_file
|
165
|
+
else
|
166
|
+
f = Tempfile.open('itamae')
|
167
|
+
f.write(attributes.content)
|
168
|
+
f.close
|
169
|
+
f.path
|
170
|
+
end
|
171
|
+
|
172
|
+
@temppath = ::File.join(runner.tmpdir, Time.now.to_f.to_s)
|
173
|
+
backend.send_file(src, @temppath)
|
174
|
+
ensure
|
175
|
+
f.unlink if f
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|