itamae-mitsurin 0.12 → 0.13

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: 68809a61d7faf30d53cf1acf769b64d2b9d4bab4
4
- data.tar.gz: 0a0664ce51fe7814e5c8930e124eb119eff09c67
3
+ metadata.gz: 0569c16f25204c1c623fcc4067ca68c04b8afc33
4
+ data.tar.gz: b83eda09fa7bd239be9014f368a4793e4fd48b93
5
5
  SHA512:
6
- metadata.gz: 9e1d33a2a2557769d0e32c7394c8a4b9f0aa190a891dd4913672882cc2b614dbf44e95ae3d0cadcd40ea1730e15ec504197560e7335b65802527de92dc6f2b47
7
- data.tar.gz: 38bdd3bde535d2d3a2570bef2262c438f8cee0d9c79d112ac9b3fc9b3d431dcbb8bc240cabf5b75c1f057d6352e986a900455da98c62d36e733f7c59b8235727
6
+ metadata.gz: ef9675110a3974320efc7f319b88799fb762d261a49d533bf8b648cdcd944a74205204b4bf5be01d2ee1717d7dfa675f7615715d08e37af533d1b0c1bedb3b81
7
+ data.tar.gz: 5e6cbc175cfae25369362d30c0b0045bc7a167748506276d427e070527bdde605832f9f029a0b3f85014c3269bb71b5edd2dc5cd21ff886cdf85c4a05036fb20
data/README.md CHANGED
@@ -13,14 +13,17 @@ Customized version of Itamae and plugin
13
13
 
14
14
  ```
15
15
  $ gem install itamae-mitsurin
16
- $ mkdir [project_dir]
17
- $ cd [project_dir]
18
16
  $ manaita init
19
17
  ```
20
18
 
19
+ ## If you want to use the AWS Resources
20
+ ```
21
+ $ aws configure
22
+ ```
23
+
21
24
  - Tips for AmazonLinux
22
25
  ```
23
- yum install ruby-devel ruby20-devel gcc-c++ rubygem20-io-console.x86_64
26
+ yum install ruby-devel ruby20-devel gcc-c++ rubygem20-io-console
24
27
  ```
25
28
 
26
29
  ## Usage AWS Resource
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_runtime_dependency "json"
29
29
  spec.add_runtime_dependency "io-console"
30
30
  spec.add_runtime_dependency "bundler"
31
+ spec.add_runtime_dependency "tempdir"
31
32
 
32
33
  spec.add_development_dependency "rake-compiler"
33
34
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -1,3 +1,4 @@
1
1
  require 'itamae-mitsurin/mitsurin/itamae_task'
2
2
  #require 'itamae-mitsurin/mitsurin/itamae_with_git_task'
3
+ require 'itamae-mitsurin/mitsurin/local_task'
3
4
  require 'itamae-mitsurin/mitsurin/serverspec_task'
@@ -1,5 +1,3 @@
1
- require 'json'
2
- require 'highline'
3
1
  require 'itamae-mitsurin/mitsurin/task_base'
4
2
  include Rake::DSL if defined? Rake::DSL
5
3
 
@@ -11,7 +9,12 @@ module ItamaeMitsurin
11
9
  Dir.glob("nodes/**/*.json").each do |node_file|
12
10
 
13
11
  bname = File.basename(node_file, '.json')
14
- node_h = JSON.parse(File.read(node_file), symbolize_names: true)
12
+ begin
13
+ node_h = JSON.parse(File.read(node_file), symbolize_names: true)
14
+ rescue JSON::ParserError => e
15
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
16
+ puts "nodefile error, nodefile:#{node_file}, reason:#{e.message}"
17
+ end
15
18
 
16
19
  desc "Itamae to #{bname}"
17
20
  task node_h[:environments][:hostname].split(".")[0] do
@@ -25,7 +28,7 @@ module ItamaeMitsurin
25
28
  end
26
29
  rescue Exception => e
27
30
  puts e.class.to_s + ", " + e.backtrace[0].to_s
28
- puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
31
+ puts "nodefile or role error, nodefile:#{node_file}, reason:#{e.message}"
29
32
  else
30
33
  recipes.flatten!
31
34
  end
@@ -33,18 +36,19 @@ module ItamaeMitsurin
33
36
  # get env attr
34
37
  begin
35
38
  env_set = node_h[:environments][:set]
39
+ raise "No environments set error" if env_set.nil?
36
40
  env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
37
41
  rescue Exception => e
38
42
  puts e.class.to_s + ", " + e.backtrace[0].to_s
39
- puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
43
+ puts "nodefile or environments error, nodefile:#{node_file}, reason:#{e.message}"
40
44
  end
41
45
 
42
46
  # get recipes attr
43
47
  recipe_attr_file = []
44
48
  recipes.each do |recipe_h|
45
- if recipe_h["#{recipe_h.keys.join}"].nil?
49
+ if recipe_h["#{recipe_h.keys.join}"] == "default"
46
50
  recipe_attr_file.insert 0,
47
- Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
51
+ Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
48
52
  else
49
53
  recipe_attr_file <<
50
54
  Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
@@ -77,7 +81,7 @@ module ItamaeMitsurin
77
81
  TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
78
82
  end
79
83
 
80
- recipes << {'_base' => nil}
84
+ recipes << {'_base' => 'default'}
81
85
  node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
82
86
  node = node_property[:environments][:hostname]
83
87
  ssh_user = node_property[:environments][:ssh_user]
@@ -105,13 +109,8 @@ module ItamaeMitsurin
105
109
  # recipe load to_command
106
110
  command_recipe = []
107
111
  recipes.each do |recipe_h|
108
- if recipe_h["#{recipe_h.keys.join}"].nil?
109
- command_recipe <<
110
- " #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/default.rb").join}"
111
- else
112
- command_recipe <<
113
- " #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join}"
114
- end
112
+ command_recipe <<
113
+ " #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join("\s")}"
115
114
  end
116
115
 
117
116
  command_recipe.sort_by! {|item| File.dirname(item)}
@@ -0,0 +1,137 @@
1
+ require 'itamae-mitsurin/mitsurin/task_base'
2
+ include Rake::DSL if defined? Rake::DSL
3
+
4
+ # For AWS Resources
5
+
6
+ module ItamaeMitsurin
7
+ module Mitsurin
8
+ class LocalTask
9
+ namespace :local do
10
+ Dir.glob("nodes/**/*.json").each do |node_file|
11
+ bname = File.basename(node_file, '.json')
12
+
13
+ begin
14
+ node_h = JSON.parse(File.read(node_file), symbolize_names: true)
15
+ rescue JSON::ParserError => e
16
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
17
+ puts "nodefile error, nodefile:#{node_file}, reason:#{e.message}"
18
+ else
19
+ all << node_h[:environments][:hostname].split(".")[0]
20
+ task :all => all
21
+ end
22
+
23
+ desc "Local to #{bname}"
24
+ task node_h[:environments][:hostname].split(".")[0] do
25
+ begin
26
+ recipes = []
27
+ TaskBase.get_roles(node_file).each do |role|
28
+ recipes << TaskBase.get_recipes(role)
29
+ end
30
+ TaskBase.get_node_recipes(node_file).each do |recipe|
31
+ recipes << recipe
32
+ end
33
+ rescue Exception => e
34
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
35
+ puts "nodefile or role error, nodefile:#{node_file}, reason:#{e.message}"
36
+ else
37
+ recipes.flatten!
38
+ end
39
+
40
+ # get env attr
41
+ begin
42
+ env_set = node_h[:environments][:set]
43
+ raise "No environments set error" if env_set.nil?
44
+ env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
45
+ rescue Exception => e
46
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
47
+ puts "nodefile or environments error, nodefile:#{node_file}, reason:#{e.message}"
48
+ end
49
+
50
+ # get recipes attr
51
+ recipe_attr_file = []
52
+ recipes.each do |recipe_h|
53
+ if recipe_h["#{recipe_h.keys.join}"] == "default"
54
+ recipe_attr_file.insert 0,
55
+ Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
56
+ else
57
+ recipe_attr_file <<
58
+ Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
59
+ end
60
+ end
61
+
62
+ recipe_attr_file.flatten!
63
+
64
+ # recipes attr other=env
65
+ recipe_env_h_a = []
66
+ recipe_attr_file.each do |file|
67
+ recipe_h = JSON.parse(File.read(file), symbolize_names: true)
68
+ recipe_env_h_a << recipe_h.deep_merge(env_h)
69
+ end
70
+
71
+ # recipe attr other=recipes_env
72
+ moto = recipe_env_h_a[0]
73
+ recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
74
+ recipe_env_h = moto
75
+
76
+ if recipe_env_h.nil?
77
+ # env attr other=node
78
+ node_env_h = env_h.deep_merge(node_h)
79
+ node_env_j = TaskBase.jq node_env_h
80
+ path = TaskBase.write_tmp_json(bname) {|file| file.puts node_env_j}
81
+ else
82
+ # recipe_env attr other=node
83
+ recipe_env_node_h = recipe_env_h.deep_merge(node_h)
84
+ recipe_env_node_j = TaskBase.jq recipe_env_node_h
85
+ path = TaskBase.write_tmp_json(bname) {|file| file.puts recipe_env_node_j}
86
+ end
87
+
88
+ recipes << {'_base' => 'default'}
89
+ node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
90
+ node = node_property[:environments][:hostname]
91
+ sudo_password = node_property[:environments][:sudo_password]
92
+
93
+ ENV['TARGET_HOST'] = node
94
+ ENV['NODE_FILE'] = node_file
95
+ ENV['SUDO_PASSWORD'] = sudo_password
96
+
97
+ command = "bundle exec itamae local"
98
+ command << " -h #{node}"
99
+ command << " -j #{path}/#{bname}.json"
100
+ command << " --shell=bash"
101
+ command << " --ask-password" unless ssh_password.nil?
102
+ command << " --dry-run" if ENV['dry-run'] == "true"
103
+ command << " -l debug" if ENV['debug'] == "true"
104
+
105
+ # recipe load to_command
106
+ command_recipe = []
107
+ recipes.each do |recipe_h|
108
+ command_recipe <<
109
+ " #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join("\s")}"
110
+ end
111
+
112
+ command_recipe.sort_by! {|item| File.dirname(item)}
113
+ command << command_recipe.join
114
+
115
+ puts TaskBase.hl.color(%!Run Itamae to \"#{bname}\"!, :red)
116
+ run_list_noti = []
117
+ command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
118
+ puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
119
+ puts TaskBase.hl.color(%!#{command}!, :white)
120
+ begin
121
+ st = system command
122
+ rescue Exception => e
123
+ puts "command error, nodefile:#{node_file}, reason:#{e.message}"
124
+ puts "#{e.backtrace}"
125
+ ensure
126
+ FileUtils.remove_entry_secure path
127
+ exit 1 unless st
128
+ end
129
+ end
130
+ end
131
+ desc "local init all"
132
+ task :local => 'local:all'
133
+ end
134
+
135
+ end
136
+ end
137
+ end
@@ -1,5 +1,3 @@
1
- require 'json'
2
- require 'highline'
3
1
  require 'itamae-mitsurin/mitsurin/task_base'
4
2
  include Rake::DSL if defined? Rake::DSL
5
3
 
@@ -14,37 +12,43 @@ module Itamae
14
12
  Dir.glob("tmp-nodes/**/*.json").each do |node_file|
15
13
 
16
14
  file_name = File.basename(node_file, '.json')
17
- node_attr = JSON.parse(File.read(node_file), symbolize_names: true)
15
+ begin
16
+ node_attr = JSON.parse(File.read(node_file), symbolize_names: true)
17
+ rescue JSON::ParserError => e
18
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
19
+ puts "nodefile error, nodefile:#{node_file}, reason:#{e.message}"
20
+ end
18
21
 
19
22
  desc "Spec to #{file_name}"
20
23
  task node_attr[:environments][:hostname].split(".")[0] do
21
24
 
22
- begin
23
- recipes = []
24
- TaskBase.get_roles(node_file).each do |role|
25
- recipes << TaskBase.get_recipes(role)
26
- end
27
- TaskBase.get_node_recipes(node_file).each do |recipe|
28
- recipes << recipe
25
+ begin
26
+ recipes = []
27
+ TaskBase.get_roles(node_file).each do |role|
28
+ recipes << TaskBase.get_recipes(role)
29
+ end
30
+ TaskBase.get_node_recipes(node_file).each do |recipe|
31
+ recipes << recipe
32
+ end
33
+ rescue Exception => e
34
+ puts e.class.to_s + ", " + e.backtrace[0].to_s
35
+ puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
36
+ exit 1
37
+ else
38
+ recipes << {'_base' => 'default'}
39
+ recipes.flatten!
29
40
  end
30
- rescue Exception => e
31
- puts e.class.to_s + ", " + e.backtrace[0].to_s
32
- puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
33
- exit 1
34
- else
35
- recipes << {'_base' => nil}
36
- recipes.flatten!
37
- end
38
41
 
39
- node_name = node_attr[:environments][:hostname]
40
- ssh_user = node_attr[:environments][:ssh_user]
41
- ssh_password = node_attr[:environments][:ssh_password]
42
- sudo_password = node_attr[:environments][:sudo_password]
43
- ssh_port = node_attr[:environments][:ssh_port]
44
- ssh_key = node_attr[:environments][:ssh_key]
42
+ node_name = node_attr[:environments][:hostname]
43
+ ssh_user = node_attr[:environments][:ssh_user]
44
+ ssh_password = node_attr[:environments][:ssh_password]
45
+ sudo_password = node_attr[:environments][:sudo_password]
46
+ ssh_port = node_attr[:environments][:ssh_port]
47
+ ssh_key = node_attr[:environments][:ssh_key]
45
48
 
46
- node_short = node_name.split(".")[0]
49
+ node_short = node_name.split(".")[0]
47
50
  all << node_short
51
+ task :all => all
48
52
 
49
53
  desc "Run spec to #{file_name}"
50
54
  ENV['TARGET_HOST'] = node_name
@@ -60,13 +64,8 @@ module Itamae
60
64
  # recipe load to_spec
61
65
  spec_pattern = []
62
66
  recipes.each do |spec_h|
63
- if spec_h["#{spec_h.keys.join}"].nil?
64
- spec_pattern <<
65
- " #{Dir.glob("site-cookbooks/**/#{spec_h.keys.join}/spec/default_spec.rb").join}"
66
- else
67
- spec_pattern <<
68
- " #{Dir.glob("site-cookbooks/**/#{spec_h.keys.join}/spec/#{spec_h["#{spec_h.keys.join}"]}_spec.rb").join}"
69
- end
67
+ spec_pattern <<
68
+ " #{Dir.glob("site-cookbooks/**/#{spec_h.keys.join}/spec/#{spec_h["#{spec_h.keys.join}"]}_spec.rb").join("\s")}"
70
69
  end
71
70
 
72
71
  spec_pattern.sort_by! {|item| File.dirname(item)}
@@ -78,8 +77,8 @@ module Itamae
78
77
  st = system specs
79
78
  exit 1 unless st
80
79
  end
81
- task :all => all
82
- task :default => :all
80
+ desc "Serverspec to all nodes"
81
+ task :all => 'spec:all'
83
82
  end
84
83
  end
85
84
 
@@ -1,3 +1,6 @@
1
+ require 'json'
2
+ require 'highline'
3
+ require "tmpdir"
1
4
 
2
5
  module ItamaeMitsurin
3
6
  module Mitsurin
@@ -30,7 +33,7 @@ module ItamaeMitsurin
30
33
  if /recipe\[(.+)::(.+)\]/ === recipe
31
34
  recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')}
32
35
  else
33
- recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil}
36
+ recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => 'default'}
34
37
  end
35
38
  end
36
39
  recipes
@@ -42,7 +45,7 @@ module ItamaeMitsurin
42
45
  if /recipe\[(.+)::(.+)\]/ === recipe
43
46
  recipes << {recipe.gsub(/recipe\[(.+)::(.+)\]/, '\1') => recipe.gsub(/recipe\[(.+)::(.+)\]/, '\2')}
44
47
  else
45
- recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => nil} unless /role\[(.+)\]/ === recipe
48
+ recipes << {recipe.gsub(/recipe\[(.+)\]/, '\1') => 'default'} unless /role\[(.+)\]/ === recipe
46
49
  end
47
50
  end
48
51
  recipes
@@ -62,6 +65,16 @@ module ItamaeMitsurin
62
65
  end
63
66
  end
64
67
 
68
+ def write_tmp_json(filename)
69
+ path = Dir.mktmpdir("mitsurin-")
70
+ open("#{path}/#{filename}.json", "w") do |f|
71
+ f.flock File::LOCK_EX
72
+ yield f
73
+ f.flock File::LOCK_UN
74
+ end
75
+ path
76
+ end
77
+
65
78
  def hl
66
79
  HighLine.new
67
80
  end
@@ -1 +1 @@
1
- 0.12
1
+ 0.13
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-mitsurin
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.12'
4
+ version: '0.13'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Kamiyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -170,6 +170,20 @@ dependencies:
170
170
  - - ">="
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: tempdir
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :runtime
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
173
187
  - !ruby/object:Gem::Dependency
174
188
  name: rake-compiler
175
189
  requirement: !ruby/object:Gem::Requirement
@@ -294,6 +308,7 @@ files:
294
308
  - lib/itamae-mitsurin/mitsurin/creators/templates/project/Gemfile
295
309
  - lib/itamae-mitsurin/mitsurin/creators/templates/project/Rakefile
296
310
  - lib/itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep
311
+ - lib/itamae-mitsurin/mitsurin/creators/templates/project/environments/nothing.json
297
312
  - lib/itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json
298
313
  - lib/itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep
299
314
  - lib/itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep
@@ -315,6 +330,7 @@ files:
315
330
  - lib/itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/default_spec.rb
316
331
  - lib/itamae-mitsurin/mitsurin/itamae_task.rb
317
332
  - lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb
333
+ - lib/itamae-mitsurin/mitsurin/local_task.rb
318
334
  - lib/itamae-mitsurin/mitsurin/serverspec_task.rb
319
335
  - lib/itamae-mitsurin/mitsurin/task_base.rb
320
336
  - lib/itamae-mitsurin/node.rb