itamae-mitsurin 0.32 → 0.33

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: ffa40997c28e38b4b9ce062e83505eb5f4f33510
4
- data.tar.gz: 232581689530c1e3e32893e4b9c41d37c0285ef5
3
+ metadata.gz: 9e3f1370d112d2e17244121f7844b94d13d35efd
4
+ data.tar.gz: 93da50239d20cb233da87db9974d74b1d50083a6
5
5
  SHA512:
6
- metadata.gz: f54264aa9d3aa84983404dfb2cc27b4bfb1c40f40d35c480ce764624c5cf05045ee63241b0b16beb2ae0c8099d2e5d512913361463d1abcf77d873648d6651d3
7
- data.tar.gz: cd6a2443f8c187bda4f7ac51ce18ade3838d71930ed8cf126d3f42982ca747e4598429bf5ec9dc8ee1f4e04307b8d84488cc110c85985a77d7fb88207fc632f1
6
+ metadata.gz: 5e26ec058020c8bab2607f7c71ea9ecfe9da021ae5062c836653d9541742c386cbca28bc9f2289e4a474a3e583a82678fc6ea6f7e80f541051a51141c41c7a91
7
+ data.tar.gz: 21aa878a2c844a67d7e6475c4c2746f253db1f04c331faf28ed9d78909dd76ec35c27cd4ad51afacf20d1e48faec9b0794b36682110438018663c026515b55fd
@@ -1,9 +1,14 @@
1
1
  ### The main itamae task
2
2
  require 'itamae-mitsurin/mitsurin/itamae_task'
3
3
 
4
- ### Change the directory to be read by the current git branch
4
+ ### Change the nodes to be load by a branch of the current git
5
+ ### In the case of now 'master' the task nodes in the 'nodes/master/'
5
6
  # require 'itamae-mitsurin/mitsurin/itamae_with_git_task'
6
7
 
8
+ ### Change the nodes to be read by a target mode
9
+ ### `rake -T <target>` to load a 'nodes/<target>'
10
+ # require 'itamae-mitsurin/mitsurin/itamae_with_target_task'
11
+
7
12
  ### Itamae task for AWS ec2instnce
8
13
  require 'itamae-mitsurin/mitsurin/local_task'
9
14
 
@@ -1,35 +1,36 @@
1
- require 'specinfra'
2
- require 'json'
3
- require 'highline'
4
- require 'specinfra/helper/set'
5
1
  require 'itamae-mitsurin/mitsurin/task_base'
6
- include Specinfra::Helper::Set
7
2
  include Rake::DSL if defined? Rake::DSL
8
3
 
9
- module Itamae
4
+ module ItamaeMitsurin
10
5
  module Mitsurin
11
6
  class ItamaeTask
12
7
 
13
- set :backend, :exec
14
-
15
8
  namespace :itamae do
16
- branches = Specinfra.backend.run_command('git branch')
17
- branch = branches.stdout.split("\n").select {|a| /\*/ === a }
18
- branch = branch.join.gsub(/\* (.+)/, '\1')
19
- if branch == 'staging'
20
- branch = 'staging/**'
21
- elsif branch == 'master'
22
- branch = 'production/**'
23
- else
24
- all = Dir.entries("nodes/")
25
- all.delete_if {|d| /(^\.|staging|production|.json)/ === d }
26
- branch = "{#{all.join(",")}}/**"
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
27
21
  end
22
+ ret = JSON.parse(File.read("Project.json"))
23
+ target = ret["project"] << '/**'
28
24
 
29
- Dir.glob("nodes/#{branch}/*.json").each do |node_file|
30
-
25
+ Dir.glob("nodes/#{target}/*.json").each do |node_file|
31
26
  bname = File.basename(node_file, '.json')
32
- node_h = JSON.parse(File.read(node_file), symbolize_names: true)
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
33
34
 
34
35
  desc "Itamae to #{bname}"
35
36
  task node_h[:environments][:hostname].split(".")[0] do
@@ -43,7 +44,7 @@ module Itamae
43
44
  end
44
45
  rescue Exception => e
45
46
  puts e.class.to_s + ", " + e.backtrace[0].to_s
46
- puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
47
+ puts "Node or role error, nodefile:#{node_file}, reason:#{e.message}"
47
48
  else
48
49
  recipes.flatten!
49
50
  end
@@ -51,18 +52,19 @@ module Itamae
51
52
  # get env attr
52
53
  begin
53
54
  env_set = node_h[:environments][:set]
55
+ raise "No environments set error" if env_set.nil?
54
56
  env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
55
57
  rescue Exception => e
56
58
  puts e.class.to_s + ", " + e.backtrace[0].to_s
57
- puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
59
+ puts "Node or environment error, nodefile:#{node_file}, reason:#{e.message}"
58
60
  end
59
61
 
60
- # get recipe attr
62
+ # get recipes attr
61
63
  recipe_attr_file = []
62
64
  recipes.each do |recipe_h|
63
- if recipe_h["#{recipe_h.keys.join}"].nil?
65
+ if recipe_h["#{recipe_h.keys.join}"] == "default"
64
66
  recipe_attr_file.insert 0,
65
- Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
67
+ Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
66
68
  else
67
69
  recipe_attr_file <<
68
70
  Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
@@ -71,31 +73,31 @@ module Itamae
71
73
 
72
74
  recipe_attr_file.flatten!
73
75
 
74
- # recipe attr other=env
76
+ # recipes attr other=env
75
77
  recipe_env_h_a = []
76
78
  recipe_attr_file.each do |file|
77
79
  recipe_h = JSON.parse(File.read(file), symbolize_names: true)
78
80
  recipe_env_h_a << recipe_h.deep_merge(env_h)
79
81
  end
80
82
 
81
- # recipe attr other=recipes
83
+ # recipe attr other=recipes_env
82
84
  moto = recipe_env_h_a[0]
83
85
  recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
84
86
  recipe_env_h = moto
85
87
 
86
88
  if recipe_env_h.nil?
87
- # node attr other=env
89
+ # env attr other=node
88
90
  node_env_h = env_h.deep_merge(node_h)
89
91
  node_env_j = TaskBase.jq node_env_h
90
92
  TaskBase.write_json(bname) {|file| file.puts node_env_j}
91
93
  else
92
- # node attr other=recipe_env
94
+ # recipe_env attr other=node
93
95
  recipe_env_node_h = recipe_env_h.deep_merge(node_h)
94
96
  recipe_env_node_j = TaskBase.jq recipe_env_node_h
95
97
  TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
96
98
  end
97
99
 
98
- recipes << {'_base' => nil}
100
+ recipes << {'_base' => 'default'}
99
101
  node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
100
102
  node = node_property[:environments][:hostname]
101
103
  ssh_user = node_property[:environments][:ssh_user]
@@ -119,24 +121,32 @@ module Itamae
119
121
  command << " --ask-password" unless ssh_password.nil?
120
122
  command << " --dry-run" if ENV['dry-run'] == "true"
121
123
  command << " -l debug" if ENV['debug'] == "true"
124
+ command << " -c logs/config/itamae_with_git_task.config"
122
125
 
123
- # recipe load to_command
126
+ # recipe load to_command
124
127
  command_recipe = []
125
128
  recipes.each do |recipe_h|
126
- if recipe_h["#{recipe_h.keys.join}"].nil?
127
- command_recipe <<
128
- " #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/default.rb").join}"
129
- else
130
- command_recipe <<
131
- " #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join}"
129
+ target_recipe = "site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb"
130
+ unless File.exists?("#{Dir.glob(target_recipe).join}")
131
+ ex_recipe = recipe_h.to_s.gsub('=>', '::').gsub('"', '')
132
+ raise "Recipe load error, nodefile:#{node_file}, reason:Not exist the recipe #{ex_recipe}"
132
133
  end
134
+ command_recipe << " #{Dir.glob(target_recipe).join("\s")}"
133
135
  end
136
+
134
137
  command_recipe.sort_by! {|item| File.dirname(item)}
135
138
  command << command_recipe.join
136
139
 
137
140
  puts TaskBase.hl.color(%!Run Itamae to \"#{bname}\"!, :red)
138
141
  run_list_noti = []
139
- command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
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
+
140
150
  puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
141
151
  puts TaskBase.hl.color(%!#{command}!, :white)
142
152
  st = system command
@@ -1 +1 @@
1
- 0.32
1
+ 0.33
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.32'
4
+ version: '0.33'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akihiro Kamiyama
@@ -331,7 +331,7 @@ files:
331
331
  - lib/itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/default_spec.rb
332
332
  - lib/itamae-mitsurin/mitsurin/itamae_task.rb
333
333
  - lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb
334
- - lib/itamae-mitsurin/mitsurin/itamae_with_git_task_old.rb
334
+ - lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb
335
335
  - lib/itamae-mitsurin/mitsurin/local_task.rb
336
336
  - lib/itamae-mitsurin/mitsurin/serverspec_task.rb
337
337
  - lib/itamae-mitsurin/mitsurin/task_base.rb