torquebox-remote-deployer 0.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/.gitignore +2 -0
- data/LICENSE.txt +23 -0
- data/README.md +60 -0
- data/lib/torquebox-remote-deployer.rb +1 -0
- data/lib/torquebox/rake/tasks/remote.rb +47 -0
- data/lib/torquebox/remote_deploy_utils.rb +147 -0
- data/torquebox-remote-deployer.gemspec +26 -0
- metadata +115 -0
data/.gitignore
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,60 @@
|
|
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 "#{ENV["GEM_HOME"]}/gems/vagrant-0.8.7/keys/vagrant"
|
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
|
+
Now you can to do more useful things like running migrations:
|
47
|
+
|
48
|
+
$ rake torquebox:remote:exec["rake db:migrate RAILS_ENV=production"]
|
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
|
+
## TODO
|
57
|
+
|
58
|
+
* Make it friendly to remote Windows targets (already works on Windows source machines).
|
59
|
+
* Support deploying to mutliple servers (config would look like multi-hosts in a Vagrantfile)
|
60
|
+
* Support deploying over FTP or SFTP in addition to SCP/SSH.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'torquebox/rake/tasks/remote'
|
@@ -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,147 @@
|
|
1
|
+
require "net/ssh"
|
2
|
+
require "net/scp"
|
3
|
+
|
4
|
+
module TorqueBox
|
5
|
+
module RemoteDeployUtils
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def stage(archive_file)
|
9
|
+
with_config(archive_file) do |config, app_name|
|
10
|
+
cleanup_stage(config, archive_file, app_name)
|
11
|
+
prepare_stage(config, app_name)
|
12
|
+
stage_archive(config, archive_file)
|
13
|
+
unjar_staged_archive(config, archive_file, app_name)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def deploy(archive_file)
|
18
|
+
with_config(archive_file) do |config, app_name|
|
19
|
+
scp_upload(config, archive_file, "#{config.torquebox_home}/jboss/standalone/deployments/")
|
20
|
+
do_deploy(config, app_name)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def deploy_from_stage(archive_file)
|
25
|
+
with_config(archive_file) do |config, app_name|
|
26
|
+
ssh_exec(config, "cp #{config.torquebox_home}/stage/#{app_name}.knob #{config.torquebox_home}/jboss/standalone/deployments")
|
27
|
+
do_deploy(config, app_name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def undeploy(archive_file)
|
32
|
+
with_config(archive_file) do |config, app_name|
|
33
|
+
ssh_exec(config, "rm -f #{config.torquebox_home}/jboss/standalone/deployments/#{app_name}.knob*")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def exec_ruby(archive_file, cmd)
|
38
|
+
with_config(archive_file) do |config, app_name|
|
39
|
+
ssh_exec(config, "cd #{config.torquebox_home}/stage/#{app_name}",
|
40
|
+
"export PATH=$PATH:#{config.torquebox_home}/jruby/bin",
|
41
|
+
"#{config.torquebox_home}/jruby/bin/jruby -S #{cmd}")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def prefix(config)
|
48
|
+
config.sudo ? "sudo" : p
|
49
|
+
end
|
50
|
+
|
51
|
+
def do_deploy(config, app_name)
|
52
|
+
ssh_exec(config, "touch #{config.torquebox_home}/jboss/standalone/deployments/#{app_name}.knob.dodeploy")
|
53
|
+
end
|
54
|
+
|
55
|
+
def app_name(archive_file)
|
56
|
+
File.basename(archive_file, ".knob")
|
57
|
+
end
|
58
|
+
|
59
|
+
def unjar_staged_archive(config, archive_file, app_name)
|
60
|
+
ssh_exec(config, "cd #{config.torquebox_home}/stage/#{app_name} && #{prefix(config)}jar -xf ../#{archive_file}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def stage_archive(config, archive_file)
|
64
|
+
scp_upload(config, archive_file, "#{config.torquebox_home}/stage/#{File.basename(archive_file)}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def cleanup_stage(config, archive_file, app_name)
|
68
|
+
ssh_exec(config, "rm -f #{config.torquebox_home}/stage/#{archive_file}")
|
69
|
+
ssh_exec(config, "rm -rf #{config.torquebox_home}/stage/#{app_name}")
|
70
|
+
end
|
71
|
+
|
72
|
+
def prepare_stage(config, app_name)
|
73
|
+
ssh_exec(config, "mkdir -p #{config.torquebox_home}/stage/#{app_name}")
|
74
|
+
end
|
75
|
+
|
76
|
+
def with_config(archive_file)
|
77
|
+
yield read_config, app_name(archive_file)
|
78
|
+
end
|
79
|
+
|
80
|
+
def ssh_exec(config, *cmd)
|
81
|
+
Net::SSH.start(config.hostname, config.user, :port => config.port, :keys => [config.key]) do |ssh|
|
82
|
+
ssh.exec(cmd.map { |c| "#{prefix(config)} #{c}" }.join("\n"))
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def scp_upload(config, local_file, remote_file)
|
87
|
+
Net::SCP.upload!(config.hostname, config.user, local_file, remote_file,
|
88
|
+
:ssh => {:port => config.port, :keys => [config.key]}
|
89
|
+
) do |ch, name, sent, total|
|
90
|
+
print "\rCopying #{name}: #{sent}/#{total}"
|
91
|
+
end
|
92
|
+
print "\n"
|
93
|
+
end
|
94
|
+
|
95
|
+
def read_config
|
96
|
+
eval(File.read("config/torquebox_remote.rb")).config
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class RemoteDeploy
|
102
|
+
def self.configure(&blk)
|
103
|
+
new(blk)
|
104
|
+
end
|
105
|
+
|
106
|
+
def initialize(blk)
|
107
|
+
@config = RemoteConfig.new
|
108
|
+
instance_eval &blk
|
109
|
+
end
|
110
|
+
|
111
|
+
attr_reader :config
|
112
|
+
|
113
|
+
def hostname(h)
|
114
|
+
@config.hostname = h
|
115
|
+
end
|
116
|
+
|
117
|
+
def port(p)
|
118
|
+
@config.port = p
|
119
|
+
end
|
120
|
+
|
121
|
+
def user(u)
|
122
|
+
@config.user = u
|
123
|
+
end
|
124
|
+
|
125
|
+
def key(k)
|
126
|
+
@config.key = k
|
127
|
+
end
|
128
|
+
|
129
|
+
def torquebox_home(tbh)
|
130
|
+
@config.torquebox_home = tbh
|
131
|
+
end
|
132
|
+
|
133
|
+
def sudo(sudo)
|
134
|
+
@config.sudo = sudo
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
class RemoteConfig
|
139
|
+
attr_accessor :hostname, :port, :user, :key, :torquebox_home, :sudo
|
140
|
+
|
141
|
+
def initialize
|
142
|
+
@user = "torquebox"
|
143
|
+
@torquebox_home = "/opt/torquebox"
|
144
|
+
@sudo = false
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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.0"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
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
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torquebox-remote-deployer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joe Kutner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-01-18 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
|
+
description: This utility allows you to deploy a Torquebox Knob file to a remote server
|
71
|
+
email:
|
72
|
+
- jpkutner@gmail.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- lib/torquebox-remote-deployer.rb
|
84
|
+
- lib/torquebox/rake/tasks/remote.rb
|
85
|
+
- lib/torquebox/remote_deploy_utils.rb
|
86
|
+
- torquebox-remote-deployer.gemspec
|
87
|
+
homepage: https://github.com/jkutner/torquebox-remote-deployer
|
88
|
+
licenses: []
|
89
|
+
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project: torquebox-remote-deployer
|
110
|
+
rubygems_version: 1.8.9
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: Deploy Knob files to a remote server with ease.
|
114
|
+
test_files: []
|
115
|
+
|