itamae-mitsurin 0.50 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/itamae-mitsurin/cli.rb +0 -2
- data/lib/itamae-mitsurin/logger.rb +74 -20
- data/lib/itamae-mitsurin/mitsurin/base.rb +109 -0
- data/lib/itamae-mitsurin/mitsurin/base_task.rb +147 -0
- data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -11
- data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +44 -130
- data/lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb +64 -157
- data/lib/itamae-mitsurin/mitsurin/local_task.rb +57 -131
- data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +56 -81
- data/lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb +80 -143
- data/lib/itamae-mitsurin/node.rb +0 -1
- data/lib/itamae-mitsurin/notification.rb +0 -1
- data/lib/itamae-mitsurin/recipe.rb +2 -5
- data/lib/itamae-mitsurin/resource.rb +1 -1
- data/lib/itamae-mitsurin/resource/base.rb +0 -12
- data/lib/itamae-mitsurin/resource/http_request.rb +23 -8
- data/lib/itamae-mitsurin/resource/s3_file.rb +33 -0
- data/lib/itamae-mitsurin/runner.rb +4 -5
- data/lib/itamae-mitsurin/version.txt +1 -1
- metadata +6 -221
- data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +0 -159
- data/lib/itamae-mitsurin/mitsurin/task_base.rb +0 -100
- data/test/test_itamae-mitsurin.rb +0 -18
- data/test/test_itamae-mitsurin/ext/test_specinfra.rb +0 -39
- data/test/test_itamae-mitsurin/handler/test_base.rb +0 -40
- data/test/test_itamae-mitsurin/handler/test_debug.rb +0 -10
- data/test/test_itamae-mitsurin/handler/test_fluentd.rb +0 -44
- data/test/test_itamae-mitsurin/handler/test_json.rb +0 -22
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +0 -2
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +0 -3
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +0 -2
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +0 -7
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +0 -9
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
- data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
- 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 +0 -33
- 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/test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb +0 -24
- data/test/test_itamae-mitsurin/mitsurin/creators/test_project.rb +0 -24
- data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +0 -56
- data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +0 -19
- data/test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb +0 -197
- data/test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb +0 -213
- data/test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb +0 -123
- data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +0 -84
- data/test/test_itamae-mitsurin/resource/test_base.rb +0 -374
- data/test/test_itamae-mitsurin/resource/test_directory.rb +0 -63
- data/test/test_itamae-mitsurin/resource/test_execute.rb +0 -26
- data/test/test_itamae-mitsurin/resource/test_file.rb +0 -176
- data/test/test_itamae-mitsurin/resource/test_gem_package.rb +0 -81
- data/test/test_itamae-mitsurin/resource/test_git.rb +0 -94
- data/test/test_itamae-mitsurin/resource/test_group.rb +0 -42
- data/test/test_itamae-mitsurin/resource/test_http_request.rb +0 -71
- data/test/test_itamae-mitsurin/resource/test_link.rb +0 -33
- data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +0 -15
- data/test/test_itamae-mitsurin/resource/test_package.rb +0 -44
- data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +0 -84
- data/test/test_itamae-mitsurin/resource/test_remote_file.rb +0 -54
- data/test/test_itamae-mitsurin/resource/test_service.rb +0 -69
- data/test/test_itamae-mitsurin/resource/test_template.rb +0 -53
- data/test/test_itamae-mitsurin/resource/test_user.rb +0 -93
- data/test/test_itamae-mitsurin/test_backend.rb +0 -297
- data/test/test_itamae-mitsurin/test_cli.rb +0 -88
- data/test/test_itamae-mitsurin/test_definition.rb +0 -40
- data/test/test_itamae-mitsurin/test_ext.rb +0 -1
- data/test/test_itamae-mitsurin/test_handler.rb +0 -21
- data/test/test_itamae-mitsurin/test_handler_proxy.rb +0 -38
- data/test/test_itamae-mitsurin/test_logger.rb +0 -124
- data/test/test_itamae-mitsurin/test_mitsurin.rb +0 -14
- data/test/test_itamae-mitsurin/test_node.rb +0 -74
- data/test/test_itamae-mitsurin/test_notification.rb +0 -46
- data/test/test_itamae-mitsurin/test_recipe.rb +0 -171
- data/test/test_itamae-mitsurin/test_recipe_children.rb +0 -86
- data/test/test_itamae-mitsurin/test_resource.rb +0 -73
- data/test/test_itamae-mitsurin/test_runner.rb +0 -124
- data/test/test_itamae-mitsurin/test_version.rb +0 -3
- data/test/test_itamae-mitsurin/version.txt +0 -1
- data/test_project/.rspec +0 -2
- data/test_project/Gemfile +0 -4
- data/test_project/Rakefile +0 -3
- 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 +0 -9
- data/test_project/roles/.keep +0 -0
- data/test_project/roles/test.json +0 -14
- 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 +0 -1
- data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
- 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 +0 -8
- data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +0 -4
- 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 +0 -2
- data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +0 -4
- 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 +0 -5
- data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
- data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +0 -6
- 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 +0 -5
- data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +0 -5
- 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 +0 -5
- data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +0 -5
- 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 +0 -1
- data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +0 -9
- 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 +0 -7
- 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 +0 -5
- data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +0 -7
- data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
- data/test_project/site-cookbooks/b_test/template/templates/template.erb +0 -2
- 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 +0 -6
- data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
- data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +0 -6
- 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 +0 -10
- 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 +0 -20
- 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 +0 -33
- data/test_project/tmp-nodes/.keep +0 -0
- data/test_project/tmp-nodes/test.json +0 -12
@@ -1,297 +0,0 @@
|
|
1
|
-
require 'specinfra/core'
|
2
|
-
require 'singleton'
|
3
|
-
require 'io/console'
|
4
|
-
require 'net/ssh'
|
5
|
-
|
6
|
-
Specinfra::Configuration.error_on_missing_backend_type = true
|
7
|
-
|
8
|
-
module Specinfra
|
9
|
-
module Configuration
|
10
|
-
def self.sudo_password
|
11
|
-
return ENV['SUDO_PASSWORD'] if ENV['SUDO_PASSWORD']
|
12
|
-
return @sudo_password if @sudo_password
|
13
|
-
|
14
|
-
# TODO: Fix this dirty hack
|
15
|
-
return nil unless caller.any? {|call| call.include?('channel_data') }
|
16
|
-
|
17
|
-
print "sudo password: "
|
18
|
-
@sudo_password = STDIN.noecho(&:gets).strip
|
19
|
-
print "\n"
|
20
|
-
@sudo_password
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module TestItamaeMitsurin
|
26
|
-
module TestBackend
|
27
|
-
UnknownBackendTypeError = Class.new(StandardError)
|
28
|
-
CommandExecutionError = Class.new(StandardError)
|
29
|
-
SourceNotExistError = Class.new(StandardError)
|
30
|
-
|
31
|
-
class << self
|
32
|
-
def create(type, opts = {})
|
33
|
-
self.const_get(type.capitalize).new(opts)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Base < Test::Unit::TestCase
|
38
|
-
attr_reader :executed_commands
|
39
|
-
|
40
|
-
def initialize(options)
|
41
|
-
@options = options
|
42
|
-
@backend = create_specinfra_backend
|
43
|
-
@executed_commands = []
|
44
|
-
end
|
45
|
-
|
46
|
-
def run_command(commands, options = {})
|
47
|
-
options = {error: true}.merge(options)
|
48
|
-
|
49
|
-
command = build_command(commands, options)
|
50
|
-
TestItamaeMitsurin.logger.debug "Executing `#{command}`..."
|
51
|
-
|
52
|
-
result = nil
|
53
|
-
|
54
|
-
TestItamaeMitsurin.logger.with_indent do
|
55
|
-
reset_output_handler
|
56
|
-
|
57
|
-
result = run_command_with_profiling(command)
|
58
|
-
|
59
|
-
flush_output_handler_buffer
|
60
|
-
|
61
|
-
if result.exit_status == 0 || !options[:error]
|
62
|
-
method = :debug
|
63
|
-
message = "exited with #{result.exit_status}"
|
64
|
-
else
|
65
|
-
method = :error
|
66
|
-
message = "Command `#{command}` failed. (exit status: #{result.exit_status})"
|
67
|
-
|
68
|
-
unless TestItamaeMitsurin.logger.level == ::Logger::DEBUG
|
69
|
-
result.stdout.each_line do |l|
|
70
|
-
log_output_line("stdout", l, :error)
|
71
|
-
end
|
72
|
-
result.stderr.each_line do |l|
|
73
|
-
log_output_line("stderr", l, :error)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
TestItamaeMitsurin.logger.public_send(method, message)
|
79
|
-
end
|
80
|
-
|
81
|
-
if options[:error] && result.exit_status != 0
|
82
|
-
raise CommandExecutionError
|
83
|
-
end
|
84
|
-
|
85
|
-
result
|
86
|
-
end
|
87
|
-
|
88
|
-
def get_command(*args)
|
89
|
-
@backend.command.get(*args)
|
90
|
-
end
|
91
|
-
|
92
|
-
def receive_file(src, dst = nil)
|
93
|
-
if dst
|
94
|
-
TestItamaeMitsurin.logger.debug "Receiving a file from '#{src}' to '#{dst}'..."
|
95
|
-
else
|
96
|
-
TestItamaeMitsurin.logger.debug "Receiving a file from '#{src}'..."
|
97
|
-
end
|
98
|
-
@backend.receive_file(src, dst)
|
99
|
-
end
|
100
|
-
|
101
|
-
def send_file(src, dst)
|
102
|
-
TestItamaeMitsurin.logger.debug "Sending a file from '#{src}' to '#{dst}'..."
|
103
|
-
unless ::File.exist?(src)
|
104
|
-
raise SourceNotExistError, "The file '#{src}' doesn't exist."
|
105
|
-
end
|
106
|
-
unless ::File.file?(src)
|
107
|
-
raise SourceNotExistError, "'#{src}' is not a file."
|
108
|
-
end
|
109
|
-
@backend.send_file(src, dst)
|
110
|
-
end
|
111
|
-
|
112
|
-
def send_directory(src, dst)
|
113
|
-
TestItamaeMitsurin.logger.debug "Sending a directory from '#{src}' to '#{dst}'..."
|
114
|
-
unless ::File.exist?(src)
|
115
|
-
raise SourceNotExistError, "The directory '#{src}' doesn't exist."
|
116
|
-
end
|
117
|
-
unless ::File.directory?(src)
|
118
|
-
raise SourceNotExistError, "'#{src}' is not a directory."
|
119
|
-
end
|
120
|
-
@backend.send_directory(src, dst)
|
121
|
-
end
|
122
|
-
|
123
|
-
def host_inventory
|
124
|
-
@backend.host_inventory
|
125
|
-
end
|
126
|
-
|
127
|
-
def finalize
|
128
|
-
# pass
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def create_specinfra_backend
|
134
|
-
raise NotImplementedError
|
135
|
-
end
|
136
|
-
|
137
|
-
def reset_output_handler
|
138
|
-
@buf = {}
|
139
|
-
%w!stdout stderr!.each do |output_name|
|
140
|
-
@buf[output_name] = ""
|
141
|
-
handler = lambda do |str|
|
142
|
-
lines = str.split(/\r?\n/, -1)
|
143
|
-
@buf[output_name] += lines.pop
|
144
|
-
unless lines.empty?
|
145
|
-
lines[0] = @buf[output_name] + lines[0]
|
146
|
-
@buf[output_name] = ""
|
147
|
-
lines.each do |l|
|
148
|
-
log_output_line(output_name, l)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
@backend.public_send("#{output_name}_handler=", handler)
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
def flush_output_handler_buffer
|
157
|
-
@buf.each do |output_name, line|
|
158
|
-
next if line.empty?
|
159
|
-
log_output_line(output_name, line)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def log_output_line(output_name, line, severity = :debug)
|
164
|
-
line = line.gsub(/[[:cntrl:]]/, '')
|
165
|
-
TestItamaeMitsurin.logger.public_send(severity, "#{output_name} | #{line}")
|
166
|
-
end
|
167
|
-
|
168
|
-
def build_command(commands, options)
|
169
|
-
if commands.is_a?(Array)
|
170
|
-
command = commands.map do |cmd|
|
171
|
-
cmd.shellescape
|
172
|
-
end.join(' ')
|
173
|
-
else
|
174
|
-
command = commands
|
175
|
-
end
|
176
|
-
|
177
|
-
cwd = options[:cwd]
|
178
|
-
if cwd
|
179
|
-
command = "cd #{cwd.shellescape} && #{command}"
|
180
|
-
end
|
181
|
-
|
182
|
-
user = options[:user]
|
183
|
-
if user
|
184
|
-
command = "cd ~#{user.shellescape} ; #{command}"
|
185
|
-
command = "sudo -H -u #{user.shellescape} -- #{shell.shellescape} -c #{command.shellescape}"
|
186
|
-
end
|
187
|
-
|
188
|
-
command
|
189
|
-
end
|
190
|
-
|
191
|
-
def shell
|
192
|
-
@options[:shell] || '/bin/sh'
|
193
|
-
end
|
194
|
-
|
195
|
-
def run_command_with_profiling(command)
|
196
|
-
start_at = Time.now
|
197
|
-
result = @backend.run_command(command)
|
198
|
-
duration = Time.now.to_f - start_at.to_f
|
199
|
-
|
200
|
-
@executed_commands << {command: command, duration: duration}
|
201
|
-
|
202
|
-
result
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
class Local < Base
|
207
|
-
private
|
208
|
-
def create_specinfra_backend
|
209
|
-
Specinfra::Backend::Exec.new(
|
210
|
-
shell: @options[:shell],
|
211
|
-
)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
class Ssh < Base
|
216
|
-
private
|
217
|
-
def create_specinfra_backend
|
218
|
-
Specinfra::Backend::Ssh.new(
|
219
|
-
request_pty: true,
|
220
|
-
host: ssh_options[:host_name],
|
221
|
-
disable_sudo: disable_sudo?,
|
222
|
-
ssh_options: ssh_options,
|
223
|
-
shell: @options[:shell],
|
224
|
-
)
|
225
|
-
end
|
226
|
-
|
227
|
-
def ssh_options
|
228
|
-
opts = {}
|
229
|
-
|
230
|
-
opts[:host_name] = @options[:host]
|
231
|
-
|
232
|
-
# from ssh-config
|
233
|
-
opts.merge!(Net::SSH::Config.for(@options[:host]))
|
234
|
-
opts[:user] = @options[:user] || opts[:user] || Etc.getlogin
|
235
|
-
opts[:keys] = [@options[:key]] if @options[:key]
|
236
|
-
opts[:port] = @options[:port] if @options[:port]
|
237
|
-
|
238
|
-
if @options[:vagrant]
|
239
|
-
config = Tempfile.new('', Dir.tmpdir)
|
240
|
-
hostname = opts[:host_name] || 'default'
|
241
|
-
vagrant_cmd = "vagrant ssh-config #{hostname} > #{config.path}"
|
242
|
-
if defined?(Bundler)
|
243
|
-
Bundler.with_clean_env do
|
244
|
-
`#{vagrant_cmd}`
|
245
|
-
end
|
246
|
-
else
|
247
|
-
`#{vagrant_cmd}`
|
248
|
-
end
|
249
|
-
opts.merge!(Net::SSH::Config.for(hostname, [config.path]))
|
250
|
-
end
|
251
|
-
|
252
|
-
if @options[:ask_password]
|
253
|
-
print "password: "
|
254
|
-
unless ENV['SSH_PASSWORD'].nil?
|
255
|
-
password = ENV['SSH_PASSWORD']
|
256
|
-
else
|
257
|
-
password = STDIN.noecho(&:gets).strip
|
258
|
-
end
|
259
|
-
print "\n"
|
260
|
-
opts.merge!(password: password)
|
261
|
-
end
|
262
|
-
|
263
|
-
opts
|
264
|
-
end
|
265
|
-
|
266
|
-
def disable_sudo?
|
267
|
-
!@options[:sudo]
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
class Docker < Base
|
272
|
-
def finalize
|
273
|
-
image = @backend.commit_container
|
274
|
-
TestItamaeMitsurin.logger.info "Image created: #{image.id}"
|
275
|
-
end
|
276
|
-
|
277
|
-
private
|
278
|
-
def create_specinfra_backend
|
279
|
-
begin
|
280
|
-
require 'docker'
|
281
|
-
rescue LoadError
|
282
|
-
TestItamaeMitsurin.logger.fatal "To use docker backend, please install 'docker-api' gem"
|
283
|
-
end
|
284
|
-
|
285
|
-
# TODO: Move to Specinfra?
|
286
|
-
Excon.defaults[:ssl_verify_peer] = @options[:tls_verify_peer]
|
287
|
-
::Docker.logger = TestItamaeMitsurin.logger
|
288
|
-
|
289
|
-
Specinfra::Backend::Docker.new(
|
290
|
-
docker_image: @options[:image],
|
291
|
-
docker_container: @options[:container],
|
292
|
-
shell: @options[:shell],
|
293
|
-
)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
end
|
297
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'itamae-mitsurin'
|
2
|
-
require 'thor'
|
3
|
-
require 'test/unit'
|
4
|
-
include Test::Unit::TestCase
|
5
|
-
|
6
|
-
module TestItamaeMitsurin
|
7
|
-
class TestCLI < Thor
|
8
|
-
|
9
|
-
class_option :log_level, type: :string, aliases: ['-l'], default: 'info'
|
10
|
-
class_option :color, type: :boolean, default: true
|
11
|
-
class_option :config, type: :string, aliases: ['-c']
|
12
|
-
|
13
|
-
def initialize(*)
|
14
|
-
super
|
15
|
-
|
16
|
-
ItamaeMitsurin.logger.level = ::Logger.const_get(options[:log_level].upcase)
|
17
|
-
ItamaeMitsurin.logger.formatter.colored = options[:color]
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.define_exec_options
|
21
|
-
option :recipe_graph, type: :string, desc: "[EXPERIMENTAL] Write recipe dependency graph in DOT", banner: "PATH"
|
22
|
-
option :node_json, type: :string, aliases: ['-j']
|
23
|
-
option :node_yaml, type: :string, aliases: ['-y']
|
24
|
-
option :dry_run, type: :boolean, aliases: ['-n']
|
25
|
-
option :shell, type: :string, default: "/bin/sh"
|
26
|
-
option :ohai, type: :boolean, default: false, desc: "This option is DEPRECATED and will be unavailable."
|
27
|
-
option :profile, type: :string, desc: "[EXPERIMENTAL] Save profiling data", banner: "PATH"
|
28
|
-
end
|
29
|
-
|
30
|
-
desc "local RECIPE [RECIPE...]", "Run Itamae locally"
|
31
|
-
define_exec_options
|
32
|
-
def local(*recipe_files)
|
33
|
-
if recipe_files.empty?
|
34
|
-
raise "Please specify recipe files."
|
35
|
-
end
|
36
|
-
|
37
|
-
Runner.run(recipe_files, :local, options)
|
38
|
-
end
|
39
|
-
|
40
|
-
desc "ssh RECIPE [RECIPE...]", "Run Itamae via ssh"
|
41
|
-
define_exec_options
|
42
|
-
option :host, type: :string, aliases: ['-h']
|
43
|
-
option :user, type: :string, aliases: ['-u']
|
44
|
-
option :key, type: :string, aliases: ['-i']
|
45
|
-
option :port, type: :numeric, aliases: ['-p']
|
46
|
-
option :vagrant, type: :boolean, default: false
|
47
|
-
option :ask_password, type: :boolean, default: false
|
48
|
-
option :sudo, type: :boolean, default: true
|
49
|
-
def ssh(*recipe_files)
|
50
|
-
if recipe_files.empty?
|
51
|
-
raise "Please specify recipe files."
|
52
|
-
end
|
53
|
-
|
54
|
-
unless options[:host] || options[:vagrant]
|
55
|
-
raise "Please set '-h <hostname>' or '--vagrant'"
|
56
|
-
end
|
57
|
-
|
58
|
-
Runner.run(recipe_files, :ssh, options)
|
59
|
-
end
|
60
|
-
|
61
|
-
desc "docker RECIPE [RECIPE...]", "Create Docker image"
|
62
|
-
define_exec_options
|
63
|
-
option :image, type: :string, desc: "This option or 'container' option is required."
|
64
|
-
option :container, type: :string, desc: "This option or 'image' option is required."
|
65
|
-
option :tls_verify_peer, type: :boolean, default: true
|
66
|
-
def docker(*recipe_files)
|
67
|
-
if recipe_files.empty?
|
68
|
-
raise "Please specify recipe files."
|
69
|
-
end
|
70
|
-
|
71
|
-
Runner.run(recipe_files, :docker, options)
|
72
|
-
end
|
73
|
-
|
74
|
-
desc "version", "Print version"
|
75
|
-
def version
|
76
|
-
puts "itamae-mitsurin v#{ItamaeMitsurin::VERSION}"
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
def options
|
81
|
-
@itamae_options ||= super.dup.tap do |options|
|
82
|
-
if config = options[:config]
|
83
|
-
options.merge!(YAML.load_file(config))
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'itamae-mitsurin'
|
2
|
-
|
3
|
-
module ItamaeMitsurin
|
4
|
-
class Definition < Resource::Base
|
5
|
-
class << self
|
6
|
-
attr_accessor :definition_block
|
7
|
-
attr_accessor :defined_in_recipe
|
8
|
-
|
9
|
-
def create_class(name, params, defined_in_recipe, &block)
|
10
|
-
Class.new(self).tap do |klass|
|
11
|
-
klass.definition_block = block
|
12
|
-
klass.defined_in_recipe = defined_in_recipe
|
13
|
-
|
14
|
-
klass.define_attribute :action, default: :run
|
15
|
-
params.each_pair do |key, value|
|
16
|
-
klass.define_attribute key.to_sym, type: Object, default: value
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(*args)
|
23
|
-
super
|
24
|
-
|
25
|
-
r = Recipe::RecipeFromDefinition.new(
|
26
|
-
runner,
|
27
|
-
self.class.defined_in_recipe.path,
|
28
|
-
)
|
29
|
-
recipe.children << r
|
30
|
-
|
31
|
-
r.definition = self
|
32
|
-
r.load(params: @attributes.merge(name: resource_name))
|
33
|
-
end
|
34
|
-
|
35
|
-
def run(*args)
|
36
|
-
# nothing
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'itamae-mitsurin/ext/specinfra'
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'itamae-mitsurin/handler/base'
|
2
|
-
|
3
|
-
module ItamaeMitsurin
|
4
|
-
module Handler
|
5
|
-
def self.from_type(type)
|
6
|
-
first_time = true
|
7
|
-
|
8
|
-
class_name = type.split('_').map(&:capitalize).join
|
9
|
-
self.const_get(class_name)
|
10
|
-
rescue NameError
|
11
|
-
require "itamae-mitsurin/handler/#{type}"
|
12
|
-
|
13
|
-
if first_time
|
14
|
-
first_time = false
|
15
|
-
retry
|
16
|
-
else
|
17
|
-
raise
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|