torquebox-remote-deployer 0.1.2.pre2-java
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +80 -0
- data/lib/torquebox/rake/tasks/remote.rb +47 -0
- data/lib/torquebox/remote_deploy_utils.rb +244 -0
- data/lib/torquebox-remote-deployer.rb +1 -0
- data/spec/fixtures/local_torquebox_remote.rb +5 -0
- data/spec/fixtures/multihost_torquebox_remote.rb +18 -0
- data/spec/fixtures/myapp.knob +1 -0
- data/spec/fixtures/simple_torquebox_remote.rb +9 -0
- data/spec/remote_deploy_spec.rb +138 -0
- data/spec/remote_deploy_utils_spec.rb +58 -0
- data/spec/spec_helper.rb +5 -0
- data/torquebox-remote-deployer.gemspec +28 -0
- metadata +140 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#--
|
2
|
+
# The MIT License
|
3
|
+
#
|
4
|
+
# Copyright (c) 2007-2008 Sun Microsystems, Inc.
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
14
|
+
# all copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
# THE SOFTWARE.
|
23
|
+
#++
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# torquebox-remote-deployer
|
2
|
+
|
3
|
+
The torquebox-remote-deployer is a Ruby Gem for deploying TorqueBox `.knob` files to a remote TorqueBox server. It
|
4
|
+
allows you to deploy your entire application as a single file, but still be able to run Rake and other jobs on the
|
5
|
+
server.
|
6
|
+
|
7
|
+
## How to Use It
|
8
|
+
|
9
|
+
First, you'll need to set up your TorqueBox application for Rake.
|
10
|
+
Then run `gem install torquebox-remote-deployer` or add the gem to your `Gemfile`:
|
11
|
+
|
12
|
+
gem "torquebox-remote-deployer"
|
13
|
+
|
14
|
+
Once the Gem is installed, you'll have a few new Rake tasks:
|
15
|
+
|
16
|
+
rake torquebox:remote:deploy # Deploy the local archive file t...
|
17
|
+
rake torquebox:remote:exec[cmd] # Execute Ruby commands against t...
|
18
|
+
rake torquebox:remote:stage # Upload this application to the ...
|
19
|
+
rake torquebox:remote:stage:check # Verify that the archive file ma...
|
20
|
+
rake torquebox:remote:stage:deploy # Deploy the staged archive file ...
|
21
|
+
rake torquebox:remote:undeploy # Undeploy the archive file to th...
|
22
|
+
|
23
|
+
Before using these, you'll need to configure your remote server by creating a `config/torquebox_remote.rb` file in your project.
|
24
|
+
This file will be similar to `config/torquebox.rb` in its format, but the directives are different.
|
25
|
+
You'll need to configure it like this:
|
26
|
+
|
27
|
+
TorqueBox::RemoteDeploy.configure do
|
28
|
+
torquebox_home "/opt/torquebox"
|
29
|
+
hostname "localhost"
|
30
|
+
port "2222"
|
31
|
+
user "vagrant"
|
32
|
+
key "~/.vagrant.d/insecure_private_key"
|
33
|
+
sudo true
|
34
|
+
end
|
35
|
+
|
36
|
+
Of course, fill in the values with your own server information.
|
37
|
+
Then you can stage your application on the remote server with this command:
|
38
|
+
|
39
|
+
$ rake torquebox:remote:stage
|
40
|
+
|
41
|
+
This will create a Knob file, copy it to the remote server, and explode it to a location where commands can be run from
|
42
|
+
its root directory; like this:
|
43
|
+
|
44
|
+
$ rake torquebox:remote:exec["bundle install --path vendor/bundle"]
|
45
|
+
|
46
|
+
Or if you ran `bundle --deployment` before creating your Knob you can just jump right in and run something more useful like your migrations:
|
47
|
+
|
48
|
+
$ rake torquebox:remote:exec["bundle exec rake db:migrate"]
|
49
|
+
|
50
|
+
After the `exec` tasks are complete, you can deploy the Knob to the TorqueBox server.
|
51
|
+
|
52
|
+
$ rake torquebox:remote:deploy
|
53
|
+
|
54
|
+
This task works just like the `torquebox:deploy:archive` task, but remotely.
|
55
|
+
|
56
|
+
## Deploying to Multiple Environments
|
57
|
+
|
58
|
+
The `torquebox-remote-deployer` gem defaults to production mode, so all the examples shown above will execute with your `production` Bundler group and db config. But it's most likely that you will want to deploy to a staging or test environment before deploying to production. In that case, you'll need a config file for each one. In each config file, you can specify the RACK_ENV or RAILS_ENV like this:
|
59
|
+
|
60
|
+
TorqueBox::RemoteDeploy.configure do
|
61
|
+
torquebox_home "/opt/torquebox"
|
62
|
+
hostname "localhost"
|
63
|
+
port "2222"
|
64
|
+
user "vagrant"
|
65
|
+
key "~/.vagrant.d/insecure_private_key"
|
66
|
+
|
67
|
+
# set the RAILS_ENV on the remote server
|
68
|
+
rails_env "test"
|
69
|
+
end
|
70
|
+
|
71
|
+
Then you can deploy with the `TB_REMOTE_FILE` environment variable set like this:
|
72
|
+
|
73
|
+
$ TB_REMOTE_FILE=config/torquebox_remote.test.rb rake torquebox:remote:stage
|
74
|
+
|
75
|
+
You can name the config file whatever you'd like, and you can have one per environment -- but use the same Rake tasks.
|
76
|
+
|
77
|
+
## TODO
|
78
|
+
|
79
|
+
* Make it friendly to remote Windows targets (already works on Windows source machines).
|
80
|
+
* Support deploying over FTP or SFTP in addition to SCP/SSH.
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'torquebox/deploy_utils'
|
3
|
+
require 'torquebox/remote_deploy_utils'
|
4
|
+
|
5
|
+
namespace :torquebox do
|
6
|
+
namespace :remote do
|
7
|
+
|
8
|
+
desc "Upload this application to the remote server as an archive file"
|
9
|
+
task :stage => ["torquebox:archive"] do
|
10
|
+
archive_name = TorqueBox::DeployUtils.archive_name
|
11
|
+
TorqueBox::RemoteDeployUtils.stage(archive_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
desc "Execute Ruby commands against the staged archive file"
|
15
|
+
task :exec, [:cmd] do |t, args|
|
16
|
+
cmd = args[:cmd]
|
17
|
+
archive_name = TorqueBox::DeployUtils.archive_name
|
18
|
+
TorqueBox::RemoteDeployUtils.exec_ruby(archive_name, cmd)
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Deploy the local archive file to the remote TorqueBox server"
|
22
|
+
task :deploy do
|
23
|
+
archive_name = TorqueBox::DeployUtils.archive_name
|
24
|
+
TorqueBox::RemoteDeployUtils.deploy(archive_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace :stage do
|
28
|
+
desc "Deploy the staged archive file to the remote TorqueBox server"
|
29
|
+
task :deploy do
|
30
|
+
archive_name = TorqueBox::DeployUtils.archive_name
|
31
|
+
TorqueBox::RemoteDeployUtils.deploy_from_stage(archive_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Verify that the archive file made it here intact"
|
35
|
+
task :check do
|
36
|
+
archive_name = TorqueBox::DeployUtils.archive_name
|
37
|
+
# TODO: checksum local and on server
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Undeploy the archive file to the remote TorqueBox server"
|
42
|
+
task :undeploy do
|
43
|
+
archive_name = TorqueBox::DeployUtils.archive_name
|
44
|
+
TorqueBox::RemoteDeployUtils.undeploy(archive_name)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,244 @@
|
|
1
|
+
require "net/ssh"
|
2
|
+
require "net/scp"
|
3
|
+
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
module TorqueBox
|
7
|
+
module RemoteDeployUtils
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def stage(archive_file)
|
11
|
+
with_config(archive_file) do |config, app_name|
|
12
|
+
# no need to stage if we are local. we'll just run from the app dir
|
13
|
+
unless config.local
|
14
|
+
cleanup_stage(config, archive_file, app_name)
|
15
|
+
prepare_stage(config, app_name)
|
16
|
+
stage_archive(config, archive_file)
|
17
|
+
unjar_staged_archive(config, archive_file, app_name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def deploy(archive_file)
|
23
|
+
with_config(archive_file) do |config, app_name|
|
24
|
+
scp_upload(config, archive_file, "#{config.jboss_home}/standalone/deployments/")
|
25
|
+
do_deploy(config, app_name)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def deploy_from_stage(archive_file)
|
30
|
+
with_config(archive_file) do |config, app_name|
|
31
|
+
unless config.local
|
32
|
+
ssh_exec(config, "cp #{config.torquebox_home}/stage/#{app_name}.knob #{config.jboss_home}/standalone/deployments")
|
33
|
+
else
|
34
|
+
scp_upload(config, archive_file, "#{config.jboss_home}/standalone/deployments/")
|
35
|
+
end
|
36
|
+
do_deploy(config, app_name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def undeploy(archive_file)
|
41
|
+
with_config(archive_file) do |config, app_name|
|
42
|
+
unless config.local
|
43
|
+
ssh_exec(config, "rm -f #{config.jboss_home}/standalone/deployments/#{app_name}-knob.yml*")
|
44
|
+
ssh_exec(config, "rm -f #{config.jboss_home}/standalone/deployments/#{app_name}.knob")
|
45
|
+
else
|
46
|
+
FileUtils.rm("#{config.jboss_home}/standalone/deployments/#{app_name}-knob.yml*")
|
47
|
+
FileUtils.rm("#{config.jboss_home}/standalone/deployments/#{app_name}.knob")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def exec_ruby(archive_file, cmd)
|
53
|
+
with_config(archive_file) do |config, app_name|
|
54
|
+
unless config.local
|
55
|
+
ssh_exec(config, "cd #{config.torquebox_home}/stage/#{app_name}",
|
56
|
+
"export PATH=$PATH:#{config.torquebox_home}/jruby/bin",
|
57
|
+
"export RAILS_ENV=#{config.rack_env}",
|
58
|
+
"export RACK_ENV=#{config.rack_env}",
|
59
|
+
"#{config.torquebox_home}/jruby/bin/jruby -S #{cmd}")
|
60
|
+
else
|
61
|
+
# not sure what to do here yet
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def prefix(config)
|
69
|
+
config.sudo ? "sudo" : p
|
70
|
+
end
|
71
|
+
|
72
|
+
def do_deploy(config, app_name)
|
73
|
+
knob_yml = <<-YAML
|
74
|
+
application:
|
75
|
+
root: #{config.jboss_home}/standalone/deployments/#{app_name}.knob
|
76
|
+
environment:
|
77
|
+
RACK_ENV: #{config.rack_env}
|
78
|
+
RAILS_ENV: #{config.rack_env}
|
79
|
+
YAML
|
80
|
+
|
81
|
+
unless config.local
|
82
|
+
knob_yml_file = Tempfile.new("#{app_name}-knob.yml")
|
83
|
+
knob_yml_file.write(knob_yml)
|
84
|
+
knob_yml_file.rewind
|
85
|
+
scp_upload(config, knob_yml_file.path, "#{config.jboss_home}/standalone/deployments/#{app_name}-knob.yml")
|
86
|
+
ssh_exec(config, "touch #{config.jboss_home}/standalone/deployments/#{app_name}-knob.yml.dodeploy")
|
87
|
+
else
|
88
|
+
# todo copy temp file to somewhere
|
89
|
+
File.open("#{config.jboss_home}/standalone/deployments/#{app_name}-knob.yml", "w") {}
|
90
|
+
File.open("#{config.jboss_home}/standalone/deployments/#{app_name}-knob.yml.dodeploy", "w") {}
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def app_name(archive_file)
|
95
|
+
File.basename(archive_file, ".knob")
|
96
|
+
end
|
97
|
+
|
98
|
+
def unjar_staged_archive(config, archive_file, app_name)
|
99
|
+
ssh_exec(config, "cd #{config.torquebox_home}/stage/#{app_name} && #{prefix(config)}jar -xf ../#{archive_file}")
|
100
|
+
end
|
101
|
+
|
102
|
+
def stage_archive(config, archive_file)
|
103
|
+
scp_upload(config, archive_file, "#{config.torquebox_home}/stage/#{File.basename(archive_file)}")
|
104
|
+
end
|
105
|
+
|
106
|
+
def cleanup_stage(config, archive_file, app_name)
|
107
|
+
ssh_exec(config, "rm -f #{config.torquebox_home}/stage/#{archive_file}")
|
108
|
+
ssh_exec(config, "rm -rf #{config.torquebox_home}/stage/#{app_name}")
|
109
|
+
end
|
110
|
+
|
111
|
+
def prepare_stage(config, app_name)
|
112
|
+
unless config.local
|
113
|
+
ssh_exec(config, "mkdir -p #{config.torquebox_home}/stage/#{app_name}")
|
114
|
+
else
|
115
|
+
FileUtils.mkdir_p("#{config.torquebox_home}/stage/#{app_name}")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def with_config(archive_file)
|
120
|
+
read_config.each do |config|
|
121
|
+
yield config, app_name(archive_file)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def ssh_exec(config, *cmd)
|
126
|
+
begin
|
127
|
+
Net::SSH.start(config.hostname, config.user, :port => config.port, :keys => [config.key]) do |ssh|
|
128
|
+
ssh.exec(cmd.map { |c| "#{prefix(config)} #{c}" }.join("\n"))
|
129
|
+
end
|
130
|
+
rescue Net::SSH::AuthenticationFailed => e
|
131
|
+
raise "Can't authenticate as #{config.user}@#{config.hostname}:#{config.port}."
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def scp_upload(config, local_file, remote_file)
|
136
|
+
unless config.local
|
137
|
+
Net::SCP.upload!(config.hostname, config.user, local_file, remote_file,
|
138
|
+
:ssh => {:port => config.port, :keys => [config.key]}
|
139
|
+
) do |ch, name, sent, total|
|
140
|
+
print "\rCopying #{name}: #{sent}/#{total}"
|
141
|
+
end
|
142
|
+
print "\n"
|
143
|
+
else
|
144
|
+
FileUtils.cp(local_file, remote_file)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def read_config
|
149
|
+
config_file = ENV["TB_REMOTE_FILE"] || ENV["tb_remote_file"] || "config/torquebox_remote.rb"
|
150
|
+
eval(File.read(config_file)).configurations
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
class RemoteDeploy
|
156
|
+
def self.configure(&blk)
|
157
|
+
new(blk)
|
158
|
+
end
|
159
|
+
|
160
|
+
def initialize(blk)
|
161
|
+
@config = RemoteConfig.new
|
162
|
+
@configs = []
|
163
|
+
instance_eval &blk
|
164
|
+
end
|
165
|
+
|
166
|
+
attr_reader :config
|
167
|
+
|
168
|
+
def configurations
|
169
|
+
# evenually, we should merge the base @config settings into the @configs
|
170
|
+
@configs.empty? ? [@config] : @configs
|
171
|
+
end
|
172
|
+
|
173
|
+
def hostname(h)
|
174
|
+
@config.hostname = h
|
175
|
+
end
|
176
|
+
|
177
|
+
def port(p)
|
178
|
+
@config.port = p
|
179
|
+
end
|
180
|
+
|
181
|
+
def user(u)
|
182
|
+
@config.user = u
|
183
|
+
end
|
184
|
+
|
185
|
+
def key(k)
|
186
|
+
@config.key = k
|
187
|
+
end
|
188
|
+
|
189
|
+
def torquebox_home(tbh)
|
190
|
+
@config.torquebox_home = tbh
|
191
|
+
end
|
192
|
+
|
193
|
+
def jboss_home(jbh)
|
194
|
+
@config.jboss_home = jbh
|
195
|
+
end
|
196
|
+
|
197
|
+
def sudo(sudo)
|
198
|
+
@config.sudo = sudo
|
199
|
+
end
|
200
|
+
|
201
|
+
def local(l)
|
202
|
+
@config.local = l
|
203
|
+
end
|
204
|
+
|
205
|
+
def host(&block)
|
206
|
+
@configs << RemoteDeploy.new(block).config
|
207
|
+
end
|
208
|
+
|
209
|
+
def rails_env(env)
|
210
|
+
@config.rack_env = env
|
211
|
+
end
|
212
|
+
|
213
|
+
def rack_env(env)
|
214
|
+
@config.rack_env = env
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class RemoteConfig
|
219
|
+
attr_accessor :hostname, :port, :user, :key, :torquebox_home, :sudo, :local
|
220
|
+
|
221
|
+
def rack_env=(env)
|
222
|
+
@rack_env = env
|
223
|
+
end
|
224
|
+
|
225
|
+
def rack_env
|
226
|
+
@rack_env || "production"
|
227
|
+
end
|
228
|
+
|
229
|
+
def jboss_home=(jbh)
|
230
|
+
@jboss_home = jbh
|
231
|
+
end
|
232
|
+
|
233
|
+
def jboss_home
|
234
|
+
@jboss_home || "#{@torquebox_home}/jboss"
|
235
|
+
end
|
236
|
+
|
237
|
+
def initialize
|
238
|
+
@user = "torquebox"
|
239
|
+
@torquebox_home = "/opt/torquebox"
|
240
|
+
@sudo = false
|
241
|
+
@local = false
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'torquebox/rake/tasks/remote'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
TorqueBox::RemoteDeploy.configure do
|
2
|
+
host do
|
3
|
+
torquebox_home "/my/tb/dir"
|
4
|
+
jboss_home "/my/jboss/dir"
|
5
|
+
hostname "1.2.3.4"
|
6
|
+
port "2222"
|
7
|
+
user "torquebox"
|
8
|
+
key "~/.ssh/id_rsa.pub"
|
9
|
+
sudo true
|
10
|
+
end
|
11
|
+
|
12
|
+
host do
|
13
|
+
hostname "4.4.4.4"
|
14
|
+
port "22"
|
15
|
+
user "deploy"
|
16
|
+
key "~/.ssh/torquebox.pub"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
this is not really a knob file
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TorqueBox::RemoteDeploy do
|
4
|
+
describe ".configure" do
|
5
|
+
context "defaults" do
|
6
|
+
subject do
|
7
|
+
TorqueBox::RemoteDeploy.configure do
|
8
|
+
hostname "1.2.3.4"
|
9
|
+
port "2222"
|
10
|
+
user "torquebox"
|
11
|
+
key "~/.ssh/id_rsa.pub"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has one configurations" do
|
16
|
+
subject.configurations.size.should == 1
|
17
|
+
subject.config.should == subject.configurations[0]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has hostname 1.2.3.4" do
|
21
|
+
subject.config.hostname.should == "1.2.3.4"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has port 2222" do
|
25
|
+
subject.config.port.should == "2222"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has user torquebox" do
|
29
|
+
subject.config.user.should == "torquebox"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has key '~/.ssh/id_rsa.pub'" do
|
33
|
+
subject.config.key.should == "~/.ssh/id_rsa.pub"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has torquebox_home '/opt/torquebox'" do
|
37
|
+
subject.config.torquebox_home.should == "/opt/torquebox"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has jboss_home '/opt/torquebox/jboss'" do
|
41
|
+
subject.config.jboss_home.should == "/opt/torquebox/jboss"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has sudo false" do
|
45
|
+
subject.config.sudo.should == false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "overrides" do
|
50
|
+
subject do
|
51
|
+
TorqueBox::RemoteDeploy.configure do
|
52
|
+
torquebox_home "/my/tb/dir"
|
53
|
+
jboss_home "/my/jboss/dir"
|
54
|
+
hostname "1.2.3.4"
|
55
|
+
port "2222"
|
56
|
+
user "torquebox"
|
57
|
+
key "~/.ssh/id_rsa.pub"
|
58
|
+
sudo true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "has one configurations" do
|
63
|
+
subject.configurations.size.should == 1
|
64
|
+
subject.config.should == subject.configurations[0]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "has hostname 1.2.3.4" do
|
68
|
+
subject.config.hostname.should == "1.2.3.4"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "has port 2222" do
|
72
|
+
subject.config.port.should == "2222"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "has user torquebox" do
|
76
|
+
subject.config.user.should == "torquebox"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "has key '~/.ssh/id_rsa.pub'" do
|
80
|
+
subject.config.key.should == "~/.ssh/id_rsa.pub"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "has torquebox_home '/my/tb/dir'" do
|
84
|
+
subject.config.torquebox_home.should == "/my/tb/dir"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has jboss_home '/my/jboss/dir'" do
|
88
|
+
subject.config.jboss_home.should == "/my/jboss/dir"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has sudo true" do
|
92
|
+
subject.config.sudo.should == true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "multiple hosts" do
|
97
|
+
subject do
|
98
|
+
TorqueBox::RemoteDeploy.configure do
|
99
|
+
host do
|
100
|
+
torquebox_home "/my/tb/dir"
|
101
|
+
jboss_home "/my/jboss/dir"
|
102
|
+
hostname "1.2.3.4"
|
103
|
+
port "2222"
|
104
|
+
user "torquebox"
|
105
|
+
key "~/.ssh/id_rsa.pub"
|
106
|
+
sudo true
|
107
|
+
end
|
108
|
+
|
109
|
+
host do
|
110
|
+
hostname "4.4.4.4"
|
111
|
+
port "22"
|
112
|
+
user "deploy"
|
113
|
+
key "~/.ssh/torquebox.pub"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "has one configurations" do
|
119
|
+
subject.configurations.size.should == 2
|
120
|
+
end
|
121
|
+
|
122
|
+
it "has correct config" do
|
123
|
+
test_config(subject.configurations[0])
|
124
|
+
test_config(subject.configurations[1])
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_config(configuration)
|
128
|
+
if configuration.hostname == "4.4.4.4"
|
129
|
+
configuration.torquebox_home.should == "/opt/torquebox"
|
130
|
+
elsif configuration.hostname == "1.2.3.4"
|
131
|
+
configuration.torquebox_home.should == "/my/tb/dir"
|
132
|
+
else
|
133
|
+
fail
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TorqueBox::RemoteDeployUtils do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@util = TorqueBox::RemoteDeployUtils
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ".stage" do
|
10
|
+
it "stages one host" do
|
11
|
+
ENV["tb_remote_file"] = File.join(File.dirname(__FILE__), "fixtures/simple_torquebox_remote.rb")
|
12
|
+
@util.stub(:ssh_exec)
|
13
|
+
@util.should_receive(:scp_upload).with(anything(), "myapp.knob", "/opt/torquebox/stage/myapp.knob")
|
14
|
+
@util.stage("myapp.knob")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "stages two hosts" do
|
18
|
+
ENV["tb_remote_file"] = File.join(File.dirname(__FILE__), "fixtures/multihost_torquebox_remote.rb")
|
19
|
+
@util.stub(:ssh_exec)
|
20
|
+
@util.should_receive(:scp_upload).with(anything(), "myapp.knob", "/my/tb/dir/stage/myapp.knob")
|
21
|
+
@util.should_receive(:scp_upload).with(anything(), "myapp.knob", "/opt/torquebox/stage/myapp.knob")
|
22
|
+
@util.stage("myapp.knob")
|
23
|
+
end
|
24
|
+
|
25
|
+
context "local" do
|
26
|
+
it "stages" do
|
27
|
+
ENV["tb_remote_file"] = File.join(File.dirname(__FILE__), "fixtures/local_torquebox_remote.rb")
|
28
|
+
@util.stage("myapp.knob") # does nothing
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".deploy" do
|
34
|
+
context "local" do
|
35
|
+
before do
|
36
|
+
FileUtils.mkdir_p(deploy_dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
FileUtils.remove_dir("#{File.dirname(__FILE__)}/../tmp/torquebox", true)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "deploys" do
|
44
|
+
ENV["tb_remote_file"] = File.join(File.dirname(__FILE__), "fixtures/local_torquebox_remote.rb")
|
45
|
+
@util.deploy(File.join(File.dirname(__FILE__), "fixtures/myapp.knob"))
|
46
|
+
File.exists?("#{deploy_dir}/myapp.knob").should == true
|
47
|
+
|
48
|
+
# this isn't really testing the real deal yet
|
49
|
+
File.exists?("#{deploy_dir}/myapp-knob.yml").should == true
|
50
|
+
File.exists?("#{deploy_dir}/myapp-knob.yml.dodeploy").should == true
|
51
|
+
end
|
52
|
+
|
53
|
+
def deploy_dir
|
54
|
+
"#{File.dirname(__FILE__)}/../tmp/torquebox/jboss/standalone/deployments/"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "torquebox-remote-deployer"
|
6
|
+
s.version = "0.1.2.pre2"
|
7
|
+
s.platform = "java"
|
8
|
+
s.authors = ["Joe Kutner"]
|
9
|
+
s.email = ["jpkutner@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/jkutner/torquebox-remote-deployer"
|
11
|
+
s.summary = %q{Deploy Knob files to a remote server with ease.}
|
12
|
+
s.description = %q{This utility allows you to deploy a Torquebox Knob file to a remote server}
|
13
|
+
|
14
|
+
s.rubyforge_project = "torquebox-remote-deployer"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "jruby-openssl"
|
22
|
+
s.add_dependency "net-ssh"
|
23
|
+
s.add_dependency "net-scp"
|
24
|
+
s.add_dependency "rake"
|
25
|
+
s.add_dependency "torquebox-rake-support"
|
26
|
+
|
27
|
+
s.add_development_dependency "rspec"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torquebox-remote-deployer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: 6
|
5
|
+
version: 0.1.2.pre2
|
6
|
+
platform: java
|
7
|
+
authors:
|
8
|
+
- Joe Kutner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-08-29 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jruby-openssl
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: net-ssh
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: net-scp
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: torquebox-rake-support
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
description: This utility allows you to deploy a Torquebox Knob file to a remote server
|
82
|
+
email:
|
83
|
+
- jpkutner@gmail.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files: []
|
89
|
+
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- lib/torquebox-remote-deployer.rb
|
96
|
+
- lib/torquebox/rake/tasks/remote.rb
|
97
|
+
- lib/torquebox/remote_deploy_utils.rb
|
98
|
+
- spec/fixtures/local_torquebox_remote.rb
|
99
|
+
- spec/fixtures/multihost_torquebox_remote.rb
|
100
|
+
- spec/fixtures/myapp.knob
|
101
|
+
- spec/fixtures/simple_torquebox_remote.rb
|
102
|
+
- spec/remote_deploy_spec.rb
|
103
|
+
- spec/remote_deploy_utils_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- torquebox-remote-deployer.gemspec
|
106
|
+
homepage: https://github.com/jkutner/torquebox-remote-deployer
|
107
|
+
licenses: []
|
108
|
+
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
none: false
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: "0"
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">"
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.3.1
|
126
|
+
requirements: []
|
127
|
+
|
128
|
+
rubyforge_project: torquebox-remote-deployer
|
129
|
+
rubygems_version: 1.8.15
|
130
|
+
signing_key:
|
131
|
+
specification_version: 3
|
132
|
+
summary: Deploy Knob files to a remote server with ease.
|
133
|
+
test_files:
|
134
|
+
- spec/fixtures/local_torquebox_remote.rb
|
135
|
+
- spec/fixtures/multihost_torquebox_remote.rb
|
136
|
+
- spec/fixtures/myapp.knob
|
137
|
+
- spec/fixtures/simple_torquebox_remote.rb
|
138
|
+
- spec/remote_deploy_spec.rb
|
139
|
+
- spec/remote_deploy_utils_spec.rb
|
140
|
+
- spec/spec_helper.rb
|