itamae-mitsurin 0.14 → 0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/itamae-mitsurin.gemspec +4 -1
- data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +1 -1
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +24 -25
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task_old.rb +150 -0
- data/lib/itamae-mitsurin/version.txt +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e84304c5237c95c74a4775e2a865b2e05aac329
|
4
|
+
data.tar.gz: 8027221c63d6db4c8ac695d691f8cb7d6eb98771
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec0f2b2ab395e0bc53effdcc9279e0d655ceaf0483309090c3e6faa88f1ad2c37a384dd4b2f1b7f2f9291ce2f675ed62aa3a29f618fd573e79dbb7b67ed0452a
|
7
|
+
data.tar.gz: b31cf70518995d279f1f80322b6f4809dda11616ceb5bcf75177c32a4cd00ba25e8c7189b9cab1f20f50087c7971b482606d3ea690a6190700019468dcbf3050
|
data/itamae-mitsurin.gemspec
CHANGED
@@ -8,7 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ItamaeMitsurin::VERSION
|
9
9
|
spec.authors = ["Akihiro Kamiyama"]
|
10
10
|
spec.email = ["akihiro.vamps@gmail.com"]
|
11
|
-
spec.summary = %q{Customized version of Itamae and Itamae plugin
|
11
|
+
spec.summary = %q{Customized version of Itamae and Itamae plugin.
|
12
|
+
configuration management tool like chef.
|
13
|
+
Deploy without the agent.
|
14
|
+
It can be deployed using the AWS Resources.}
|
12
15
|
spec.homepage = "https://github.com/kammy1231/itamae-mitsurin"
|
13
16
|
spec.license = "MIT"
|
14
17
|
|
@@ -1,18 +1,15 @@
|
|
1
1
|
require 'specinfra'
|
2
|
-
require 'json'
|
3
|
-
require 'highline'
|
4
2
|
require 'specinfra/helper/set'
|
5
3
|
require 'itamae-mitsurin/mitsurin/task_base'
|
6
4
|
include Specinfra::Helper::Set
|
7
5
|
include Rake::DSL if defined? Rake::DSL
|
8
6
|
|
9
|
-
module
|
7
|
+
module ItamaeMitsurin
|
10
8
|
module Mitsurin
|
11
9
|
class ItamaeTask
|
12
10
|
|
13
|
-
set :backend, :exec
|
14
|
-
|
15
11
|
namespace :itamae do
|
12
|
+
set :backend, :exec
|
16
13
|
branches = Specinfra.backend.run_command('git branch')
|
17
14
|
branch = branches.stdout.split("\n").select {|a| /\*/ === a }
|
18
15
|
branch = branch.join.gsub(/\* (.+)/, '\1')
|
@@ -27,9 +24,14 @@ module Itamae
|
|
27
24
|
end
|
28
25
|
|
29
26
|
Dir.glob("nodes/#{branch}/*.json").each do |node_file|
|
30
|
-
|
31
27
|
bname = File.basename(node_file, '.json')
|
32
|
-
|
28
|
+
|
29
|
+
begin
|
30
|
+
node_h = JSON.parse(File.read(node_file), symbolize_names: true)
|
31
|
+
rescue JSON::ParserError => e
|
32
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
33
|
+
puts "nodefile error, nodefile:#{node_file}, reason:#{e.message}"
|
34
|
+
end
|
33
35
|
|
34
36
|
desc "Itamae to #{bname}"
|
35
37
|
task node_h[:environments][:hostname].split(".")[0] do
|
@@ -43,7 +45,7 @@ module Itamae
|
|
43
45
|
end
|
44
46
|
rescue Exception => e
|
45
47
|
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
46
|
-
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
48
|
+
puts "nodefile or role error, nodefile:#{node_file}, reason:#{e.message}"
|
47
49
|
else
|
48
50
|
recipes.flatten!
|
49
51
|
end
|
@@ -51,18 +53,19 @@ module Itamae
|
|
51
53
|
# get env attr
|
52
54
|
begin
|
53
55
|
env_set = node_h[:environments][:set]
|
56
|
+
raise "No environments set error" if env_set.nil?
|
54
57
|
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
55
58
|
rescue Exception => e
|
56
59
|
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
57
|
-
puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
|
60
|
+
puts "nodefile or environments error, nodefile:#{node_file}, reason:#{e.message}"
|
58
61
|
end
|
59
62
|
|
60
|
-
# get
|
63
|
+
# get recipes attr
|
61
64
|
recipe_attr_file = []
|
62
65
|
recipes.each do |recipe_h|
|
63
|
-
if recipe_h["#{recipe_h.keys.join}"]
|
66
|
+
if recipe_h["#{recipe_h.keys.join}"] == "default"
|
64
67
|
recipe_attr_file.insert 0,
|
65
|
-
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes
|
68
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
66
69
|
else
|
67
70
|
recipe_attr_file <<
|
68
71
|
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
@@ -71,31 +74,31 @@ module Itamae
|
|
71
74
|
|
72
75
|
recipe_attr_file.flatten!
|
73
76
|
|
74
|
-
#
|
77
|
+
# recipes attr other=env
|
75
78
|
recipe_env_h_a = []
|
76
79
|
recipe_attr_file.each do |file|
|
77
80
|
recipe_h = JSON.parse(File.read(file), symbolize_names: true)
|
78
81
|
recipe_env_h_a << recipe_h.deep_merge(env_h)
|
79
82
|
end
|
80
83
|
|
81
|
-
# recipe attr other=
|
84
|
+
# recipe attr other=recipes_env
|
82
85
|
moto = recipe_env_h_a[0]
|
83
86
|
recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
|
84
87
|
recipe_env_h = moto
|
85
88
|
|
86
89
|
if recipe_env_h.nil?
|
87
|
-
#
|
90
|
+
# env attr other=node
|
88
91
|
node_env_h = env_h.deep_merge(node_h)
|
89
92
|
node_env_j = TaskBase.jq node_env_h
|
90
93
|
TaskBase.write_json(bname) {|file| file.puts node_env_j}
|
91
94
|
else
|
92
|
-
#
|
95
|
+
# recipe_env attr other=node
|
93
96
|
recipe_env_node_h = recipe_env_h.deep_merge(node_h)
|
94
97
|
recipe_env_node_j = TaskBase.jq recipe_env_node_h
|
95
98
|
TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
|
96
99
|
end
|
97
100
|
|
98
|
-
recipes << {'_base' =>
|
101
|
+
recipes << {'_base' => 'default'}
|
99
102
|
node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
|
100
103
|
node = node_property[:environments][:hostname]
|
101
104
|
ssh_user = node_property[:environments][:ssh_user]
|
@@ -120,17 +123,13 @@ module Itamae
|
|
120
123
|
command << " --dry-run" if ENV['dry-run'] == "true"
|
121
124
|
command << " -l debug" if ENV['debug'] == "true"
|
122
125
|
|
123
|
-
|
126
|
+
# recipe load to_command
|
124
127
|
command_recipe = []
|
125
128
|
recipes.each do |recipe_h|
|
126
|
-
|
127
|
-
|
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}"
|
132
|
-
end
|
129
|
+
command_recipe <<
|
130
|
+
" #{Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/recipes/#{recipe_h["#{recipe_h.keys.join}"]}.rb").join("\s")}"
|
133
131
|
end
|
132
|
+
|
134
133
|
command_recipe.sort_by! {|item| File.dirname(item)}
|
135
134
|
command << command_recipe.join
|
136
135
|
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require 'specinfra'
|
2
|
+
require 'json'
|
3
|
+
require 'highline'
|
4
|
+
require 'specinfra/helper/set'
|
5
|
+
require 'itamae-mitsurin/mitsurin/task_base'
|
6
|
+
include Specinfra::Helper::Set
|
7
|
+
include Rake::DSL if defined? Rake::DSL
|
8
|
+
|
9
|
+
module Itamae
|
10
|
+
module Mitsurin
|
11
|
+
class ItamaeTask
|
12
|
+
|
13
|
+
set :backend, :exec
|
14
|
+
|
15
|
+
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(",")}}/**"
|
27
|
+
end
|
28
|
+
|
29
|
+
Dir.glob("nodes/#{branch}/*.json").each do |node_file|
|
30
|
+
|
31
|
+
bname = File.basename(node_file, '.json')
|
32
|
+
node_h = JSON.parse(File.read(node_file), symbolize_names: true)
|
33
|
+
|
34
|
+
desc "Itamae to #{bname}"
|
35
|
+
task node_h[:environments][:hostname].split(".")[0] do
|
36
|
+
begin
|
37
|
+
recipes = []
|
38
|
+
TaskBase.get_roles(node_file).each do |role|
|
39
|
+
recipes << TaskBase.get_recipes(role)
|
40
|
+
end
|
41
|
+
TaskBase.get_node_recipes(node_file).each do |recipe|
|
42
|
+
recipes << recipe
|
43
|
+
end
|
44
|
+
rescue Exception => e
|
45
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
46
|
+
puts "nodefile or role error, nodefile:#{node_file} reason:#{e.message}"
|
47
|
+
else
|
48
|
+
recipes.flatten!
|
49
|
+
end
|
50
|
+
|
51
|
+
# get env attr
|
52
|
+
begin
|
53
|
+
env_set = node_h[:environments][:set]
|
54
|
+
env_h = JSON.parse(File.read("environments/#{env_set}.json"), symbolize_names: true)
|
55
|
+
rescue Exception => e
|
56
|
+
puts e.class.to_s + ", " + e.backtrace[0].to_s
|
57
|
+
puts "nodefile or environments error, nodefile:#{node_file} reason:#{e.message}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# get recipe attr
|
61
|
+
recipe_attr_file = []
|
62
|
+
recipes.each do |recipe_h|
|
63
|
+
if recipe_h["#{recipe_h.keys.join}"].nil?
|
64
|
+
recipe_attr_file.insert 0,
|
65
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/default.json")
|
66
|
+
else
|
67
|
+
recipe_attr_file <<
|
68
|
+
Dir.glob("site-cookbooks/**/#{recipe_h.keys.join}/attributes/#{recipe_h["#{recipe_h.keys.join}"]}.json")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
recipe_attr_file.flatten!
|
73
|
+
|
74
|
+
# recipe attr other=env
|
75
|
+
recipe_env_h_a = []
|
76
|
+
recipe_attr_file.each do |file|
|
77
|
+
recipe_h = JSON.parse(File.read(file), symbolize_names: true)
|
78
|
+
recipe_env_h_a << recipe_h.deep_merge(env_h)
|
79
|
+
end
|
80
|
+
|
81
|
+
# recipe attr other=recipes
|
82
|
+
moto = recipe_env_h_a[0]
|
83
|
+
recipe_env_h_a.each {|hash| moto.deep_merge!(hash)}
|
84
|
+
recipe_env_h = moto
|
85
|
+
|
86
|
+
if recipe_env_h.nil?
|
87
|
+
# node attr other=env
|
88
|
+
node_env_h = env_h.deep_merge(node_h)
|
89
|
+
node_env_j = TaskBase.jq node_env_h
|
90
|
+
TaskBase.write_json(bname) {|file| file.puts node_env_j}
|
91
|
+
else
|
92
|
+
# node attr other=recipe_env
|
93
|
+
recipe_env_node_h = recipe_env_h.deep_merge(node_h)
|
94
|
+
recipe_env_node_j = TaskBase.jq recipe_env_node_h
|
95
|
+
TaskBase.write_json(bname) {|file| file.puts recipe_env_node_j}
|
96
|
+
end
|
97
|
+
|
98
|
+
recipes << {'_base' => nil}
|
99
|
+
node_property = JSON.parse(File.read("tmp-nodes/#{bname}.json"), symbolize_names: true)
|
100
|
+
node = node_property[:environments][:hostname]
|
101
|
+
ssh_user = node_property[:environments][:ssh_user]
|
102
|
+
ssh_password = node_property[:environments][:ssh_password]
|
103
|
+
sudo_password = node_property[:environments][:sudo_password]
|
104
|
+
ssh_port = node_property[:environments][:ssh_port]
|
105
|
+
ssh_key = node_property[:environments][:ssh_key]
|
106
|
+
|
107
|
+
ENV['TARGET_HOST'] = node
|
108
|
+
ENV['NODE_FILE'] = node_file
|
109
|
+
ENV['SSH_PASSWORD'] = ssh_password
|
110
|
+
ENV['SUDO_PASSWORD'] = sudo_password
|
111
|
+
|
112
|
+
command = "bundle exec itamae ssh"
|
113
|
+
command << " -h #{node}"
|
114
|
+
command << " -u #{ssh_user}"
|
115
|
+
command << " -p #{ssh_port}"
|
116
|
+
command << " -i keys/#{ssh_key}" unless ssh_key.nil?
|
117
|
+
command << " -j tmp-nodes/#{bname}.json"
|
118
|
+
command << " --shell=bash"
|
119
|
+
command << " --ask-password" unless ssh_password.nil?
|
120
|
+
command << " --dry-run" if ENV['dry-run'] == "true"
|
121
|
+
command << " -l debug" if ENV['debug'] == "true"
|
122
|
+
|
123
|
+
# recipe load to_command
|
124
|
+
command_recipe = []
|
125
|
+
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}"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
command_recipe.sort_by! {|item| File.dirname(item)}
|
135
|
+
command << command_recipe.join
|
136
|
+
|
137
|
+
puts TaskBase.hl.color(%!Run Itamae to \"#{bname}\"!, :red)
|
138
|
+
run_list_noti = []
|
139
|
+
command_recipe.each {|c_recipe| run_list_noti << c_recipe.split("/") [2]}
|
140
|
+
puts TaskBase.hl.color(%!Run List to \"#{run_list_noti.uniq.join(", ")}\"!, :green)
|
141
|
+
puts TaskBase.hl.color(%!#{command}!, :white)
|
142
|
+
st = system command
|
143
|
+
exit 1 unless st
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.15
|
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.
|
4
|
+
version: '0.15'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akihiro Kamiyama
|
@@ -330,6 +330,7 @@ files:
|
|
330
330
|
- lib/itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/default_spec.rb
|
331
331
|
- lib/itamae-mitsurin/mitsurin/itamae_task.rb
|
332
332
|
- lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb
|
333
|
+
- lib/itamae-mitsurin/mitsurin/itamae_with_git_task_old.rb
|
333
334
|
- lib/itamae-mitsurin/mitsurin/local_task.rb
|
334
335
|
- lib/itamae-mitsurin/mitsurin/serverspec_task.rb
|
335
336
|
- lib/itamae-mitsurin/mitsurin/task_base.rb
|
@@ -559,7 +560,8 @@ rubyforge_project:
|
|
559
560
|
rubygems_version: 2.4.5.1
|
560
561
|
signing_key:
|
561
562
|
specification_version: 4
|
562
|
-
summary: Customized version of Itamae and Itamae plugin
|
563
|
+
summary: Customized version of Itamae and Itamae plugin. configuration management
|
564
|
+
tool like chef. Deploy without the agent. It can be deployed using the AWS Resources.
|
563
565
|
test_files:
|
564
566
|
- spec/integration/Vagrantfile
|
565
567
|
- spec/integration/default_spec.rb
|