lastobelus-vlad 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +24 -0
- data/History.txt +162 -0
- data/Manifest.txt +38 -0
- data/README.txt +78 -0
- data/Rakefile +44 -0
- data/considerations.txt +91 -0
- data/doco/deploying-merb-with-vlad.txt +155 -0
- data/doco/deploying-sinatra-with-vlad.txt +119 -0
- data/doco/faq.txt +131 -0
- data/doco/getting_started.txt +61 -0
- data/doco/migration.txt +43 -0
- data/doco/perforce.txt +5 -0
- data/doco/variables.txt +79 -0
- data/lib/rake_remote_task.rb +589 -0
- data/lib/vlad.rb +91 -0
- data/lib/vlad/apache.rb +37 -0
- data/lib/vlad/core.rb +181 -0
- data/lib/vlad/darcs.rb +24 -0
- data/lib/vlad/git.rb +49 -0
- data/lib/vlad/god.rb +23 -0
- data/lib/vlad/lighttpd.rb +85 -0
- data/lib/vlad/maintenance.rb +20 -0
- data/lib/vlad/merb.rb +51 -0
- data/lib/vlad/mercurial.rb +37 -0
- data/lib/vlad/mongrel.rb +62 -0
- data/lib/vlad/nginx.rb +48 -0
- data/lib/vlad/passenger.rb +8 -0
- data/lib/vlad/perforce.rb +117 -0
- data/lib/vlad/subversion.rb +35 -0
- data/lib/vlad/thin.rb +63 -0
- data/test/test_rake_remote_task.rb +257 -0
- data/test/test_vlad.rb +210 -0
- data/test/test_vlad_git.rb +41 -0
- data/test/test_vlad_mercurial.rb +31 -0
- data/test/test_vlad_perforce.rb +37 -0
- data/test/test_vlad_subversion.rb +27 -0
- data/test/vlad_test_case.rb +72 -0
- data/vladdemo.sh +97 -0
- metadata +141 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'vlad'
|
2
|
+
|
3
|
+
##
|
4
|
+
# See the following documents for recipes:
|
5
|
+
#
|
6
|
+
# * http://clarkware.com/cgi/blosxom/2007/01/05/CustomMaintenancePages
|
7
|
+
# * http://blog.nodeta.fi/2009/03/11/stopping-your-rails-application-with-phusion-passenger/
|
8
|
+
#
|
9
|
+
|
10
|
+
namespace :vlad do
|
11
|
+
namespace :maintenance do
|
12
|
+
remote_task :on, :roles => [:web] do
|
13
|
+
run "cp -f #{shared_path}/config/maintenance.html #{shared_path}/system/"
|
14
|
+
end
|
15
|
+
|
16
|
+
remote_task :off, :roles => [:web] do
|
17
|
+
run "rm -f #{shared_path}/system/maintenance.html"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/vlad/merb.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'vlad'
|
2
|
+
|
3
|
+
namespace :vlad do
|
4
|
+
##
|
5
|
+
# Merb app server
|
6
|
+
|
7
|
+
set :merb_address, "127.0.0.1"
|
8
|
+
set :merb_command, 'merb'
|
9
|
+
set :merb_environment, "production"
|
10
|
+
set :merb_port, 8000
|
11
|
+
set :merb_servers, 2
|
12
|
+
|
13
|
+
# maybe needed later
|
14
|
+
#set :merb_clean, false
|
15
|
+
#set(:merb_conf) { "#{current_path}/config/merb.yml" }
|
16
|
+
#set :merb_config_script, nil
|
17
|
+
#set :merb_group, nil
|
18
|
+
#set :merb_log_file, nil
|
19
|
+
#set :merb_pid_file, nil
|
20
|
+
#set :merb_prefix, nil
|
21
|
+
#set :merb_user, nil
|
22
|
+
|
23
|
+
desc "Start the app servers"
|
24
|
+
remote_task :start_app, :roles => :app do
|
25
|
+
cmd = [
|
26
|
+
"cd #{current_path} &&", # work around merb bug,
|
27
|
+
# http://merb.devjavu.com/ticket/469
|
28
|
+
"#{merb_command}",
|
29
|
+
#"-m #{current_path}", # the buggy behaviour
|
30
|
+
"-e #{merb_environment}",
|
31
|
+
"-p #{merb_port}",
|
32
|
+
"-c #{merb_servers}"
|
33
|
+
].compact.join ' '
|
34
|
+
run cmd
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "Stop the app servers"
|
38
|
+
remote_task :stop_app, :roles => :app do
|
39
|
+
merb_servers.times do |i|
|
40
|
+
cmd = "#{current_path}/script/stop_merb #{merb_port + i}"
|
41
|
+
puts "$ #{cmd}"
|
42
|
+
run cmd
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Stop, then restart the app servers"
|
47
|
+
remote_task :restart_app, :roles => :app do
|
48
|
+
Rake::Task['vlad:stop_app'].invoke
|
49
|
+
Rake::Task['vlad:start_app'].invoke
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Vlad::Mercurial
|
2
|
+
|
3
|
+
set :source, Vlad::Mercurial.new
|
4
|
+
|
5
|
+
##
|
6
|
+
# Returns the command that will check out +revision+ from the repository
|
7
|
+
# into directory +destination+
|
8
|
+
|
9
|
+
def checkout(revision, destination)
|
10
|
+
revision = 'tip' if revision =~ /^head$/i
|
11
|
+
|
12
|
+
[ "if [ ! -d #{destination}/.hg ]; then hg init -R #{destination}; fi",
|
13
|
+
"hg pull -r #{revision} -R #{destination} #{repository}"
|
14
|
+
].join(' && ')
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Returns the command that will export +revision+ from the repository into
|
19
|
+
# the directory +destination+.
|
20
|
+
|
21
|
+
def export(revision_or_source, destination)
|
22
|
+
revision_or_source = 'tip' if revision_or_source =~ /^head$/i
|
23
|
+
if revision_or_source =~ /^(\d+|tip)$/i then
|
24
|
+
"hg archive -r #{revision_or_source} -R #{repository} #{destination}"
|
25
|
+
else
|
26
|
+
"hg archive -R #{revision_or_source} #{destination}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
##
|
31
|
+
# Returns a command that maps human-friendly revision identifier +revision+
|
32
|
+
# into a subversion revision specification.
|
33
|
+
|
34
|
+
def revision(revision)
|
35
|
+
"`hg identify -R #{repository} | cut -f1 -d\\ `"
|
36
|
+
end
|
37
|
+
end
|
data/lib/vlad/mongrel.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'vlad'
|
2
|
+
|
3
|
+
namespace :vlad do
|
4
|
+
##
|
5
|
+
# Mongrel app server
|
6
|
+
|
7
|
+
set :mongrel_address, "127.0.0.1"
|
8
|
+
set :mongrel_clean, false
|
9
|
+
set :mongrel_command, 'mongrel_rails'
|
10
|
+
set(:mongrel_conf) { "#{shared_path}/mongrel_cluster.conf" }
|
11
|
+
set :mongrel_config_script, nil
|
12
|
+
set :mongrel_environment, "production"
|
13
|
+
set :mongrel_group, nil
|
14
|
+
set :mongrel_log_file, nil
|
15
|
+
set :mongrel_pid_file, nil
|
16
|
+
set :mongrel_port, 8000
|
17
|
+
set :mongrel_prefix, nil
|
18
|
+
set :mongrel_servers, 2
|
19
|
+
set :mongrel_user, nil
|
20
|
+
|
21
|
+
desc "Prepares application servers for deployment. Mongrel
|
22
|
+
configuration is set via the mongrel_* variables.".cleanup
|
23
|
+
|
24
|
+
remote_task :setup_app, :roles => :app do
|
25
|
+
cmd = [
|
26
|
+
'cluster::configure',
|
27
|
+
"-N #{mongrel_servers}",
|
28
|
+
"-p #{mongrel_port}",
|
29
|
+
"-e #{mongrel_environment}",
|
30
|
+
"-a #{mongrel_address}",
|
31
|
+
"-c #{current_path}",
|
32
|
+
("-P #{mongrel_pid_file}" if mongrel_pid_file),
|
33
|
+
("-l #{mongrel_log_file}" if mongrel_log_file),
|
34
|
+
("--user #{mongrel_user}" if mongrel_user),
|
35
|
+
("--group #{mongrel_group}" if mongrel_group),
|
36
|
+
("--prefix #{mongrel_prefix}" if mongrel_prefix),
|
37
|
+
("-S #{mongrel_config_script}" if mongrel_config_script),
|
38
|
+
]
|
39
|
+
|
40
|
+
run mongrel(*cmd)
|
41
|
+
end
|
42
|
+
|
43
|
+
def mongrel(cmd, *opts) # :nodoc:
|
44
|
+
cmd = ["#{mongrel_command} #{cmd} -C #{mongrel_conf}"]
|
45
|
+
cmd << ' --clean' if mongrel_clean unless cmd == 'cluster::configure'
|
46
|
+
cmd.push(*opts)
|
47
|
+
|
48
|
+
cmd.compact.join ' '
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Restart the app servers"
|
52
|
+
|
53
|
+
remote_task :start_app, :roles => :app do
|
54
|
+
run mongrel("cluster::restart")
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Stop the app servers"
|
58
|
+
|
59
|
+
remote_task :stop_app, :roles => :app do
|
60
|
+
run mongrel("cluster::stop")
|
61
|
+
end
|
62
|
+
end
|
data/lib/vlad/nginx.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'vlad'
|
2
|
+
|
3
|
+
namespace :vlad do
|
4
|
+
##
|
5
|
+
# Nginx web server on Gentoo/Debian init.d systems FIX
|
6
|
+
|
7
|
+
set :web_command, "/etc/init.d/nginx"
|
8
|
+
|
9
|
+
remote_task :setup_app, :roles => :web do
|
10
|
+
config_file = "/etc/nginx/vhosts/#{application}_#{environment}.conf"
|
11
|
+
raise "not yet... must review this code"
|
12
|
+
run [ "sudo test -e #{config_file} || ",
|
13
|
+
"sudo sh -c \"ruby ",
|
14
|
+
" /etc/sliceconfig/install/interactive/nginx_config.rb ",
|
15
|
+
"'#{app_domain}' '#{application}' '#{environment}' ",
|
16
|
+
"'#{app_port}' '#{app_servers}' #{only_www ? 1 : 0} ",
|
17
|
+
"> #{config_file}\""
|
18
|
+
].join(" ")
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "(Re)Start the web servers"
|
22
|
+
|
23
|
+
remote_task :start_web, :roles => :web do
|
24
|
+
run "#{web_command} restart"
|
25
|
+
# TODO: run %Q(sudo #{web_command} configtest && sudo #{web_command} reload)
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Stop the web servers"
|
29
|
+
|
30
|
+
remote_task :stop_web, :roles => :web do
|
31
|
+
run "#{web_command} stop"
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Everything HTTP.
|
36
|
+
|
37
|
+
desc "(Re)Start the web and app servers"
|
38
|
+
|
39
|
+
remote_task :start do
|
40
|
+
Rake::Task['vlad:start_app'].invoke
|
41
|
+
Rake::Task['vlad:start_web'].invoke
|
42
|
+
end
|
43
|
+
|
44
|
+
remote_task :stop do
|
45
|
+
Rake::Task['vlad:stop_app'].invoke
|
46
|
+
Rake::Task['vlad:stop_web'].invoke
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
class Vlad::Perforce
|
2
|
+
|
3
|
+
set :p4_cmd, "p4"
|
4
|
+
set :source, Vlad::Perforce.new
|
5
|
+
|
6
|
+
##
|
7
|
+
# Returns the p4 command that will checkout +revision+ into the directory
|
8
|
+
# +destination+.
|
9
|
+
|
10
|
+
def checkout(revision, destination)
|
11
|
+
"#{p4_cmd} sync ...#{rev_no(revision)}"
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Returns the p4 command that will export +revision+ into the directory
|
16
|
+
# +directory+.
|
17
|
+
|
18
|
+
def export(revision_or_source, destination)
|
19
|
+
if revision_or_source =~ /^(\d+|head)$/i then
|
20
|
+
"(cd #{destination} && #{p4_cmd} sync ...#{rev_no(revision_or_source)})"
|
21
|
+
else
|
22
|
+
"cp -r #{revision_or_source} #{destination}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Returns a command that maps human-friendly revision identifier +revision+
|
28
|
+
# into a Perforce revision specification.
|
29
|
+
|
30
|
+
def revision(revision)
|
31
|
+
"`#{p4_cmd} changes -s submitted -m 1 ...#{rev_no(revision)} | cut -f 2 -d\\ `"
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Maps revision +revision+ into a Perforce revision.
|
36
|
+
|
37
|
+
def rev_no(revision)
|
38
|
+
case revision.to_s
|
39
|
+
when /head/i then
|
40
|
+
"#head"
|
41
|
+
when /^\d+$/ then
|
42
|
+
"@#{revision}"
|
43
|
+
else
|
44
|
+
revision
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
namespace :vlad do
|
50
|
+
remote_task :setup_app, :roles => :app do
|
51
|
+
p4data = p4port = p4user = p4passwd = nil
|
52
|
+
|
53
|
+
if ENV['P4CONFIG'] then
|
54
|
+
p4config_name = ENV['P4CONFIG']
|
55
|
+
p4config = nil
|
56
|
+
orig_dir = Dir.pwd.split File::SEPARATOR
|
57
|
+
|
58
|
+
until orig_dir.length == 1 do
|
59
|
+
p4config = orig_dir + [p4config_name]
|
60
|
+
p4config = File.join p4config
|
61
|
+
break if File.exist? p4config
|
62
|
+
orig_dir.pop
|
63
|
+
end
|
64
|
+
|
65
|
+
raise "couldn't find .p4config" unless File.exist? p4config
|
66
|
+
|
67
|
+
p4data = File.readlines(p4config).map { |line| line.strip.split '=', 2 }
|
68
|
+
p4data = Hash[*p4data.flatten]
|
69
|
+
else
|
70
|
+
p4data = ENV
|
71
|
+
end
|
72
|
+
|
73
|
+
p4port = p4data['P4PORT']
|
74
|
+
p4user = p4data['P4USER']
|
75
|
+
p4passwd = p4data['P4PASSWD']
|
76
|
+
|
77
|
+
raise "couldn't get P4PORT" if p4port.nil?
|
78
|
+
raise "couldn't get P4USER" if p4user.nil?
|
79
|
+
raise "couldn't get P4PASSWD" if p4passwd.nil?
|
80
|
+
|
81
|
+
p4client = [p4user, target_host, application].join '-'
|
82
|
+
|
83
|
+
require 'tmpdir'
|
84
|
+
require 'tempfile'
|
85
|
+
|
86
|
+
put File.join(scm_path, '.p4config'), 'vlad.p4config' do
|
87
|
+
[ "P4PORT=#{p4port}",
|
88
|
+
"P4USER=#{p4user}",
|
89
|
+
"P4PASSWD=#{p4passwd}",
|
90
|
+
"P4CLIENT=#{p4client}" ].join("\n")
|
91
|
+
end
|
92
|
+
|
93
|
+
p4client_path = File.join deploy_to, 'p4client.tmp'
|
94
|
+
|
95
|
+
put p4client_path, 'vlad.p4client' do
|
96
|
+
conf = <<-"CLIENT"
|
97
|
+
Client: #{p4client}
|
98
|
+
|
99
|
+
Owner: #{p4user}
|
100
|
+
|
101
|
+
Root: #{scm_path}
|
102
|
+
|
103
|
+
View:
|
104
|
+
#{repository}/... //#{p4client}/...
|
105
|
+
CLIENT
|
106
|
+
end
|
107
|
+
|
108
|
+
cmds = [
|
109
|
+
"cd #{scm_path}",
|
110
|
+
"p4 client -i < #{p4client_path}",
|
111
|
+
"rm #{p4client_path}",
|
112
|
+
]
|
113
|
+
|
114
|
+
run cmds.join(' && ')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Vlad::Subversion
|
2
|
+
|
3
|
+
set :source, Vlad::Subversion.new
|
4
|
+
set :svn_cmd, "svn"
|
5
|
+
|
6
|
+
##
|
7
|
+
# Returns the command that will check out +revision+ from the repository
|
8
|
+
# into directory +destination+
|
9
|
+
|
10
|
+
def checkout(revision, destination)
|
11
|
+
"#{svn_cmd} co -r #{revision} #{repository} #{destination}"
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Returns the command that will export +revision+ from the repository into
|
16
|
+
# the directory +destination+.
|
17
|
+
|
18
|
+
def export(revision_or_source, destination)
|
19
|
+
"#{svn_cmd} #{deploy_via} " +
|
20
|
+
if revision_or_source =~ /^(\d+|head)$/i then
|
21
|
+
"-r #{revision_or_source} #{repository} #{destination}"
|
22
|
+
else
|
23
|
+
"#{revision_or_source} #{destination}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Returns a command that maps human-friendly revision identifier +revision+
|
29
|
+
# into a subversion revision specification.
|
30
|
+
|
31
|
+
def revision(revision)
|
32
|
+
"`#{svn_cmd} info #{repository} | grep 'Revision:' | cut -f2 -d\\ `"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
data/lib/vlad/thin.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# $GEM_HOME/gems/vlad-1.2.0/lib/vlad/thin.rb
|
2
|
+
# Thin tasks for Vlad the Deployer
|
3
|
+
# By cnantais
|
4
|
+
require 'vlad'
|
5
|
+
|
6
|
+
namespace :vlad do
|
7
|
+
##
|
8
|
+
# Thin app server
|
9
|
+
|
10
|
+
set :thin_address, "127.0.0.1"
|
11
|
+
set :thin_command, 'thin'
|
12
|
+
set(:thin_conf) { "#{shared_path}/thin_cluster.conf" }
|
13
|
+
set :thin_environment, "production"
|
14
|
+
set :thin_group, nil
|
15
|
+
set :thin_log_file, nil
|
16
|
+
set :thin_pid_file, nil
|
17
|
+
set :thin_port, nil
|
18
|
+
set :thin_socket, "/tmp/thin.sock"
|
19
|
+
set :thin_prefix, nil
|
20
|
+
set :thin_servers, 2
|
21
|
+
set :thin_user, nil
|
22
|
+
set :thin_rackup, nil
|
23
|
+
|
24
|
+
desc "Prepares application servers for deployment. thin
|
25
|
+
configuration is set via the thin_* variables.".cleanup
|
26
|
+
|
27
|
+
remote_task :setup_app, :roles => :app do
|
28
|
+
cmd = [
|
29
|
+
"#{thin_command} config",
|
30
|
+
"-s #{thin_servers}",
|
31
|
+
"-S #{thin_socket}",
|
32
|
+
"-e #{thin_environment}",
|
33
|
+
"-c #{current_path}",
|
34
|
+
"-C #{thin_conf}",
|
35
|
+
("-a #{thin_address}" if thin_address),
|
36
|
+
("-R #{thin_rackup}" if thin_rackup),
|
37
|
+
("-P #{thin_pid_file}" if thin_pid_file),
|
38
|
+
("-l #{thin_log_file}" if thin_log_file),
|
39
|
+
("--user #{thin_user}" if thin_user),
|
40
|
+
("--group #{thin_group}" if thin_group),
|
41
|
+
("--prefix #{thin_prefix}" if thin_prefix),
|
42
|
+
("-p #{thin_port}" if thin_port),
|
43
|
+
].compact.join ' '
|
44
|
+
|
45
|
+
run cmd
|
46
|
+
end
|
47
|
+
|
48
|
+
def thin(cmd) # :nodoc:
|
49
|
+
"#{thin_command} #{cmd} -C #{thin_conf}"
|
50
|
+
end
|
51
|
+
|
52
|
+
desc "Restart the app servers"
|
53
|
+
|
54
|
+
remote_task :start_app, :roles => :app do
|
55
|
+
run thin("restart -s #{thin_servers}")
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "Stop the app servers"
|
59
|
+
|
60
|
+
remote_task :stop_app, :roles => :app do
|
61
|
+
run thin("stop -s #{thin_servers}")
|
62
|
+
end
|
63
|
+
end
|