itamae-mitsurin 0.38 → 0.39

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce77231150b75053ae849ce8b2148f9061a2bc54
4
- data.tar.gz: cf6a95dbb7ecb252c819cbb430b82ae9822a6aa4
3
+ metadata.gz: af422192efcdc407ade7816bac6282d6004879ea
4
+ data.tar.gz: d4ee8a913e3443f945289b898f5e7e2576925650
5
5
  SHA512:
6
- metadata.gz: 8e3eb8316e71c408cba05e1a00de93644c300f3ebbfe76a4b298f17cae9188a1b14c0d2418e89b994d8971270100d5aa11a5c6ded49bd66daf1fce7c01f39076
7
- data.tar.gz: 41e23113264b22587ba7cd045fcc9a8f12423f4d02868eff1c55a988667ac14d90f154421815f40fe61ad5f4193a0b995f6814732c2b881b20e3b41c65a2ddfe
6
+ metadata.gz: a0b6ff77f1e52a0466b633908db5203d9c17559bf09a8d6063369049337a3a866b051cc38beea82bcdffedbc0c22f09a973205b182c49913897a11ea72274393
7
+ data.tar.gz: d7f30b606f6b0e01ff70b2303ddaaa331e6d9e0ebcbad82e74b66ba0f6b62baf63e0b31452a7e6002e677fe4de327ba1e0320b202a98b025afae5edbec33b58b
@@ -6,7 +6,7 @@ include Rake::DSL if defined? Rake::DSL
6
6
 
7
7
  module ItamaeMitsurin
8
8
  module Mitsurin
9
- class ItamaeTask
9
+ class ItamaeWithGitTask
10
10
 
11
11
  namespace :itamae do
12
12
  set :backend, :exec
@@ -3,7 +3,7 @@ include Rake::DSL if defined? Rake::DSL
3
3
 
4
4
  module ItamaeMitsurin
5
5
  module Mitsurin
6
- class ItamaeTask
6
+ class ItamaeWithTargetTask
7
7
 
8
8
  namespace :itamae do
9
9
  if (ARGV[0] == '-T' || ARGV[0] == '--tasks') && ARGV[1] != nil
@@ -0,0 +1,160 @@
1
+ require 'itamae-mitsurin/mitsurin/task_base'
2
+ include Rake::DSL if defined? Rake::DSL
3
+
4
+ module ItamaeMitsurin
5
+ module Mitsurin
6
+ class ServerspecWithTargetTask
7
+
8
+ namespace :spec do
9
+ if (ARGV[0] == '-T' || ARGV[0] == '--tasks') && ARGV[1] != nil
10
+ if File.exists?("nodes/#{ARGV[1]}")
11
+ project_h = {:project => ARGV[1]}
12
+ File.open "Project.json", 'w' do |f|
13
+ f.flock File::LOCK_EX
14
+ f.puts project_h.to_json
15
+ f.flock File::LOCK_UN
16
+ end
17
+ puts TaskBase.hl.color "Changed target mode '#{ARGV[1]}'", :green
18
+ else
19
+ raise "Change mode error '#{ARGV[1]}' is not exists"
20
+ end
21
+ end
22
+ ret = JSON.parse(File.read("Project.json"))
23
+ target = ret["project"] << '/**'
24
+
25
+ Dir.glob("nodes/#{target}/*.json").each do |node_file|
26
+ bname = File.basename(node_file, '.json')
27
+
28
+ begin
29
+ node_h = JSON.parse(File.read(node_file), symbolize_names: true)
30
+ rescue JSON::ParserError => e
31
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
32
+ puts "Node error, nodefile:#{node_file}, reason:#{e.message}"
33
+ end
34
+
35
+ desc "Serverspec to #{bname}"
36
+ task node_h[:environments][:hostname].split(".")[0] do
37
+ begin
38
+ recipes = []
39
+ TaskBase.get_roles(node_file).each do |role|
40
+ recipes << TaskBase.get_recipes(role)
41
+ end
42
+ TaskBase.get_node_recipes(node_file).each do |recipe|
43
+ recipes << recipe
44
+ end
45
+ rescue Exception => e
46
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
47
+ puts "Node or role error, nodefile:#{node_file}, reason:#{e.message}"
48
+ else
49
+ recipes.flatten!
50
+ end
51
+
52
+ # get env attr
53
+ begin
54
+ env_set = node_h[:environments][:set]
55
+ raise "No environments set error" if env_set.nil?
56
+ env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
57
+ rescue Exception => e
58
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
59
+ puts "Node or environment error, nodefile:#{node_file}, reason:#{e.message}"
60
+ end
61
+
62
+ # get recipes attr
63
+ recipe_attr_file = []
64
+ recipes.each do |recipe_h|
65
+ if recipe_h["#{recipe_h.keys.join}"] == "default"
66
+ recipe_attr_file.insert 0,
67
+ Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
68
+ else
69
+ recipe_attr_file <<
70
+ Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
71
+ end
72
+ end
73
+
74
+ recipe_attr_file.flatten!
75
+
76
+ # recipes attr other=env
77
+ recipe_env_h_a = []
78
+ recipe_attr_file.each do |file|
79
+ recipe_h = JSON.parse(File.read(file), symbolize_names: true)
80
+ recipe_env_h_a << recipe_h.deep_merge(env_h)
81
+ end
82
+
83
+ # recipe attr other=recipes_env
84
+ moto = recipe_env_h_a[0]
85
+ recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
86
+ recipe_env_h = moto
87
+
88
+ if recipe_env_h.nil?
89
+ # env attr other=node
90
+ node_env_h = env_h.deep_merge(node_h)
91
+ node_env_j = TaskBase.jq node_env_h
92
+ TaskBase.write_json(bname) {|file| file.puts node_env_j}
93
+ else
94
+ # recipe_env attr other=node
95
+ recipe_env_node_h = recipe_env_h.deep_merge(node_h)
96
+ recipe_env_node_j = TaskBase.jq recipe_env_node_h
97
+ TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
98
+ end
99
+
100
+ recipes << {'_base' => 'default'}
101
+ node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
102
+ node = node_property[:environments][:hostname]
103
+ ssh_user = node_property[:environments][:ssh_user]
104
+ ssh_password = node_property[:environments][:ssh_password]
105
+ sudo_password = node_property[:environments][:sudo_password]
106
+ ssh_port = node_property[:environments][:ssh_port]
107
+ ssh_key = node_property[:environments][:ssh_key]
108
+ local_ipv4 = node_property[:environments][:local_ipv4]
109
+
110
+ if local_ipv4.nil?
111
+ ENV['TARGET_HOST'] = node
112
+ else
113
+ ENV['TARGET_HOST'] = local_ipv4
114
+ end
115
+ ENV['NODE_FILE'] = node_file
116
+ ENV['SSH_PASSWORD'] = ssh_password
117
+ ENV['SUDO_PASSWORD'] = sudo_password
118
+ ENV['SSH_KEY'] = "keys/#{ssh_key}"
119
+ ENV['SSH_PORT'] = ssh_port
120
+ ENV['SSH_USER'] = ssh_user
121
+
122
+ command = "bundle exec rspec"
123
+
124
+ # spec load to_command
125
+ command_recipe = []
126
+ recipes.each do |recipe_h|
127
+ target_recipe = "site-cookbooks/**/#{recipe_h.keys.join}/spec/#{recipe_h[recipe_h.keys.join]}_spec.rb"
128
+ Dir.glob(target_recipe).join("\s").split.each do |target|
129
+ unless File.exists?(target)
130
+ ex_recipe = recipe_h.to_s.gsub('=>', '::').gsub('"', '')
131
+ raise "Recipe load error, nodefile:#{node_file}, reason:Not exist the recipe #{ex_recipe}"
132
+ end
133
+ command_recipe << " #{target}"
134
+ end
135
+ end
136
+
137
+ command_recipe.sort_by! {|item| File.dirname(item)}
138
+ command << command_recipe.join
139
+
140
+ puts TaskBase.hl.color(%!Run Spec to \"#{bname}\"!, :red)
141
+ run_list_noti = []
142
+ command_recipe.each { |c_recipe|
143
+ unless c_recipe.split("/")[4].split(".")[0] == 'default'
144
+ run_list_noti << c_recipe.split("/")[2] + "::#{c_recipe.split("/")[4].split(".")[0]}"
145
+ else
146
+ run_list_noti << c_recipe.split("/")[2]
147
+ end
148
+ }
149
+
150
+ puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
151
+ puts TaskBase.hl.color(%!#{command}!, :white)
152
+ st = system command
153
+ exit 1 unless st
154
+ end
155
+ end
156
+ end
157
+
158
+ end
159
+ end
160
+ end
@@ -1 +1 @@
1
- 0.38
1
+ 0.39
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-mitsurin
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.38'
4
+ version: '0.39'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Kamiyama
@@ -335,6 +335,7 @@ files:
335
335
  - lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb
336
336
  - lib/itamae-mitsurin/mitsurin/local_task.rb
337
337
  - lib/itamae-mitsurin/mitsurin/serverspec_task.rb
338
+ - lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb
338
339
  - lib/itamae-mitsurin/mitsurin/task_base.rb
339
340
  - lib/itamae-mitsurin/node.rb
340
341
  - lib/itamae-mitsurin/notification.rb