tpkg 2.0.1 → 2.1.0
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.
- data/Rakefile +1 -1
- data/bin/tpkg +28 -23
- data/lib/tpkg.rb +243 -233
- data/lib/tpkg/deployer.rb +37 -32
- metadata +2 -2
data/lib/tpkg/deployer.rb
CHANGED
@@ -37,15 +37,15 @@ class Deployer
|
|
37
37
|
@ssh_key = options["ssh-key"]
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def prompt_username
|
42
42
|
ask("Username: ")
|
43
|
-
end
|
44
|
-
|
43
|
+
end
|
44
|
+
|
45
45
|
def prompt_password
|
46
|
-
ask("SSH Password (leave blank if using ssh key): ", true)
|
46
|
+
ask("SSH Password (leave blank if using ssh key): ", true)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def ask(str,mask=false)
|
50
50
|
begin
|
51
51
|
system 'stty -echo;' if mask
|
@@ -53,20 +53,20 @@ class Deployer
|
|
53
53
|
input = STDIN.gets.chomp
|
54
54
|
ensure
|
55
55
|
system 'stty echo; echo ""'
|
56
|
-
end
|
56
|
+
end
|
57
57
|
return input
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def get_sudo_pw
|
61
61
|
@mutex.synchronize {
|
62
62
|
if @sudo_pw.nil?
|
63
63
|
@sudo_pw = ask("Sudo password: ", true)
|
64
64
|
else
|
65
65
|
return @sudo_pw
|
66
|
-
end
|
66
|
+
end
|
67
67
|
}
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# Prompt user for input and cache it. If in the future, we see
|
71
71
|
# the same prompt again, we can reuse the existing inputs. This saves
|
72
72
|
# the users from having to type in a bunch of inputs (such as password)
|
@@ -78,13 +78,13 @@ class Deployer
|
|
78
78
|
return @pw_prompts[prompt]
|
79
79
|
}
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# Return a block that can be used for executing a cmd on the remote server
|
83
83
|
def ssh_execute(server, username, password, key, cmd)
|
84
|
-
return lambda {
|
84
|
+
return lambda {
|
85
85
|
exit_status = 0
|
86
86
|
result = []
|
87
|
-
|
87
|
+
|
88
88
|
params = {}
|
89
89
|
params[:password] = password if password
|
90
90
|
params[:keys] = [key] if key
|
@@ -96,11 +96,11 @@ class Deployer
|
|
96
96
|
# now we request a "pty" (i.e. interactive) session so we can send data
|
97
97
|
# back and forth if needed. it WILL NOT WORK without this, and it has to
|
98
98
|
# be done before any call to exec.
|
99
|
-
|
99
|
+
|
100
100
|
channel.request_pty do |ch, success|
|
101
101
|
raise "Could not obtain pty (i.e. an interactive ssh session)" if !success
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
channel.exec(cmd) do |ch, success|
|
105
105
|
puts "Executing #{cmd} on #{server}"
|
106
106
|
# 'success' isn't related to bash exit codes or anything, but more
|
@@ -108,7 +108,7 @@ class Deployer
|
|
108
108
|
# not sure why it would fail at such a basic level, but it seems smart
|
109
109
|
# to do something about it.
|
110
110
|
abort "could not execute command" unless success
|
111
|
-
|
111
|
+
|
112
112
|
# on_data is a hook that fires when the loop that this block is fired
|
113
113
|
# in (see below) returns data. This is what we've been doing all this
|
114
114
|
# for; now we can check to see if it's a password prompt, and
|
@@ -117,7 +117,7 @@ class Deployer
|
|
117
117
|
if data =~ /Password:/
|
118
118
|
password = get_sudo_pw unless !password.nil? && password != ""
|
119
119
|
channel.send_data "#{password}\n"
|
120
|
-
elsif data =~ /password/i or data =~ /passphrase/i or
|
120
|
+
elsif data =~ /password/i or data =~ /passphrase/i or
|
121
121
|
data =~ /pass phrase/i or data =~ /incorrect passphrase/i
|
122
122
|
input = get_input_for_pw_prompt(data)
|
123
123
|
channel.send_data "#{input}\n"
|
@@ -125,25 +125,24 @@ class Deployer
|
|
125
125
|
result << data unless data.nil? or data.empty?
|
126
126
|
end
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
channel.on_extended_data do |ch, type, data|
|
130
130
|
print "SSH command returned on stderr: #{data}"
|
131
131
|
end
|
132
|
-
|
133
|
-
channel.on_request "exit-status" do |ch, data|
|
132
|
+
|
133
|
+
channel.on_request "exit-status" do |ch, data|
|
134
134
|
exit_status = data.read_long
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end
|
138
138
|
ch.wait
|
139
139
|
ssh.loop
|
140
|
-
end
|
140
|
+
end
|
141
141
|
if $debug
|
142
|
-
puts "==================================================\nResult from #{server}:"
|
143
|
-
puts result.join
|
142
|
+
puts "==================================================\nResult from #{server}:"
|
143
|
+
puts result.join
|
144
144
|
puts "=================================================="
|
145
145
|
end
|
146
|
-
|
147
146
|
rescue Net::SSH::AuthenticationFailed
|
148
147
|
exit_status = 1
|
149
148
|
puts "Bad username/password combination"
|
@@ -153,28 +152,33 @@ class Deployer
|
|
153
152
|
puts e.backtrace
|
154
153
|
puts "Can't connect to server"
|
155
154
|
end
|
156
|
-
|
155
|
+
|
157
156
|
return exit_status
|
158
157
|
}
|
159
158
|
end
|
160
|
-
|
159
|
+
|
161
160
|
# deploy_params is an array that holds the list of paramters that is used when invoking tpkg on to the remote
|
162
|
-
# servers where we want to deploy to.
|
161
|
+
# servers where we want to deploy to.
|
163
162
|
#
|
164
163
|
# servers is an array, a filename or a callback that list the remote servers where we want to deploy to
|
165
164
|
def deploy(deploy_params, servers)
|
166
|
-
params = deploy_params.join(" ")
|
167
|
-
cmd =
|
165
|
+
params = deploy_params.join(" ")
|
166
|
+
cmd = nil
|
167
|
+
if ENV['TPKG_HOME']
|
168
|
+
cmd = "env TPKG_HOME=#{ENV['TPKG_HOME']} tpkg #{params} -n"
|
169
|
+
else
|
170
|
+
cmd = "tpkg #{params} -n"
|
171
|
+
end
|
168
172
|
user = @user
|
169
|
-
|
173
|
+
|
170
174
|
if @user.nil? && !@use_ssh_key
|
171
175
|
@user = prompt_username
|
172
176
|
end
|
173
|
-
|
177
|
+
|
174
178
|
if @password.nil? && !@use_ssh_key
|
175
179
|
@password = prompt_password
|
176
180
|
end
|
177
|
-
|
181
|
+
|
178
182
|
tp = ThreadPool.new(@max_worker)
|
179
183
|
statuses = {}
|
180
184
|
deploy_to = []
|
@@ -191,7 +195,7 @@ class Deployer
|
|
191
195
|
else
|
192
196
|
deploy_to = servers
|
193
197
|
end
|
194
|
-
|
198
|
+
|
195
199
|
deploy_to.each do | server |
|
196
200
|
tp.process do
|
197
201
|
status = ssh_execute(server, @user, @password, @ssh_key, cmd).call
|
@@ -205,3 +209,4 @@ class Deployer
|
|
205
209
|
return statuses
|
206
210
|
end
|
207
211
|
end
|
212
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tpkg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darren Dao
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-
|
13
|
+
date: 2010-12-17 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|